Skip to content

Commit

Permalink
Merge pull request #144 from benconnito/main
Browse files Browse the repository at this point in the history
allow artifacts type to be overridden
  • Loading branch information
taoyong-ty authored Jan 31, 2024
2 parents 6e37b5c + d8df16c commit 8802399
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ inputs:
disable-github-env-vars:
description: 'Set to `true` if you want do disable github environment variables in codebuild'
required: false
artifacts-type-override:
description: 'The type of build output artifact'
required: false
outputs:
aws-build-id:
description: 'The AWS CodeBuild Build ID for this build.'
Expand Down
14 changes: 14 additions & 0 deletions code-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ function githubInputs() {
const disableGithubEnvVars =
core.getInput("disable-github-env-vars", { required: false }) === "true";

const artifactsTypeOverride =
core.getInput("artifacts-type-override", { required: false }) || undefined;

return {
projectName,
owner,
Expand All @@ -239,6 +242,7 @@ function githubInputs() {
disableSourceOverride,
hideCloudWatchLogs,
disableGithubEnvVars,
artifactsTypeOverride,
};
}

Expand All @@ -256,6 +260,7 @@ function inputs2Parameters(inputs) {
envPassthrough = [],
disableSourceOverride,
disableGithubEnvVars,
artifactsTypeOverride,
} = inputs;

const sourceOverride = !disableSourceOverride
Expand All @@ -266,6 +271,14 @@ function inputs2Parameters(inputs) {
}
: {};

const artifactsOverride = artifactsTypeOverride
? {
artifactsOverride: {
type: artifactsTypeOverride,
},
}
: {};

const environmentVariablesOverride = Object.entries(process.env)
.filter(
([key]) =>
Expand All @@ -280,6 +293,7 @@ function inputs2Parameters(inputs) {
projectName,
...sourceOverride,
buildspecOverride,
...artifactsOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
Expand Down
14 changes: 14 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ function githubInputs() {
const disableGithubEnvVars =
core.getInput("disable-github-env-vars", { required: false }) === "true";

const artifactsTypeOverride =
core.getInput("artifacts-type-override", { required: false }) || undefined;

return {
projectName,
owner,
Expand All @@ -245,6 +248,7 @@ function githubInputs() {
disableSourceOverride,
hideCloudWatchLogs,
disableGithubEnvVars,
artifactsTypeOverride,
};
}

Expand All @@ -262,6 +266,7 @@ function inputs2Parameters(inputs) {
envPassthrough = [],
disableSourceOverride,
disableGithubEnvVars,
artifactsTypeOverride,
} = inputs;

const sourceOverride = !disableSourceOverride
Expand All @@ -272,6 +277,14 @@ function inputs2Parameters(inputs) {
}
: {};

const artifactsOverride = artifactsTypeOverride
? {
artifactsOverride: {
type: artifactsTypeOverride,
},
}
: {};

const environmentVariablesOverride = Object.entries(process.env)
.filter(
([key]) =>
Expand All @@ -286,6 +299,7 @@ function inputs2Parameters(inputs) {
projectName,
...sourceOverride,
buildspecOverride,
...artifactsOverride,
computeTypeOverride,
environmentTypeOverride,
imageOverride,
Expand Down
9 changes: 7 additions & 2 deletions test/code-build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("githubInputs", () => {
process.env[`GITHUB_REPOSITORY`] = repoInfo;
process.env[`GITHUB_SHA`] = sha;

process.env[`INPUT_ENV-VARS-FOR-CODEBUILD`] = `one, two
process.env[`INPUT_ENV-VARS-FOR-CODEBUILD`] = `one, two
, three,
four `;

Expand Down Expand Up @@ -296,6 +296,7 @@ describe("inputs2Parameters", () => {
imageOverride:
"111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo",
imagePullCredentialsTypeOverride: "CODEBUILD",
artifactsTypeOverride: "NO_ARTIFACTS",
});
expect(test).to.haveOwnProperty("projectName").and.to.equal(projectName);
expect(test).to.haveOwnProperty("sourceVersion").and.to.equal(sha);
Expand All @@ -305,6 +306,10 @@ describe("inputs2Parameters", () => {
expect(test)
.to.haveOwnProperty("sourceLocationOverride")
.and.to.equal(`https://github.com/owner/repo.git`);
expect(test)
.to.haveOwnProperty("artifactsOverride")
.that.has.property("type")
.that.equals("NO_ARTIFACTS");
expect(test)
.to.haveOwnProperty("buildspecOverride")
.and.to.equal(undefined);
Expand Down Expand Up @@ -352,7 +357,7 @@ describe("inputs2Parameters", () => {
process.env[`GITHUB_REPOSITORY`] = repoInfo;
process.env[`GITHUB_SHA`] = sha;

process.env[`INPUT_ENV-VARS-FOR-CODEBUILD`] = `one, two
process.env[`INPUT_ENV-VARS-FOR-CODEBUILD`] = `one, two
, three,
four `;

Expand Down

0 comments on commit 8802399

Please sign in to comment.