diff --git a/README.md b/README.md index 06c8237..ed5389f 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,15 @@ The only required input is `project-name`. that CodeBuild requires. By default, the action uses the buildspec file location that you configured in the CodeBuild project. +1. **compute-type-override** (optional) : + The name of a compute type for this build that overrides the one specified + in the build project. +1. **environment-type-override** (optional) : + A container type for this build that overrides the one specified in the + build project. +1. **image-override** (optional) : + The name of an image for this build that overrides the one specified + in the build project. 1. **env-vars-for-codebuild** (optional) : A comma-separated list of the names of environment variables that the action passes from GitHub Actions to CodeBuild. @@ -162,6 +171,9 @@ this will overwrite them. with: project-name: CodeBuildProjectName buildspec-override: path/to/buildspec.yaml + compute-type-override: compute-type + environment-type-override: environment-type + image-override: ecr-image-uri env-vars-for-codebuild: | custom, requester, diff --git a/action.yml b/action.yml index ba01cde..2071962 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,15 @@ inputs: buildspec-override: description: 'Buildspec Override' required: false + compute-type-override: + description: 'The name of a compute type for this build that overrides the one specified in the build project.' + required: false + environment-type-override: + description: 'A container type for this build that overrides the one specified in the build project.' + required: false + image-override: + description: 'The name of an image for this build that overrides the one specified in the build project.' + required: false env-vars-for-codebuild: description: 'Comma separated list of environment variables to send to CodeBuild' required: false diff --git a/code-build.js b/code-build.js index c73ce40..fae10d6 100644 --- a/code-build.js +++ b/code-build.js @@ -169,6 +169,14 @@ function githubInputs() { const buildspecOverride = core.getInput("buildspec-override", { required: false }) || undefined; + const computeTypeOverride = + core.getInput("compute-type-override", { required: false }) || undefined; + + const environmentTypeOverride = + core.getInput("environment-type-override", { required: false }) || undefined; + const imageOverride = + core.getInput("image-override", { required: false }) || undefined; + const envPassthrough = core .getInput("env-vars-for-codebuild", { required: false }) .split(",") @@ -181,6 +189,9 @@ function githubInputs() { repo, sourceVersion, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, envPassthrough, }; } @@ -192,6 +203,9 @@ function inputs2Parameters(inputs) { repo, sourceVersion, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, envPassthrough = [], } = inputs; @@ -212,6 +226,9 @@ function inputs2Parameters(inputs) { sourceTypeOverride, sourceLocationOverride, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, environmentVariablesOverride, }; } diff --git a/dist/index.js b/dist/index.js index a49cfe4..e288ea1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -295409,7 +295409,12 @@ module.exports = /******/ (function (modules, runtime) { assert(sourceVersion, "No source version could be evaluated."); const buildspecOverride = core.getInput("buildspec-override", { required: false }) || undefined; - + const computeTypeOverride = + core.getInput("compute-type-override", { required: false }) || undefined; + const environmentTypeOverride = + core.getInput("environment-type-override", { required: false }) || undefined; + const imageOverride = + core.getInput("image-override", { required: false }) || undefined; const envPassthrough = core .getInput("env-vars-for-codebuild", { required: false }) .split(",") @@ -295422,6 +295427,9 @@ module.exports = /******/ (function (modules, runtime) { repo, sourceVersion, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, envPassthrough, }; } @@ -295433,6 +295441,9 @@ module.exports = /******/ (function (modules, runtime) { repo, sourceVersion, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, envPassthrough = [], } = inputs; @@ -295453,6 +295464,9 @@ module.exports = /******/ (function (modules, runtime) { sourceTypeOverride, sourceLocationOverride, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, environmentVariablesOverride, }; } diff --git a/local.js b/local.js index 82868ff..45eec45 100755 --- a/local.js +++ b/local.js @@ -8,7 +8,7 @@ const cb = require("./code-build"); const assert = require("assert"); const yargs = require("yargs"); -const { projectName, buildspecOverride, envPassthrough, remote } = yargs +const { projectName, buildspecOverride, computeTypeOverride, environmentTypeOverride, imageOverride, envPassthrough, remote } = yargs .option("project-name", { alias: "p", describe: "AWS CodeBuild Project Name", @@ -20,6 +20,21 @@ const { projectName, buildspecOverride, envPassthrough, remote } = yargs describe: "Path to buildspec file", type: "string", }) + .option("compute-type-override", { + alias: "c", + describe: "The name of a compute type for this build that overrides the one specified in the build project.", + type: "string", + }) + .option("environment-type-override", { + alias: "et", + describe: "A container type for this build that overrides the one specified in the build project.", + type: "string", + }) + .option("image-override", { + alias: "i", + describe: "The name of an image for this build that overrides the one specified in the build project.", + type: "string", + }) .option("env-vars-for-codebuild", { alias: "e", describe: "List of environment variables to send to CodeBuild", @@ -39,6 +54,9 @@ const params = cb.inputs2Parameters({ ...githubInfo(remote), sourceVersion: BRANCH_NAME, buildspecOverride, + computeTypeOverride, + environmentTypeOverride, + imageOverride, envPassthrough, }); diff --git a/test/code-build-test.js b/test/code-build-test.js index 3a36908..944b4dd 100644 --- a/test/code-build-test.js +++ b/test/code-build-test.js @@ -71,6 +71,9 @@ describe("githubInputs", () => { expect(test) .to.haveOwnProperty("buildspecOverride") .and.to.equal(undefined); + expect(test).to.haveOwnProperty("computeTypeOverride").and.to.equal(undefined); + expect(test).to.haveOwnProperty("environmentTypeOverride").and.to.equal(undefined); + expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined); expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]); }); @@ -120,6 +123,9 @@ describe("githubInputs", () => { expect(test) .to.haveOwnProperty("buildspecOverride") .and.to.equal(undefined); + expect(test).to.haveOwnProperty("computeTypeOverride").and.to.equal(undefined); + expect(test).to.haveOwnProperty("environmentTypeOverride").and.to.equal(undefined); + expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined); expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]); }); @@ -173,6 +179,67 @@ describe("inputs2Parameters", () => { expect(test) .to.haveOwnProperty("buildspecOverride") .and.to.equal(undefined); + expect(test).to.haveOwnProperty("computeTypeOverride").and.to.equal(undefined); + expect(test).to.haveOwnProperty("environmentTypeOverride").and.to.equal(undefined); + expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined); + + // I send everything that starts 'GITHUB_' + expect(test) + .to.haveOwnProperty("environmentVariablesOverride") + .and.to.have.lengthOf.greaterThan(1); + + const [repoEnv] = test.environmentVariablesOverride.filter( + ({ name }) => name === "GITHUB_REPOSITORY" + ); + expect(repoEnv) + .to.haveOwnProperty("name") + .and.to.equal("GITHUB_REPOSITORY"); + expect(repoEnv).to.haveOwnProperty("value").and.to.equal(repoInfo); + expect(repoEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT"); + + const [shaEnv] = test.environmentVariablesOverride.filter( + ({ name }) => name === "GITHUB_SHA" + ); + expect(shaEnv).to.haveOwnProperty("name").and.to.equal("GITHUB_SHA"); + expect(shaEnv).to.haveOwnProperty("value").and.to.equal(sha); + expect(shaEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT"); + }); + + it("build override parameters for codeBuild.startBuild", () => { + // This is how GITHUB injects its input values. + // It would be nice if there was an easy way to test this... + process.env[`INPUT_PROJECT-NAME`] = projectName; + process.env[`GITHUB_REPOSITORY`] = repoInfo; + process.env[`GITHUB_SHA`] = sha; + const test = inputs2Parameters({ + projectName, + sourceVersion: sha, + owner: "owner", + repo: "repo", + computeTypeOverride: "BUILD_GENERAL1_LARGE", + environmentTypeOverride: "LINUX_CONTAINER", + imageOverride: "111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo" + }); + expect(test).to.haveOwnProperty("projectName").and.to.equal(projectName); + expect(test).to.haveOwnProperty("sourceVersion").and.to.equal(sha); + expect(test) + .to.haveOwnProperty("sourceTypeOverride") + .and.to.equal("GITHUB"); + expect(test) + .to.haveOwnProperty("sourceLocationOverride") + .and.to.equal(`https://github.com/owner/repo.git`); + expect(test) + .to.haveOwnProperty("buildspecOverride") + .and.to.equal(undefined); + expect(test) + .to.haveOwnProperty("computeTypeOverride") + .and.to.equal(`BUILD_GENERAL1_LARGE`); + expect(test) + .to.haveOwnProperty("environmentTypeOverride") + .and.to.equal(`LINUX_CONTAINER`); + expect(test) + .to.haveOwnProperty("imageOverride") + .and.to.equal(`111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo`); // I send everything that starts 'GITHUB_' expect(test)