Write a warning if there is an error with the workflow
This commit is contained in:
parent
7eb9dfcc60
commit
33bb87523e
9 changed files with 92 additions and 61 deletions
27
lib/actions-util.js
generated
27
lib/actions-util.js
generated
|
|
@ -7,10 +7,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const toolrunner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const safeWhich = __importStar(require("@chrisgavin/safe-which"));
|
||||
const yaml = __importStar(require("js-yaml"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
const util_1 = require("./util");
|
||||
|
|
@ -105,6 +107,12 @@ var MissingTriggers;
|
|||
MissingTriggers[MissingTriggers["PUSH"] = 1] = "PUSH";
|
||||
MissingTriggers[MissingTriggers["PULL_REQUEST"] = 2] = "PULL_REQUEST";
|
||||
})(MissingTriggers || (MissingTriggers = {}));
|
||||
exports.ErrCheckoutWrongHead = `Git checkout HEAD^2 is no longer necessary. Please remove this line.`;
|
||||
exports.ErrMismatchedBranches = `Please make sure that any branches in on.pull_request are also in on.push so that CodeQL can establish a baseline.`;
|
||||
exports.ErrMissingHooks = `Please specify on.push and on.pull_request hooks.`;
|
||||
exports.ErrMissingPushHook = `Please specify an on.push hook so CodeQL can establish a baseline.`;
|
||||
exports.ErrMissingPullRequestHook = `Please specify an on.pull_request hook so CodeQL is run against new pull requests.`;
|
||||
exports.ErrPathsSpecified = `Please do not specify paths at on.pull.`;
|
||||
function validateWorkflow(doc) {
|
||||
var _a, _b, _c, _d;
|
||||
const errors = [];
|
||||
|
|
@ -112,7 +120,7 @@ function validateWorkflow(doc) {
|
|||
for (const job of Object.values(((_a = doc) === null || _a === void 0 ? void 0 : _a.jobs) || {})) {
|
||||
for (const step of ((_b = job) === null || _b === void 0 ? void 0 : _b.steps) || []) {
|
||||
if (((_c = step) === null || _c === void 0 ? void 0 : _c.run) === "git checkout HEAD^2") {
|
||||
errors.push(`Git checkout HEAD^2 is no longer necessary. Please remove this line from your workflow.`);
|
||||
errors.push(exports.ErrCheckoutWrongHead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -151,7 +159,7 @@ function validateWorkflow(doc) {
|
|||
else {
|
||||
const paths = (_d = doc.on.push) === null || _d === void 0 ? void 0 : _d.paths;
|
||||
if (Array.isArray(paths) && paths.length > 0) {
|
||||
errors.push("Please do not specify paths at on.pull.");
|
||||
errors.push(exports.ErrPathsSpecified);
|
||||
}
|
||||
}
|
||||
if (doc.on.pull_request !== undefined && doc.on.push !== undefined) {
|
||||
|
|
@ -159,28 +167,35 @@ function validateWorkflow(doc) {
|
|||
const pull_request = doc.on.pull_request.branches || [];
|
||||
const intersects = pull_request.filter((value) => !push.includes(value));
|
||||
if (intersects.length > 0) {
|
||||
errors.push("Please make sure that any branches in on.pull_request: are also in on.push: so that CodeQL can establish a baseline.");
|
||||
errors.push(exports.ErrMismatchedBranches);
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (missing) {
|
||||
case MissingTriggers.PULL_REQUEST | MissingTriggers.PUSH:
|
||||
errors.push("Please specify on.push and on.pull_request hooks.");
|
||||
errors.push(exports.ErrMissingHooks);
|
||||
break;
|
||||
case MissingTriggers.PULL_REQUEST:
|
||||
errors.push("Please specify an on.pull_request hook so CodeQL is run against new pull requests.");
|
||||
errors.push(exports.ErrMissingPullRequestHook);
|
||||
break;
|
||||
case MissingTriggers.PUSH:
|
||||
errors.push("Please specify an on.push hook so CodeQL can establish a baseline.");
|
||||
errors.push(exports.ErrMissingPushHook);
|
||||
break;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
exports.validateWorkflow = validateWorkflow;
|
||||
async function getWorkflow() {
|
||||
return yaml.safeLoad(fs.readFileSync(await getWorkflowPath(), "utf-8"));
|
||||
}
|
||||
exports.getWorkflow = getWorkflow;
|
||||
/**
|
||||
* Get the path of the currently executing workflow.
|
||||
*/
|
||||
async function getWorkflowPath() {
|
||||
if (util_1.isLocalRun()) {
|
||||
return getRequiredEnvParam("WORKFLOW_PATH");
|
||||
}
|
||||
const repo_nwo = getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
|
||||
const owner = repo_nwo[0];
|
||||
const repo = repo_nwo[1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue