Skip to content

Commit a6e29fe

Browse files
authored
Merge pull request #100 from ronakfof/add-override-params
Add override params
2 parents 95cc38b + e4f6d63 commit a6e29fe

File tree

6 files changed

+139
-2
lines changed

6 files changed

+139
-2
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ The only required input is `project-name`.
2222
that CodeBuild requires.
2323
By default, the action uses the buildspec file location
2424
that you configured in the CodeBuild project.
25+
1. **compute-type-override** (optional) :
26+
The name of a compute type for this build that overrides the one specified
27+
in the build project.
28+
1. **environment-type-override** (optional) :
29+
A container type for this build that overrides the one specified in the
30+
build project.
31+
1. **image-override** (optional) :
32+
The name of an image for this build that overrides the one specified
33+
in the build project.
2534
1. **env-vars-for-codebuild** (optional) :
2635
A comma-separated list of the names of environment variables
2736
that the action passes from GitHub Actions to CodeBuild.
@@ -162,6 +171,9 @@ this will overwrite them.
162171
with:
163172
project-name: CodeBuildProjectName
164173
buildspec-override: path/to/buildspec.yaml
174+
compute-type-override: compute-type
175+
environment-type-override: environment-type
176+
image-override: ecr-image-uri
165177
env-vars-for-codebuild: |
166178
custom,
167179
requester,

action.yml

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ inputs:
1010
buildspec-override:
1111
description: 'Buildspec Override'
1212
required: false
13+
compute-type-override:
14+
description: 'The name of a compute type for this build that overrides the one specified in the build project.'
15+
required: false
16+
environment-type-override:
17+
description: 'A container type for this build that overrides the one specified in the build project.'
18+
required: false
19+
image-override:
20+
description: 'The name of an image for this build that overrides the one specified in the build project.'
21+
required: false
1322
env-vars-for-codebuild:
1423
description: 'Comma separated list of environment variables to send to CodeBuild'
1524
required: false

code-build.js

+17
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ function githubInputs() {
169169
const buildspecOverride =
170170
core.getInput("buildspec-override", { required: false }) || undefined;
171171

172+
const computeTypeOverride =
173+
core.getInput("compute-type-override", { required: false }) || undefined;
174+
175+
const environmentTypeOverride =
176+
core.getInput("environment-type-override", { required: false }) || undefined;
177+
const imageOverride =
178+
core.getInput("image-override", { required: false }) || undefined;
179+
172180
const envPassthrough = core
173181
.getInput("env-vars-for-codebuild", { required: false })
174182
.split(",")
@@ -181,6 +189,9 @@ function githubInputs() {
181189
repo,
182190
sourceVersion,
183191
buildspecOverride,
192+
computeTypeOverride,
193+
environmentTypeOverride,
194+
imageOverride,
184195
envPassthrough,
185196
};
186197
}
@@ -192,6 +203,9 @@ function inputs2Parameters(inputs) {
192203
repo,
193204
sourceVersion,
194205
buildspecOverride,
206+
computeTypeOverride,
207+
environmentTypeOverride,
208+
imageOverride,
195209
envPassthrough = [],
196210
} = inputs;
197211

@@ -212,6 +226,9 @@ function inputs2Parameters(inputs) {
212226
sourceTypeOverride,
213227
sourceLocationOverride,
214228
buildspecOverride,
229+
computeTypeOverride,
230+
environmentTypeOverride,
231+
imageOverride,
215232
environmentVariablesOverride,
216233
};
217234
}

dist/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -295409,7 +295409,12 @@ module.exports = /******/ (function (modules, runtime) {
295409295409
assert(sourceVersion, "No source version could be evaluated.");
295410295410
const buildspecOverride =
295411295411
core.getInput("buildspec-override", { required: false }) || undefined;
295412-
295412+
const computeTypeOverride =
295413+
core.getInput("compute-type-override", { required: false }) || undefined;
295414+
const environmentTypeOverride =
295415+
core.getInput("environment-type-override", { required: false }) || undefined;
295416+
const imageOverride =
295417+
core.getInput("image-override", { required: false }) || undefined;
295413295418
const envPassthrough = core
295414295419
.getInput("env-vars-for-codebuild", { required: false })
295415295420
.split(",")
@@ -295422,6 +295427,9 @@ module.exports = /******/ (function (modules, runtime) {
295422295427
repo,
295423295428
sourceVersion,
295424295429
buildspecOverride,
295430+
computeTypeOverride,
295431+
environmentTypeOverride,
295432+
imageOverride,
295425295433
envPassthrough,
295426295434
};
295427295435
}
@@ -295433,6 +295441,9 @@ module.exports = /******/ (function (modules, runtime) {
295433295441
repo,
295434295442
sourceVersion,
295435295443
buildspecOverride,
295444+
computeTypeOverride,
295445+
environmentTypeOverride,
295446+
imageOverride,
295436295447
envPassthrough = [],
295437295448
} = inputs;
295438295449

@@ -295453,6 +295464,9 @@ module.exports = /******/ (function (modules, runtime) {
295453295464
sourceTypeOverride,
295454295465
sourceLocationOverride,
295455295466
buildspecOverride,
295467+
computeTypeOverride,
295468+
environmentTypeOverride,
295469+
imageOverride,
295456295470
environmentVariablesOverride,
295457295471
};
295458295472
}

local.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const cb = require("./code-build");
88
const assert = require("assert");
99
const yargs = require("yargs");
1010

11-
const { projectName, buildspecOverride, envPassthrough, remote } = yargs
11+
const { projectName, buildspecOverride, computeTypeOverride, environmentTypeOverride, imageOverride, envPassthrough, remote } = yargs
1212
.option("project-name", {
1313
alias: "p",
1414
describe: "AWS CodeBuild Project Name",
@@ -20,6 +20,21 @@ const { projectName, buildspecOverride, envPassthrough, remote } = yargs
2020
describe: "Path to buildspec file",
2121
type: "string",
2222
})
23+
.option("compute-type-override", {
24+
alias: "c",
25+
describe: "The name of a compute type for this build that overrides the one specified in the build project.",
26+
type: "string",
27+
})
28+
.option("environment-type-override", {
29+
alias: "et",
30+
describe: "A container type for this build that overrides the one specified in the build project.",
31+
type: "string",
32+
})
33+
.option("image-override", {
34+
alias: "i",
35+
describe: "The name of an image for this build that overrides the one specified in the build project.",
36+
type: "string",
37+
})
2338
.option("env-vars-for-codebuild", {
2439
alias: "e",
2540
describe: "List of environment variables to send to CodeBuild",
@@ -39,6 +54,9 @@ const params = cb.inputs2Parameters({
3954
...githubInfo(remote),
4055
sourceVersion: BRANCH_NAME,
4156
buildspecOverride,
57+
computeTypeOverride,
58+
environmentTypeOverride,
59+
imageOverride,
4260
envPassthrough,
4361
});
4462

test/code-build-test.js

+67
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ describe("githubInputs", () => {
7171
expect(test)
7272
.to.haveOwnProperty("buildspecOverride")
7373
.and.to.equal(undefined);
74+
expect(test).to.haveOwnProperty("computeTypeOverride").and.to.equal(undefined);
75+
expect(test).to.haveOwnProperty("environmentTypeOverride").and.to.equal(undefined);
76+
expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined);
7477
expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]);
7578
});
7679

@@ -120,6 +123,9 @@ describe("githubInputs", () => {
120123
expect(test)
121124
.to.haveOwnProperty("buildspecOverride")
122125
.and.to.equal(undefined);
126+
expect(test).to.haveOwnProperty("computeTypeOverride").and.to.equal(undefined);
127+
expect(test).to.haveOwnProperty("environmentTypeOverride").and.to.equal(undefined);
128+
expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined);
123129
expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]);
124130
});
125131

@@ -173,6 +179,67 @@ describe("inputs2Parameters", () => {
173179
expect(test)
174180
.to.haveOwnProperty("buildspecOverride")
175181
.and.to.equal(undefined);
182+
expect(test).to.haveOwnProperty("computeTypeOverride").and.to.equal(undefined);
183+
expect(test).to.haveOwnProperty("environmentTypeOverride").and.to.equal(undefined);
184+
expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined);
185+
186+
// I send everything that starts 'GITHUB_'
187+
expect(test)
188+
.to.haveOwnProperty("environmentVariablesOverride")
189+
.and.to.have.lengthOf.greaterThan(1);
190+
191+
const [repoEnv] = test.environmentVariablesOverride.filter(
192+
({ name }) => name === "GITHUB_REPOSITORY"
193+
);
194+
expect(repoEnv)
195+
.to.haveOwnProperty("name")
196+
.and.to.equal("GITHUB_REPOSITORY");
197+
expect(repoEnv).to.haveOwnProperty("value").and.to.equal(repoInfo);
198+
expect(repoEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT");
199+
200+
const [shaEnv] = test.environmentVariablesOverride.filter(
201+
({ name }) => name === "GITHUB_SHA"
202+
);
203+
expect(shaEnv).to.haveOwnProperty("name").and.to.equal("GITHUB_SHA");
204+
expect(shaEnv).to.haveOwnProperty("value").and.to.equal(sha);
205+
expect(shaEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT");
206+
});
207+
208+
it("build override parameters for codeBuild.startBuild", () => {
209+
// This is how GITHUB injects its input values.
210+
// It would be nice if there was an easy way to test this...
211+
process.env[`INPUT_PROJECT-NAME`] = projectName;
212+
process.env[`GITHUB_REPOSITORY`] = repoInfo;
213+
process.env[`GITHUB_SHA`] = sha;
214+
const test = inputs2Parameters({
215+
projectName,
216+
sourceVersion: sha,
217+
owner: "owner",
218+
repo: "repo",
219+
computeTypeOverride: "BUILD_GENERAL1_LARGE",
220+
environmentTypeOverride: "LINUX_CONTAINER",
221+
imageOverride: "111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo"
222+
});
223+
expect(test).to.haveOwnProperty("projectName").and.to.equal(projectName);
224+
expect(test).to.haveOwnProperty("sourceVersion").and.to.equal(sha);
225+
expect(test)
226+
.to.haveOwnProperty("sourceTypeOverride")
227+
.and.to.equal("GITHUB");
228+
expect(test)
229+
.to.haveOwnProperty("sourceLocationOverride")
230+
.and.to.equal(`https://github.com/owner/repo.git`);
231+
expect(test)
232+
.to.haveOwnProperty("buildspecOverride")
233+
.and.to.equal(undefined);
234+
expect(test)
235+
.to.haveOwnProperty("computeTypeOverride")
236+
.and.to.equal(`BUILD_GENERAL1_LARGE`);
237+
expect(test)
238+
.to.haveOwnProperty("environmentTypeOverride")
239+
.and.to.equal(`LINUX_CONTAINER`);
240+
expect(test)
241+
.to.haveOwnProperty("imageOverride")
242+
.and.to.equal(`111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo`);
176243

177244
// I send everything that starts 'GITHUB_'
178245
expect(test)

0 commit comments

Comments
 (0)