Skip to content

Commit

Permalink
Package code
Browse files Browse the repository at this point in the history
  • Loading branch information
lindluni committed Apr 20, 2022
1 parent ca9eddc commit 9837515
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'GitHub Actions Variable Groups'
author: 'Brett Logan'
description: 'Allows for the central management of environment variables across multiple GitHub Actions projects.'
description: 'Allows for the central management of environment variables across multiple GitHub Actions workflows'
inputs:
groups:
description: A list of variable group files or directories containing variable group files.
Expand Down
57 changes: 40 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14358,7 +14358,7 @@ const {retry} = __nccwpck_require__(6298);
const {throttling} = __nccwpck_require__(9968);
const _Octokit = Octokit.plugin(retry, throttling);

const groups = core.getInput('groups', {required: true, trimWhitespace: true}).split('\n');
const groups = core.getInput('groups', {required: true, trimWhitespace: true}).split('\n').map(group => group.trim());
const org = core.getInput('org', {required: true, trimWhitespace: true});
const repo = core.getInput('repo', {required: true, trimWhitespace: true});
const token = core.getInput('token', {required: true, trimWhitespace: true});
Expand All @@ -14381,9 +14381,13 @@ const client = new _Octokit({

(async function main() {
try {
for (const group of groups) {
for (let group of groups) {
core.info(`Processing group ${group}`)
const files = await retrieveFiles(group)
let ref
if (group.includes('@')) {
[group, ref] = group.split('@')
}
const files = await retrieveFiles(group, ref)
if (Array.isArray(files)) {
for (const _file of files) {
const file = await retrieveFile(_file.path)
Expand All @@ -14399,30 +14403,49 @@ const client = new _Octokit({
}
})()

async function retrieveFiles(group) {
async function retrieveFiles(group, ref) {
try {
core.info(`Retrieving files for group ${group}`)
const {data: files} = await client.repos.getContent({
owner: org,
repo: repo,
path: group
})
return files
if (ref) {
const {data: files} = await client.repos.getContent({
owner: org,
repo: repo,
path: group,
})
return files
} else {
const {data: files} = await client.repos.getContent({
owner: org,
repo: repo,
path: group,
})
return files
}
} catch (err) {
core.setFailed(`Fail to retrieve files ${group}: ${err.message}`)
process.exit(1)
}
}

async function retrieveFile(path) {
async function retrieveFile(path, ref) {
try {
core.info(`Retrieving file ${path}`)
const {data: file} = await client.repos.getContent({
owner: org,
repo: repo,
path: path
})
return file.content
if (ref) {
const {data: file} = await client.repos.getContent({
owner: org,
repo: repo,
path: path,
ref: ref
})
return file.content
} else {
const {data: file} = await client.repos.getContent({
owner: org,
repo: repo,
path: path,
})
return file.content
}
} catch (err) {
core.setFailed(`Fail to retrieve file ${path}: ${err.message}`)
process.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "actions-variable-groups",
"version": "1.0.0",
"description": "",
"description": "Allows for the central management of environment variables across multiple GitHub Actions workflows",
"main": "index.js",
"scripts": {
"build": "./node_modules/.bin/ncc build index.js"
},
"keywords": [],
"author": "",
"author": "Brett Logan",
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.6.0",
Expand Down

0 comments on commit 9837515

Please sign in to comment.