Skip to content

Commit

Permalink
Fix logic to get branch name (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfespa17 authored Sep 29, 2022
1 parent 907d543 commit 61b1aa6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Add the following snippet to the script section of your github actions file:
jobs:
build:
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.release.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: AzBuilder/terrakube-action-github@1.0.0
Expand All @@ -20,6 +18,7 @@ jobs:
TERRAKUBE_TEMPLATE: "vulnerability-snyk"
TERRAKUBE_REPOSITORY: "https://github.com/AzBuilder/terraform-sample-repository.git"
TERRAKUBE_ENDPOINT: "https://terrakube.interal/service"
TERRAKUBE_BRANCH: ${{ github.event.pull_request.base.ref }}
GITHUB_TOKEN: "xxxx"
```
Expand All @@ -31,6 +30,7 @@ jobs:
| TERRAKUBE_REPOSITORY (*) | Terrakube git repository |
| TERRAKUBE_TEMPLATE (*) | Terrakube template name |
| TERRAKUBE_ENDPOINT (*) | Terrakbue api endpoint |
| TERRAKUBE_BRANCH (*) | Github Branch when running a job |
| GITHUB_TOKEN (*) | Github Token |
_(*) = required variable._
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
TERRAKUBE_TEMPLATE:
description: 'Terrakube Template'
required: true
TERRAKUBE_BRANCH:
description: 'Branch to run the job'
required: true
TOKEN:
description: 'Github Token'
required: true
Expand Down
11 changes: 5 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const terrakube_1 = require("./terrakube");
const promises_1 = require("fs/promises");
function run() {
var e_1, _a;
var _b, _c;
return __awaiter(this, void 0, void 0, function* () {
try {
const githubActionInput = yield (0, userInput_1.getActionInput)();
Expand All @@ -63,8 +62,8 @@ function run() {
const currentDirectory = yield getCurrentDirectory();
console.debug(`Processing: ${currentDirectory}`);
try {
for (var _d = __asyncValues(globber.globGenerator()), _e; _e = yield _d.next(), !_e.done;) {
const file = _e.value;
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
const file = _c.value;
const terrakubeData = JSON.parse(yield (0, promises_1.readFile)(`${file}`, "utf8"));
core.startGroup(`Execute Workspace ${terrakubeData.workspace}`);
console.debug(`Processing: ${file}`);
Expand All @@ -75,8 +74,8 @@ function run() {
core.info(`Workspace: ${terrakubeData.workspace}`);
core.info(`Folder: ${terrakubeData.folder}`);
core.info(`Action branch: ${process.env.GITHUB_REF}`);
core.info(`Branch: ${(_b = process.env.GITHUB_REF) === null || _b === void 0 ? void 0 : _b.toString().split("/")[2]}`);
terrakubeData.branch = (_c = process.env.GITHUB_REF) === null || _c === void 0 ? void 0 : _c.toString().split("/")[2];
core.info(`Branch: ${githubActionInput.branch}`);
terrakubeData.branch = githubActionInput.branch;
//Object.keys(terrakubeData.variables).forEach(key => {
// console.log('Key : ' + key + ', Value : ' + terrakubeData.variables[key])
//})
Expand Down Expand Up @@ -131,7 +130,7 @@ function run() {
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_e && !_e.done && (_a = _d.return)) yield _a.call(_d);
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
Expand Down
5 changes: 4 additions & 1 deletion dist/userInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ function getActionInput() {
core.debug(`Terrakube Repository: ${terrakubeRepository}`);
const terrakubeTemplate = core.getInput('terrakube_template', { required: true });
core.debug(`Terrakube Template: ${terrakubeTemplate}`);
const terrakubeBranch = core.getInput('terrakube_branch', { required: true });
core.debug(`Terrakube Branch: ${terrakubeTemplate}`);
const githubToken = core.getInput('token', { required: true });
const terrakubeActionInput = {
token: terrakubeToken,
terrakubeEndpoint: terrakubeEndpoint,
terrakubeRepository: terrakubeRepository,
terrakubeTemplate: terrakubeTemplate,
githubToken: githubToken
githubToken: githubToken,
branch: terrakubeBranch
};
return terrakubeActionInput;
});
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ async function run(): Promise<void> {
core.info(`Workspace: ${terrakubeData.workspace}`)
core.info(`Folder: ${terrakubeData.folder}`)
core.info(`Action branch: ${process.env.GITHUB_REF}`)
core.info(`Branch: ${process.env.GITHUB_REF?.toString().split("/")[2]}`)
terrakubeData.branch = process.env.GITHUB_REF?.toString().split("/")[2];
core.info(`Branch: ${githubActionInput.branch}`)
terrakubeData.branch = githubActionInput.branch

//Object.keys(terrakubeData.variables).forEach(key => {
// console.log('Key : ' + key + ', Value : ' + terrakubeData.variables[key])
Expand Down
9 changes: 7 additions & 2 deletions src/userInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export interface GitHubActionInput{
terrakubeEndpoint: string,
terrakubeRepository: string,
terrakubeTemplate: string,
githubToken: string
githubToken: string,
branch: string
}

export async function getActionInput(): Promise<any>{
Expand All @@ -21,14 +22,18 @@ export async function getActionInput(): Promise<any>{
const terrakubeTemplate: string = core.getInput('terrakube_template', { required: true })
core.debug(`Terrakube Template: ${terrakubeTemplate}`)

const terrakubeBranch: string = core.getInput('terrakube_branch', { required: true })
core.debug(`Terrakube Branch: ${terrakubeBranch}`)

const githubToken: string = core.getInput('token', { required: true })

const terrakubeActionInput:GitHubActionInput = {
token: terrakubeToken,
terrakubeEndpoint: terrakubeEndpoint,
terrakubeRepository: terrakubeRepository,
terrakubeTemplate: terrakubeTemplate,
githubToken: githubToken
githubToken: githubToken,
branch: terrakubeBranch
}

return terrakubeActionInput
Expand Down

0 comments on commit 61b1aa6

Please sign in to comment.