Skip to content

Commit

Permalink
Merge pull request #100 from ronakfof/add-override-params
Browse files Browse the repository at this point in the history
Add override params
  • Loading branch information
linghaoz authored Aug 2, 2022
2 parents 95cc38b + e4f6d63 commit a6e29fe
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions code-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand All @@ -181,6 +189,9 @@ function githubInputs() {
repo,
sourceVersion,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
envPassthrough,
};
}
Expand All @@ -192,6 +203,9 @@ function inputs2Parameters(inputs) {
repo,
sourceVersion,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
envPassthrough = [],
} = inputs;

Expand All @@ -212,6 +226,9 @@ function inputs2Parameters(inputs) {
sourceTypeOverride,
sourceLocationOverride,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
environmentVariablesOverride,
};
}
Expand Down
16 changes: 15 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand All @@ -295422,6 +295427,9 @@ module.exports = /******/ (function (modules, runtime) {
repo,
sourceVersion,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
envPassthrough,
};
}
Expand All @@ -295433,6 +295441,9 @@ module.exports = /******/ (function (modules, runtime) {
repo,
sourceVersion,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
envPassthrough = [],
} = inputs;

Expand All @@ -295453,6 +295464,9 @@ module.exports = /******/ (function (modules, runtime) {
sourceTypeOverride,
sourceLocationOverride,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
environmentVariablesOverride,
};
}
Expand Down
20 changes: 19 additions & 1 deletion local.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -39,6 +54,9 @@ const params = cb.inputs2Parameters({
...githubInfo(remote),
sourceVersion: BRANCH_NAME,
buildspecOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
envPassthrough,
});

Expand Down
67 changes: 67 additions & 0 deletions test/code-build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});

Expand Down Expand Up @@ -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([]);
});

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a6e29fe

Please sign in to comment.