mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
split the sarif file into languages
This commit is contained in:
10
.github/workflows/ql-for-ql-build.yml
vendored
10
.github/workflows/ql-for-ql-build.yml
vendored
@@ -176,3 +176,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: ql-for-ql.sarif
|
name: ql-for-ql.sarif
|
||||||
path: ql-for-ql.sarif
|
path: ql-for-ql.sarif
|
||||||
|
- name: Split out the sarif file into langs
|
||||||
|
run: |
|
||||||
|
mkdir split-sarif
|
||||||
|
node ./ql/scripts/split-sarif.js ql-for-ql.sarif split-sarif
|
||||||
|
- name: Upload langs as artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ql-for-ql-langs
|
||||||
|
path: split-sarif
|
||||||
|
retention-days: 1
|
||||||
30
ql/scripts/split-sarif.js
Normal file
30
ql/scripts/split-sarif.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
|
// the .sarif file to split, and then the directory to put the split files in.
|
||||||
|
async function main(inputs) {
|
||||||
|
const sarifFile = JSON.parse(fs.readFileSync(inputs[0]));
|
||||||
|
const outFolder = inputs[1];
|
||||||
|
|
||||||
|
const out = {};
|
||||||
|
|
||||||
|
for (const result of sarifFile.runs[0].results) {
|
||||||
|
const lang = getLanguage(result);
|
||||||
|
if (!out[lang]) {
|
||||||
|
out[lang] = [];
|
||||||
|
}
|
||||||
|
out[lang].push(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const lang in out) {
|
||||||
|
const outSarif = JSON.parse(JSON.stringify(sarifFile));
|
||||||
|
outSarif.runs[0].results = out[lang];
|
||||||
|
fs.writeFileSync(`${outFolder}/${lang}.sarif`, JSON.stringify(outSarif, null, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLanguage(result) {
|
||||||
|
return result.locations[0].physicalLocation.artifactLocation.uri.split(
|
||||||
|
"/"
|
||||||
|
)[0];
|
||||||
|
}
|
||||||
|
main(process.argv.splice(2));
|
||||||
Reference in New Issue
Block a user