-
Notifications
You must be signed in to change notification settings - Fork 11
/
action.yml
76 lines (66 loc) · 2.64 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: 'SecurityCodeScan'
description: 'Security Code Scan action to upload code scanning results'
branding:
icon: 'check-circle'
color: 'purple'
inputs:
sarif_directory:
description: The output directory where SARIF files should be collected.
required: false
default: '../results'
runs:
using: "composite"
steps:
- name: Convert sarif
shell: bash
run: |
dotnet tool install --global Sarif.Multitool --version 2.3.10
outputDir="${{ inputs.sarif_directory }}"
mkdir $outputDir
cat << EOF > convert.js
const fs = require('fs')
var args = process.argv.slice(2);
var sarif = JSON.parse(fs.readFileSync(args[0], "utf8"));
for (run of sarif.runs) {
run.tool.driver.name = "SecurityCodeScan";
run.tool.driver.fullName = "Vulnerability Patterns Detector for C# and VB.NET";
run.tool.driver.informationUri = "https://security-code-scan.github.io";
run.results = run.results.filter((e => e.ruleId.startsWith("SCS")));
run.tool.driver.rules = run.tool.driver.rules.filter((e => e.id.startsWith("SCS")));
for (let i = 0; i < run.results.length; ++i) {
run.results[i].ruleIndex = undefined;
run.results[i].relatedLocations = undefined;
if (run.results[i].locations === undefined) {
const match = run.results[i].message.text.match(/(.*) in (.*)\((\d+)\)(:.*)/);
run.results[i].message.text = match[1];
run.results[i].locations = [{
"physicalLocation" : {
"artifactLocation" : {
"uri" : "file:///" + match[2].replace(/\\\\/g, "/")
},
"region" : {
"startLine": Number(match[3]),
"startColumn": 1,
"endLine": Number(match[3]),
"endColumn": 1
}
}
}];
}
}
for (rule of run.tool.driver.rules) {
rule.shortDescription = undefined;
rule.help = { "text" : rule.helpUri};
}
run.language = undefined;
}
var converted = JSON.stringify(sarif, null, 2);
fs.writeFileSync(args[1], converted);
EOF
i=0
for sarifFile in $(find ./ -name '*.sarif')
do
sarif transform $sarifFile --output $sarifFile -f --sarif-output-version Current
node convert.js $sarifFile $sarifFile
mv $sarifFile $outputDir/$((i++)).sarif
done