Skip to content

Commit a7a9428

Browse files
committed
split the sarif file into languages
1 parent 47c9b44 commit a7a9428

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,13 @@ jobs:
176176
with:
177177
name: ql-for-ql.sarif
178178
path: ql-for-ql.sarif
179+
- name: Split out the sarif file into langs
180+
run: |
181+
mkdir split-sarif
182+
node ./ql/scripts/split-sarif.js ql-for-ql.sarif split-sarif
183+
- name: Upload langs as artifacts
184+
uses: actions/upload-artifact@v3
185+
with:
186+
name: ql-for-ql-langs
187+
path: split-sarif
188+
retention-days: 1

ql/scripts/split-sarif.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var fs = require("fs");
2+
3+
// the .sarif file to split, and then the directory to put the split files in.
4+
async function main(inputs) {
5+
const sarifFile = JSON.parse(fs.readFileSync(inputs[0]));
6+
const outFolder = inputs[1];
7+
8+
const out = {};
9+
10+
for (const result of sarifFile.runs[0].results) {
11+
const lang = getLanguage(result);
12+
if (!out[lang]) {
13+
out[lang] = [];
14+
}
15+
out[lang].push(result);
16+
}
17+
18+
for (const lang in out) {
19+
const outSarif = JSON.parse(JSON.stringify(sarifFile));
20+
outSarif.runs[0].results = out[lang];
21+
fs.writeFileSync(`${outFolder}/${lang}.sarif`, JSON.stringify(outSarif, null, 2));
22+
}
23+
}
24+
25+
function getLanguage(result) {
26+
return result.locations[0].physicalLocation.artifactLocation.uri.split(
27+
"/"
28+
)[0];
29+
}
30+
main(process.argv.splice(2));

0 commit comments

Comments
 (0)