Skip to content

Commit cc27260

Browse files
authored
Merge branch 'main' into fix/140
2 parents d21ca61 + 24e5771 commit cc27260

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ The only required input is `project-name`.
115115
1. **hide-cloudwatch-logs** (optional) :
116116
Set to `true` if you do not want CloudWatch Logs to be streamed to GitHub Action.
117117

118+
1. **disable-github-env-vars** (optional) :
119+
Set to `true` if you want do disable github environment variables in codebuild.
120+
118121
### Outputs
119122

120123
1. **aws-build-id** : The CodeBuild build ID of the build that the action ran.

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ inputs:
3737
hide-cloudwatch-logs:
3838
description: 'Set to `true` to prevent the CloudWatch logs from streaming the output to GitHub'
3939
required: false
40+
disable-github-env-vars:
41+
description: 'Set to `true` if you want do disable github environment variables in codebuild'
42+
required: false
4043
outputs:
4144
aws-build-id:
4245
description: 'The AWS CodeBuild Build ID for this build.'

code-build.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ function githubInputs() {
219219
const hideCloudWatchLogs =
220220
core.getInput("hide-cloudwatch-logs", { required: false }) === "true";
221221

222+
const disableGithubEnvVars =
223+
core.getInput("disable-github-env-vars", { required: false }) === "true";
224+
222225
return {
223226
projectName,
224227
owner,
@@ -234,6 +237,7 @@ function githubInputs() {
234237
updateBackOff,
235238
disableSourceOverride,
236239
hideCloudWatchLogs,
240+
disableGithubEnvVars,
237241
};
238242
}
239243

@@ -250,6 +254,7 @@ function inputs2Parameters(inputs) {
250254
imagePullCredentialsTypeOverride,
251255
envPassthrough = [],
252256
disableSourceOverride,
257+
disableGithubEnvVars,
253258
} = inputs;
254259

255260
const sourceOverride = !disableSourceOverride
@@ -262,7 +267,9 @@ function inputs2Parameters(inputs) {
262267

263268
const environmentVariablesOverride = Object.entries(process.env)
264269
.filter(
265-
([key]) => key.startsWith("GITHUB_") || envPassthrough.includes(key)
270+
([key]) =>
271+
(!disableGithubEnvVars && key.startsWith("GITHUB_")) ||
272+
envPassthrough.includes(key)
266273
)
267274
.map(([name, value]) => ({ name, value, type: "PLAINTEXT" }));
268275

dist/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ function githubInputs() {
225225
const hideCloudWatchLogs =
226226
core.getInput("hide-cloudwatch-logs", { required: false }) === "true";
227227

228+
const disableGithubEnvVars =
229+
core.getInput("disable-github-env-vars", { required: false }) === "true";
230+
228231
return {
229232
projectName,
230233
owner,
@@ -240,6 +243,7 @@ function githubInputs() {
240243
updateBackOff,
241244
disableSourceOverride,
242245
hideCloudWatchLogs,
246+
disableGithubEnvVars,
243247
};
244248
}
245249

@@ -256,6 +260,7 @@ function inputs2Parameters(inputs) {
256260
imagePullCredentialsTypeOverride,
257261
envPassthrough = [],
258262
disableSourceOverride,
263+
disableGithubEnvVars,
259264
} = inputs;
260265

261266
const sourceOverride = !disableSourceOverride
@@ -268,7 +273,9 @@ function inputs2Parameters(inputs) {
268273

269274
const environmentVariablesOverride = Object.entries(process.env)
270275
.filter(
271-
([key]) => key.startsWith("GITHUB_") || envPassthrough.includes(key)
276+
([key]) =>
277+
(!disableGithubEnvVars && key.startsWith("GITHUB_")) ||
278+
envPassthrough.includes(key)
272279
)
273280
.map(([name, value]) => ({ name, value, type: "PLAINTEXT" }));
274281

test/code-build-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("githubInputs", () => {
8888
.and.to.equal(undefined);
8989
expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]);
9090
expect(test).to.haveOwnProperty("hideCloudWatchLogs").and.to.equal(false);
91+
expect(test).to.haveOwnProperty("disableGithubEnvVars").and.to.equal(false);
9192
});
9293

9394
it("a project name is required.", () => {
@@ -413,6 +414,29 @@ describe("inputs2Parameters", () => {
413414
expect(test).to.not.haveOwnProperty("sourceLocationOverride");
414415
expect(test).to.not.haveOwnProperty("sourceVersion");
415416
});
417+
418+
it("can process disable-github-env-vars", () => {
419+
process.env[`GITHUB_REPOSITORY`] = repoInfo;
420+
process.env[`GITHUB_SHA`] = sha;
421+
422+
const test = inputs2Parameters({
423+
projectName,
424+
sourceVersion: sha,
425+
owner: "owner",
426+
repo: "repo",
427+
disableGithubEnvVars: true,
428+
});
429+
430+
const [repoEnv] = test.environmentVariablesOverride.filter(
431+
({ name }) => name === "GITHUB_REPOSITORY"
432+
);
433+
expect(repoEnv).to.equal(undefined);
434+
435+
const [shaEnv] = test.environmentVariablesOverride.filter(
436+
({ name }) => name === "GITHUB_SHA"
437+
);
438+
expect(shaEnv).to.equal(undefined);
439+
});
416440
});
417441

418442
describe("waitForBuildEndTime", () => {

0 commit comments

Comments
 (0)