Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Disabling Source Type Override Parameters #64

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if you want to" - typo

required: false
outputs:
aws-build-id:
description: 'The AWS CodeBuild Build ID for this build.'
Expand Down
15 changes: 11 additions & 4 deletions code-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ async function waitForBuildEndTime(sdk, { id, logs }, nextToken) {

function githubInputs() {
const projectName = core.getInput("project-name", { required: true });
const disableSourceOverride =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - For consistency, could you either update this new line to use core.getInput("disable-source-override", {required: false}) === "true", or remove all other { required: false }s from githubInputs()?

core.getInput("disable-source-override") === "true";
const { owner, repo } = github.context.repo;
const { payload } = github.context;
// The github.context.sha is evaluated on import.
Expand Down Expand Up @@ -140,6 +142,7 @@ function githubInputs() {
sourceVersion,
buildspecOverride,
envPassthrough,
disableSourceOverride,
};
}

Expand All @@ -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(
Expand All @@ -167,8 +175,7 @@ function inputs2Parameters(inputs) {
return {
projectName,
sourceVersion,
sourceTypeOverride,
sourceLocationOverride,
...sourceOverride,
buildspecOverride,
environmentVariablesOverride,
};
Expand Down
160 changes: 138 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -123249,6 +123297,14 @@ module.exports = /******/ (function (modules, runtime) {
res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(
str
);
if (!res) {
res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(
str
);
if (res) {
res.pop(); // drop last quote
}
}

if (res) {
res = /charset=(.*)/i.exec(res.pop());
Expand Down Expand Up @@ -124366,7 +124422,7 @@ module.exports = /******/ (function (modules, runtime) {
case "error":
reject(
new FetchError(
`redirect mode is set to error: ${request.url}`,
`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`,
"no-redirect"
)
);
Expand Down Expand Up @@ -124414,6 +124470,7 @@ module.exports = /******/ (function (modules, runtime) {
body: request.body,
signal: request.signal,
timeout: request.timeout,
size: request.size,
};

// HTTP-redirect fetch step 9
Expand Down Expand Up @@ -147209,6 +147266,30 @@ module.exports = /******/ (function (modules, runtime) {
/***/
},

/***/ 5082: /***/ function (__unusedmodule, exports) {
"use strict";

// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return "";
} else if (typeof input === "string" || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
//# sourceMappingURL=utils.js.map

/***/
},

/***/ 5089: /***/ function (module) {
module.exports = {
version: "2.0",
Expand Down Expand Up @@ -197787,6 +197868,8 @@ module.exports = /******/ (function (modules, runtime) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = __webpack_require__(4431);
const file_command_1 = __webpack_require__(2102);
const utils_1 = __webpack_require__(5082);
const os = __importStar(__webpack_require__(2087));
const path = __importStar(__webpack_require__(5622));
/**
Expand All @@ -197809,11 +197892,20 @@ module.exports = /******/ (function (modules, runtime) {
/**
* Sets env variable for this action and future actions in the job
* @param name the name of the variable to set
* @param val the value of the variable
* @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable(name, val) {
process.env[name] = val;
command_1.issueCommand("set-env", { name }, val);
const convertedVal = utils_1.toCommandValue(val);
process.env[name] = convertedVal;
const filePath = process.env["GITHUB_ENV"] || "";
if (filePath) {
const delimiter = "_GitHubActionsFileCommandDelimeter_";
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
file_command_1.issueCommand("ENV", commandValue);
} else {
command_1.issueCommand("set-env", { name }, convertedVal);
}
}
exports.exportVariable = exportVariable;
/**
Expand All @@ -197829,7 +197921,12 @@ module.exports = /******/ (function (modules, runtime) {
* @param inputPath
*/
function addPath(inputPath) {
command_1.issueCommand("add-path", {}, inputPath);
const filePath = process.env["GITHUB_PATH"] || "";
if (filePath) {
file_command_1.issueCommand("PATH", inputPath);
} else {
command_1.issueCommand("add-path", {}, inputPath);
}
process.env[
"PATH"
] = `${inputPath}${path.delimiter}${process.env["PATH"]}`;
Expand All @@ -197855,12 +197952,22 @@ module.exports = /******/ (function (modules, runtime) {
* Sets the value of an output.
*
* @param name name of the output to set
* @param value value to store
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) {
command_1.issueCommand("set-output", { name }, value);
}
exports.setOutput = setOutput;
/**
* Enables or disables the echoing of commands into stdout for the rest of the step.
* Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
*
*/
function setCommandEcho(enabled) {
command_1.issue("echo", enabled ? "on" : "off");
}
exports.setCommandEcho = setCommandEcho;
//-----------------------------------------------------------------------
// Results
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -197894,18 +198001,24 @@ module.exports = /******/ (function (modules, runtime) {
exports.debug = debug;
/**
* Adds an error issue
* @param message error issue message
* @param message error issue message. Errors will be converted to string via toString()
*/
function error(message) {
command_1.issue("error", message);
command_1.issue(
"error",
message instanceof Error ? message.toString() : message
);
}
exports.error = error;
/**
* Adds an warning issue
* @param message warning issue message
* @param message warning issue message. Errors will be converted to string via toString()
*/
function warning(message) {
command_1.issue("warning", message);
command_1.issue(
"warning",
message instanceof Error ? message.toString() : message
);
}
exports.warning = warning;
/**
Expand Down Expand Up @@ -197962,8 +198075,9 @@ module.exports = /******/ (function (modules, runtime) {
* Saves state for current action, the state can only be retrieved by this action's post job execution.
*
* @param name name of the state to store
* @param value value to store
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function saveState(name, value) {
command_1.issueCommand("save-state", { name }, value);
}
Expand Down Expand Up @@ -221066,11 +221180,6 @@ module.exports = /******/ (function (modules, runtime) {
bundlesize: [
{ path: "./dist/octokit-rest.min.js.gz", maxSize: "33 kB" },
],
_resolved:
"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz",
_integrity:
"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==",
_from: "@octokit/rest@16.43.1",
};

/***/
Expand Down Expand Up @@ -295206,6 +295315,8 @@ module.exports = /******/ (function (modules, runtime) {

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.
Expand Down Expand Up @@ -295236,6 +295347,7 @@ module.exports = /******/ (function (modules, runtime) {
sourceVersion,
buildspecOverride,
envPassthrough,
disableSourceOverride,
};
}

Expand All @@ -295247,10 +295359,15 @@ module.exports = /******/ (function (modules, runtime) {
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(
Expand All @@ -295263,8 +295380,7 @@ module.exports = /******/ (function (modules, runtime) {
return {
projectName,
sourceVersion,
sourceTypeOverride,
sourceLocationOverride,
...sourceOverride,
buildspecOverride,
environmentVariablesOverride,
};
Expand Down
Loading