Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Batch (#10)
Browse files Browse the repository at this point in the history
* add batch mode

* Update version of aws-sdk

* Fix property assignment
  • Loading branch information
matt-tyler authored Dec 1, 2020
1 parent 4513338 commit 47344d8
Show file tree
Hide file tree
Showing 6 changed files with 1,720 additions and 548 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
env-vars-for-codebuild:
description: 'Comma separated list of environment variables to send to CodeBuild'
required: false
batch:
description: 'Use batch mode'
required: false
default: 'false'
outputs:
aws-build-id:
description: 'The AWS CodeBuild Build ID for this build.'
Expand Down
15 changes: 11 additions & 4 deletions code-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ function runBuild() {
const { headers } = inputs;
const params = inputs2Parameters(inputs);

return build(sdk, params, headers);
return build(sdk, inputs.batch, params, headers);
}

async function build(sdk, params, headers) {
async function build(sdk, batch, params, headers) {
// Start the build
//const makeRequest = sdk.useCredentials ? sdk.codeBuild.makeRequest : sdk.codeBuild.makeUnauthenticatedRequest;
const req = sdk.codeBuild.startBuild(params);
const req = batch ? sdk.codeBuild.startBuildBatch(params) : sdk.codeBuild.startBuild(params);
if (!sdk.useCredentials) {
req.toUnauthenticated();
}
Expand All @@ -41,6 +41,11 @@ async function build(sdk, params, headers) {

const start = await req.promise();

if (batch) {
const { id, buildBatchStatus: buildStatus } = start.buildBatch;
return { id, buildStatus };
}

// Wait for the build to "complete"
return waitForBuildEndTime(sdk, start.build, null, headers);
}
Expand Down Expand Up @@ -129,7 +134,7 @@ async function waitForBuildEndTime(sdk, { id, logs }, nextToken, headers) {
events.forEach(({ message }) => console.log(message.trimEnd()));

// We did it! We can stop looking!
if (current.endTime && !events.length) return current;
if (current.endTime && !events.length) return { id: current.id, buildStatus: current.buildStatus };

// More to do: Sleep for a few seconds to avoid rate limiting
await new Promise((resolve) => setTimeout(resolve, wait));
Expand All @@ -140,6 +145,7 @@ async function waitForBuildEndTime(sdk, { id, logs }, nextToken, headers) {

function githubInputs() {
const projectName = core.getInput("project-name", { required: true });
const batch = core.getInput("batch") === "true" ? true : false;
// const { owner, repo } = github.context.repo;
const { payload } = github.context;
// The github.context.sha is evaluated on import.
Expand Down Expand Up @@ -176,6 +182,7 @@ function githubInputs() {
// owner,
// repo,
// sourceVersion,
batch,
buildspecOverride,
envPassthrough,
headers,
Expand Down
2,218 changes: 1,689 additions & 529 deletions dist/index.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ module.exports = run;
async function run() {
console.log("*****STARTING CODEBUILD*****");
try {
const build = await runBuild();
core.setOutput("aws-build-id", build.id);
const { id, buildStatus } = await runBuild();
core.setOutput("aws-build-id", id);

const status = new Set(["SUCCEEDED", "IN_PROGRESS"]);
// Signal the outcome
assert(
build.buildStatus === "SUCCEEDED",
`Build status: ${build.buildStatus}`
status.has(buildStatus),
`Build status: ${buildStatus}`
);
} catch (error) {
console.log(error);
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3",
"@actions/github": "^2.1.1",
"aws-sdk": "^2.654.0",
"aws-sdk": "^2.799.0",
"uuid": "^3.4.0",
"yargs": "^15.3.1"
},
Expand Down

0 comments on commit 47344d8

Please sign in to comment.