Skip to content

Commit 6e2f3e2

Browse files
committed
merge all .sarif files at the end of the QL-for-QL workflow
1 parent 638a886 commit 6e2f3e2

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

.github/workflows/ql-for-ql-build.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ jobs:
5050
path: ${{ runner.temp }}/query-pack.zip
5151

5252
extractors:
53-
strategy:
54-
fail-fast: false
55-
5653
runs-on: ubuntu-latest
5754

5855
steps:
@@ -201,3 +198,27 @@ jobs:
201198
name: ${{ matrix.folder }}.sarif
202199
path: ${{ matrix.folder }}.sarif
203200

201+
combine:
202+
runs-on: ubuntu-latest
203+
needs:
204+
- analyze
205+
206+
steps:
207+
- uses: actions/checkout@v3
208+
- name: Make a folder for artifacts.
209+
run: mkdir -p results
210+
- name: Download all sarif files
211+
uses: actions/download-artifact@v3
212+
with:
213+
path: results
214+
- uses: actions/setup-node@v3
215+
with:
216+
node-version: 16
217+
- name: Combine all sarif files
218+
run: |
219+
node ./ql/scripts/merge-sarif.js results/**/*.sarif combined.sarif
220+
- name: Upload combined sarif file
221+
uses: actions/upload-artifact@v3
222+
with:
223+
name: combined.sarif
224+
path: combined.sarif

ql/scripts/merge-sarif.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var fs = require("fs");
2+
3+
// first a list of files to merge, and the last argument is the output file.
4+
async function main(files) {
5+
const inputs = files
6+
.slice(0, -1)
7+
.map((file) => fs.readFileSync(file))
8+
.map((data) => JSON.parse(data));
9+
const out = inputs[0]; // just arbitrarily take the first one
10+
const outFile = files[files.length - 1];
11+
12+
const combinedResults = [];
13+
14+
for (const sarif of inputs) {
15+
combinedResults.push(...sarif.runs[0].results);
16+
}
17+
18+
out.runs[0].artifacts = []; // the indexes in these won't make sense, so I hope this works.
19+
out.runs[0].results = combinedResults;
20+
21+
// workaround until https://github.com/microsoft/sarif-vscode-extension/pull/436/ is part of a release
22+
out["$schema"] = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0";
23+
24+
fs.writeFileSync(outFile, JSON.stringify(out, null, 2));
25+
}
26+
main(process.argv.splice(2));

0 commit comments

Comments
 (0)