Skip to content

Commit e951dae

Browse files
committed
Disabled GITHUB Envs being passed to Codebuild
1 parent 2e69f61 commit e951dae

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

README.md

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

115+
1. **disable-github-env-vars** (optional) :
116+
Set to `true` if you want do disable github environment variables in codebuild.
117+
115118
### Outputs
116119

117120
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
@@ -34,6 +34,9 @@ inputs:
3434
hide-cloudwatch-logs:
3535
description: 'Set to `true` to prevent the CloudWatch logs from streaming the output to GitHub'
3636
required: false
37+
disable-github-env-vars:
38+
description: 'Set to `true` if you want do disable github environment variables in codebuild'
39+
required: false
3740
outputs:
3841
aws-build-id:
3942
description: 'The AWS CodeBuild Build ID for this build.'

code-build.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ function githubInputs() {
167167
const projectName = core.getInput("project-name", { required: true });
168168
const disableSourceOverride =
169169
core.getInput("disable-source-override", { required: false }) === "true";
170+
const disableGithubEnvVars =
171+
core.getInput("disable-github-env-vars", { required: false }) === "true";
170172
const { owner, repo } = github.context.repo;
171173
const { payload } = github.context;
172174
// The github.context.sha is evaluated on import.
@@ -227,6 +229,7 @@ function githubInputs() {
227229
updateBackOff,
228230
disableSourceOverride,
229231
hideCloudWatchLogs,
232+
disableGithubEnvVars,
230233
};
231234
}
232235

@@ -242,6 +245,7 @@ function inputs2Parameters(inputs) {
242245
imageOverride,
243246
envPassthrough = [],
244247
disableSourceOverride,
248+
disableGithubEnvVars,
245249
} = inputs;
246250

247251
const sourceOverride = !disableSourceOverride
@@ -254,7 +258,9 @@ function inputs2Parameters(inputs) {
254258

255259
const environmentVariablesOverride = Object.entries(process.env)
256260
.filter(
257-
([key]) => key.startsWith("GITHUB_") || envPassthrough.includes(key)
261+
([key]) =>
262+
(!disableGithubEnvVars && key.startsWith("GITHUB_")) ||
263+
envPassthrough.includes(key)
258264
)
259265
.map(([name, value]) => ({ name, value, type: "PLAINTEXT" }));
260266

test/code-build-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe("githubInputs", () => {
8585
expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined);
8686
expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]);
8787
expect(test).to.haveOwnProperty("hideCloudWatchLogs").and.to.equal(false);
88+
expect(test).to.haveOwnProperty("disableGithubEnvVars").and.to.equal(false);
8889
});
8990

9091
it("a project name is required.", () => {
@@ -400,6 +401,29 @@ describe("inputs2Parameters", () => {
400401
expect(test).to.not.haveOwnProperty("sourceLocationOverride");
401402
expect(test).to.not.haveOwnProperty("sourceVersion");
402403
});
404+
405+
it("can process disable-github-env-vars", () => {
406+
process.env[`GITHUB_REPOSITORY`] = repoInfo;
407+
process.env[`GITHUB_SHA`] = sha;
408+
409+
const test = inputs2Parameters({
410+
projectName,
411+
sourceVersion: sha,
412+
owner: "owner",
413+
repo: "repo",
414+
disableGithubEnvVars: true,
415+
});
416+
417+
const [repoEnv] = test.environmentVariablesOverride.filter(
418+
({ name }) => name === "GITHUB_REPOSITORY"
419+
);
420+
expect(repoEnv).to.equal(undefined);
421+
422+
const [shaEnv] = test.environmentVariablesOverride.filter(
423+
({ name }) => name === "GITHUB_SHA"
424+
);
425+
expect(shaEnv).to.equal(undefined);
426+
});
403427
});
404428

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

0 commit comments

Comments
 (0)