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

Stop action when no scans are enabled #38

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 14 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const STATUS_FAILED = 'FAILED';
const STATUS_SUCCEEDED = 'SUCCEEDED';
const STATUS_TIMED_OUT = 'TIMED_OUT';
async function run() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
try {
const secretKey = core.getInput('secret-key');
const fromSeverity = core.getInput('minimum-severity');
Expand Down Expand Up @@ -156,8 +156,19 @@ async function run() {
core.info(`starting a scan with secret key: "${redactedToken}"`);
}
else {
const isLikelyDependabotPr = ((_z = startScanPayload.branch_name) !== null && _z !== void 0 ? _z : '').starts_with('dependabot/');
if (isLikelyDependabotPr) {
core.info(`it looks like the action is running on a dependabot PR, this means that secret variables are not available in this context and thus we can not start a scan. Please see: https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/`);
core.setOutput('outcome', STATUS_SUCCEEDED);
return;
}
core.info(`secret key not set.`);
}
if (failOnDependencyScan === 'true' && failOnIacScan === 'true' && failOnSastScan === 'true') {
core.setOutput('output', STATUS_FAILED);
core.setFailed(`You must enable at least one of the scans.`);
return;
}
const scanId = await (0, api_1.startScan)(secretKey, startScanPayload);
core.info(`successfully started a scan with id: "${scanId}"`);
const getScanCompletionStatus = (0, api_1.getScanStatus)(secretKey, scanId);
Expand Down Expand Up @@ -187,9 +198,9 @@ async function run() {
if (result.diff_url) {
moreDetailsText = ` More details at ${result.diff_url}`;
}
if (postScanStatusAsComment === 'true' && !!((_z = result.outcome) === null || _z === void 0 ? void 0 : _z.human_readable_message)) {
if (postScanStatusAsComment === 'true' && !!((_0 = result.outcome) === null || _0 === void 0 ? void 0 : _0.human_readable_message)) {
try {
await (0, postMessage_1.postScanStatusMessage)((_0 = result.outcome) === null || _0 === void 0 ? void 0 : _0.human_readable_message);
await (0, postMessage_1.postScanStatusMessage)((_1 = result.outcome) === null || _1 === void 0 ? void 0 : _1.human_readable_message);
}
catch (error) {
if (error instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ async function run(): Promise<void> {
core.info(`secret key not set.`);
}

if (failOnDependencyScan === 'true' && failOnIacScan === 'true' && failOnSastScan === 'true') {
Kemosabert marked this conversation as resolved.
Show resolved Hide resolved
core.setOutput('output', STATUS_FAILED);
core.setFailed(`You must enable at least one of the scans.`);
return;
}

const scanId = await startScan(secretKey, startScanPayload);

core.info(`successfully started a scan with id: "${scanId}"`);
Expand Down
Loading