Skip to content

Commit 5b9d1f4

Browse files
committed
Simplify prepareFailedSarif for risk assessments
1 parent f265dd9 commit 5b9d1f4

File tree

2 files changed

+79
-31
lines changed

2 files changed

+79
-31
lines changed

lib/init-action-post.js

Lines changed: 36 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init-action-post-helper.ts

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,56 @@ async function prepareFailedSarif(
9696
upload_failed_run_skipped_because: "CodeQL command not found",
9797
});
9898
}
99-
const workflow = await getWorkflow(logger);
10099
const jobName = getRequiredEnvParam("GITHUB_JOB");
101100
const matrix = parseMatrixInput(actionsUtil.getRequiredInput("matrix"));
102-
const shouldUpload = getUploadInputOrThrow(workflow, jobName, matrix);
103-
if (
104-
!["always", "failure-only"].includes(
105-
actionsUtil.getUploadValue(shouldUpload),
106-
) ||
107-
shouldSkipSarifUpload()
108-
) {
101+
102+
if (shouldSkipSarifUpload()) {
109103
return new Failure({
110104
upload_failed_run_skipped_because: "SARIF upload is disabled",
111105
});
112106
}
113-
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
114-
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
115107

116-
const result = await generateFailedSarif(
117-
features,
118-
config,
119-
category,
120-
checkoutPath,
121-
);
122-
return new Success(result);
108+
if (isRiskAssessmentEnabled(config)) {
109+
if (config.languages.length !== 1) {
110+
return new Failure({
111+
upload_failed_run_skipped_because:
112+
"Unexpectedly, the configuration is not for a single language.",
113+
});
114+
}
115+
116+
// We can make these assumptions for risk assessments.
117+
const category = `/language:${config.languages[0]}`;
118+
const checkoutPath = ".";
119+
const result = await generateFailedSarif(
120+
features,
121+
config,
122+
category,
123+
checkoutPath,
124+
);
125+
return new Success(result);
126+
} else {
127+
const workflow = await getWorkflow(logger);
128+
const shouldUpload = getUploadInputOrThrow(workflow, jobName, matrix);
129+
if (
130+
!["always", "failure-only"].includes(
131+
actionsUtil.getUploadValue(shouldUpload),
132+
)
133+
) {
134+
return new Failure({
135+
upload_failed_run_skipped_because: "SARIF upload is disabled",
136+
});
137+
}
138+
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
139+
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
140+
141+
const result = await generateFailedSarif(
142+
features,
143+
config,
144+
category,
145+
checkoutPath,
146+
);
147+
return new Success(result);
148+
}
123149
}
124150

125151
async function generateFailedSarif(

0 commit comments

Comments
 (0)