Skip to content

Commit 7cef3cf

Browse files
committed
Add an integration test for uploading SARIF when the run fails
1 parent f890f6d commit 7cef3cf

5 files changed

Lines changed: 58 additions & 23 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Submit SARIF after failure
2+
on: push
3+
4+
env:
5+
# Internal-only environment variable used to indicate that the post-init Action
6+
# should expect to upload a SARIF file for the failed run.
7+
CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF: true
8+
# Make sure the uploading SARIF files feature is enabled.
9+
CODEQL_ACTION_UPLOAD_FAILED_SARIF: true
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
language: [javascript]
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: ./init
20+
with:
21+
languages: ${{ matrix.language }}
22+
- name: Fail
23+
# We want this job to pass if the Action correctly uploads the SARIF file for
24+
# the failed run.
25+
# Setting this step to continue on error means that it is marked as completing
26+
# successfully, so will not fail the job.
27+
continue-on-error: true
28+
run: exit 1
29+
- uses: ./analyze
30+
# In a real workflow, this step wouldn't run. Since we used `continue-on-error`
31+
# above, we manually disable it with an `if` condition.
32+
if: false
33+
with:
34+
category: "/language:${{ matrix.language }}"

.github/workflows/test-report-failed-run.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/init-action-post-helper.js

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

lib/init-action-post-helper.js.map

Lines changed: 1 addition & 1 deletion
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,28 @@ export async function run(
8787
return;
8888
}
8989

90+
// Environment variable used to integration test uploading a SARIF file for failed runs
91+
const expectFailedSarifUpload =
92+
process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true";
93+
9094
if (process.env[CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF] !== "true") {
9195
try {
9296
await uploadFailedSarif(config, repositoryNwo, featureEnablement, logger);
9397
} catch (e) {
98+
if (expectFailedSarifUpload) {
99+
throw new Error(
100+
"Expected to upload a SARIF file for the failed run, but encountered " +
101+
`the following error: ${e}`
102+
);
103+
}
94104
logger.warning(
95105
`Failed to upload a SARIF file for the failed run. Error: ${e}`
96106
);
97107
}
108+
} else if (expectFailedSarifUpload) {
109+
throw new Error(
110+
"Expected to upload a SARIF file for the failed run, but didn't."
111+
);
98112
}
99113

100114
// Upload appropriate Actions artifacts for debugging

0 commit comments

Comments
 (0)