Provide a better error message
This commit is contained in:
parent
366b68eda0
commit
c989ee7b39
3 changed files with 29 additions and 7 deletions
15
lib/actions-util.js
generated
15
lib/actions-util.js
generated
|
|
@ -540,6 +540,16 @@ function getRelativeScriptPath() {
|
||||||
return path.relative(actionsDirectory, __filename);
|
return path.relative(actionsDirectory, __filename);
|
||||||
}
|
}
|
||||||
exports.getRelativeScriptPath = getRelativeScriptPath;
|
exports.getRelativeScriptPath = getRelativeScriptPath;
|
||||||
|
// Reads the contents of GITHUB_EVENT_PATH as a JSON object
|
||||||
|
function getWorkflowEvent() {
|
||||||
|
const eventJsonFile = util_1.getRequiredEnvParam("GITHUB_EVENT_PATH");
|
||||||
|
try {
|
||||||
|
return JSON.parse(fs.readFileSync(eventJsonFile, "utf-8"));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw new Error(`Unable to read workflow event JSON from ${eventJsonFile}: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Is the version of the repository we are currently analyzing from the default branch,
|
// Is the version of the repository we are currently analyzing from the default branch,
|
||||||
// or alternatively from another branch or a pull request.
|
// or alternatively from another branch or a pull request.
|
||||||
async function isAnalyzingDefaultBranch() {
|
async function isAnalyzingDefaultBranch() {
|
||||||
|
|
@ -549,8 +559,9 @@ async function isAnalyzingDefaultBranch() {
|
||||||
currentRef = currentRef.startsWith("refs/heads/")
|
currentRef = currentRef.startsWith("refs/heads/")
|
||||||
? currentRef.substr("refs/heads/".length)
|
? currentRef.substr("refs/heads/".length)
|
||||||
: currentRef;
|
: currentRef;
|
||||||
const eventJson = JSON.parse(fs.readFileSync(util_1.getRequiredEnvParam("GITHUB_EVENT_PATH"), "utf-8"));
|
const event = getWorkflowEvent();
|
||||||
return currentRef === ((_b = (_a = eventJson) === null || _a === void 0 ? void 0 : _a.repository) === null || _b === void 0 ? void 0 : _b.default_branch);
|
const defaultBranch = (_b = (_a = event) === null || _a === void 0 ? void 0 : _a.repository) === null || _b === void 0 ? void 0 : _b.default_branch;
|
||||||
|
return currentRef === defaultBranch;
|
||||||
}
|
}
|
||||||
exports.isAnalyzingDefaultBranch = isAnalyzingDefaultBranch;
|
exports.isAnalyzingDefaultBranch = isAnalyzingDefaultBranch;
|
||||||
//# sourceMappingURL=actions-util.js.map
|
//# sourceMappingURL=actions-util.js.map
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -692,6 +692,18 @@ export function getRelativeScriptPath(): string {
|
||||||
return path.relative(actionsDirectory, __filename);
|
return path.relative(actionsDirectory, __filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reads the contents of GITHUB_EVENT_PATH as a JSON object
|
||||||
|
function getWorkflowEvent(): any {
|
||||||
|
const eventJsonFile = getRequiredEnvParam("GITHUB_EVENT_PATH");
|
||||||
|
try {
|
||||||
|
return JSON.parse(fs.readFileSync(eventJsonFile, "utf-8"));
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`Unable to read workflow event JSON from ${eventJsonFile}: ${e}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Is the version of the repository we are currently analyzing from the default branch,
|
// Is the version of the repository we are currently analyzing from the default branch,
|
||||||
// or alternatively from another branch or a pull request.
|
// or alternatively from another branch or a pull request.
|
||||||
export async function isAnalyzingDefaultBranch(): Promise<boolean> {
|
export async function isAnalyzingDefaultBranch(): Promise<boolean> {
|
||||||
|
|
@ -701,9 +713,8 @@ export async function isAnalyzingDefaultBranch(): Promise<boolean> {
|
||||||
? currentRef.substr("refs/heads/".length)
|
? currentRef.substr("refs/heads/".length)
|
||||||
: currentRef;
|
: currentRef;
|
||||||
|
|
||||||
const eventJson = JSON.parse(
|
const event = getWorkflowEvent();
|
||||||
fs.readFileSync(getRequiredEnvParam("GITHUB_EVENT_PATH"), "utf-8")
|
const defaultBranch = event?.repository?.default_branch;
|
||||||
);
|
|
||||||
|
|
||||||
return currentRef === eventJson?.repository?.default_branch;
|
return currentRef === defaultBranch;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue