From a848def82c0ee810b248c906058462e027d7e9c5 Mon Sep 17 00:00:00 2001 From: cbuto_contrast Date: Fri, 2 Jul 2021 09:51:10 -0400 Subject: [PATCH] Add sourceOverride from PR #64 --- README.md | 6 +- action.yml | 3 + code-build.js | 15 +++- dist/index.js | 160 ++++++++++++++++++++++++++++++++++------ test/code-build-test.js | 26 +++++++ 5 files changed, 183 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index fd65e10..960c509 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ 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. **disable-source-override** (optional) : + Set to `true` if you want to disable providing `sourceTypeOverride` and `sourceLocationOverride` to CodeBuild. 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. @@ -210,7 +212,7 @@ In the call to StartBuild, we pass in all `GITHUB_` [environment variables][github environment variables] in the GitHub Actions environment, plus any environment variables that you specified in the `evn-passthrough` input value. -Regardless of the project configuration in CodeBuild or GitHub Actions, +By default, regardless of the project configuration in CodeBuild or GitHub Actions, we always pass the following parameters and values to CodeBuild in the StartBuild API call. | CodeBuild value | GitHub value | @@ -219,6 +221,8 @@ we always pass the following parameters and values to CodeBuild in the StartBuil | `sourceTypeOverride` | The string `'GITHUB'` | | `sourceLocationOverride` | The `HTTPS` git url for `context.repo` | +If you want to disable sending the parameters `sourceTypeOverride` and `sourceLocationOverride` you can use `disable-source-override` input. + ### What we did not do This action intentionally does not let you specify every option diff --git a/action.yml b/action.yml index 8feaae4..fe9bd5a 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: env-vars-for-codebuild: description: 'Comma separated list of environment variables to send to CodeBuild' required: false + disable-source-override: + description: 'Set to `true` if you want do disable source repo override' + required: false outputs: aws-build-id: description: 'The AWS CodeBuild Build ID for this build.' diff --git a/code-build.js b/code-build.js index 3087510..a74fe51 100644 --- a/code-build.js +++ b/code-build.js @@ -110,6 +110,8 @@ async function waitForBuildEndTime(sdk, { id, logs }, nextToken) { function githubInputs() { const projectName = core.getInput("project-name", { required: true }); + const disableSourceOverride = + core.getInput("disable-source-override") === "true"; const { owner, repo } = github.context.repo; const { payload } = github.context; // The github.context.sha is evaluated on import. @@ -140,6 +142,7 @@ function githubInputs() { sourceVersion, buildspecOverride, envPassthrough, + disableSourceOverride, }; } @@ -151,10 +154,15 @@ function inputs2Parameters(inputs) { sourceVersion, buildspecOverride, envPassthrough = [], + disableSourceOverride, } = inputs; - const sourceTypeOverride = "GITHUB"; - const sourceLocationOverride = `https://github.com/${owner}/${repo}.git`; + const sourceOverride = !disableSourceOverride + ? { + sourceTypeOverride: "GITHUB", + sourceLocationOverride: `https://github.com/${owner}/${repo}.git`, + } + : {}; const environmentVariablesOverride = Object.entries(process.env) .filter( @@ -167,8 +175,7 @@ function inputs2Parameters(inputs) { return { projectName, sourceVersion, - sourceTypeOverride, - sourceLocationOverride, + ...sourceOverride, buildspecOverride, environmentVariablesOverride, }; diff --git a/dist/index.js b/dist/index.js index 1e90747..d4dffce 100644 --- a/dist/index.js +++ b/dist/index.js @@ -66968,6 +66968,51 @@ module.exports = /******/ (function (modules, runtime) { /***/ }, + /***/ 2102: /***/ function (__unusedmodule, exports, __webpack_require__) { + "use strict"; + + // For internal use, subject to change. + var __importStar = + (this && this.__importStar) || + function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) + for (var k in mod) + if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; + }; + Object.defineProperty(exports, "__esModule", { value: true }); + // We use any as a valid input type + /* eslint-disable @typescript-eslint/no-explicit-any */ + const fs = __importStar(__webpack_require__(5747)); + const os = __importStar(__webpack_require__(2087)); + const utils_1 = __webpack_require__(5082); + function issueCommand(command, message) { + const filePath = process.env[`GITHUB_${command}`]; + if (!filePath) { + throw new Error( + `Unable to find environment variable for file command ${command}` + ); + } + if (!fs.existsSync(filePath)) { + throw new Error(`Missing file at path: ${filePath}`); + } + fs.appendFileSync( + filePath, + `${utils_1.toCommandValue(message)}${os.EOL}`, + { + encoding: "utf8", + } + ); + } + exports.issueCommand = issueCommand; + //# sourceMappingURL=file-command.js.map + + /***/ + }, + /***/ 2106: /***/ function (module, __unusedexports, __webpack_require__) { __webpack_require__(3234); var AWS = __webpack_require__(395); @@ -118516,6 +118561,7 @@ module.exports = /******/ (function (modules, runtime) { }; Object.defineProperty(exports, "__esModule", { value: true }); const os = __importStar(__webpack_require__(2087)); + const utils_1 = __webpack_require__(5082); /** * Commands * @@ -118569,13 +118615,15 @@ module.exports = /******/ (function (modules, runtime) { } } function escapeData(s) { - return (s || "") + return utils_1 + .toCommandValue(s) .replace(/%/g, "%25") .replace(/\r/g, "%0D") .replace(/\n/g, "%0A"); } function escapeProperty(s) { - return (s || "") + return utils_1 + .toCommandValue(s) .replace(/%/g, "%25") .replace(/\r/g, "%0D") .replace(/\n/g, "%0A") @@ -123249,6 +123297,14 @@ module.exports = /******/ (function (modules, runtime) { res = / { .and.to.deep.equal(["one", "two", "three", "four"]); }); + it("skips override when parameter is set to true", () => { + // 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[`INPUT_DISABLE-SOURCE-OVERRIDE`] = "true"; + process.env[`GITHUB_REPOSITORY`] = repoInfo; + process.env[`GITHUB_SHA`] = sha; + + const test = githubInputs(); + + expect(test) + .to.haveOwnProperty("disableSourceOverride") + .and.to.deep.equal(true); + }); + it("can handle pull requests", () => { // This is how GITHUB injects its input values. // It would be nice if there was an easy way to test this... @@ -245,6 +260,17 @@ describe("inputs2Parameters", () => { expect(fourEnv).to.haveOwnProperty("value").and.to.equal("_four_"); expect(fourEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT"); }); + + it("skips source override when disableSourceOverride is set to true", () => { + const test = inputs2Parameters({ + projectName, + sourceVersion: sha, + owner: "owner", + repo: "repo", + disableSourceOverride: true, + }); + expect(test).to.not.haveOwnProperty("sourceTypeOverride"); + }); }); describe("waitForBuildEndTime", () => {