Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make SARIF file more compact to allow for more findings to be uploaded to GitHub 🐘 #467

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ generate_SARIF () {
--set-scan-prop='tool:ShellCheck' \
--set-scan-prop="tool-version:${shellcheck_version}" \
--set-scan-prop='tool-url:https://www.shellcheck.net/wiki/' \
"${defects}" > "${output}"
"${defects}" > full.sarif

# Make the SARIF report compact to allow for more efficient uploading to GitHub
# It also allows to upload more defects in a single request (GitHub limit is 10MB)
jq --compact-output < full.sarif > "${output}"
}

# Function to upload the SARIF report to GitHub
Expand Down
232 changes: 1 addition & 231 deletions test/fixtures/generate_SARIF/test.sarif
Original file line number Diff line number Diff line change
@@ -1,231 +1 @@
{
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"version": "2.1.0",
"inlineExternalProperties": [
{
"externalizedProperties": {
"tool": "ShellCheck",
"tool-url": "https://www.shellcheck.net/wiki/",
"tool-version": "0.10.0"
}
}
],
"runs": [
{
"tool": {
"driver": {
"name": "ShellCheck",
"version": "0.10.0",
"informationUri": "https://www.shellcheck.net/wiki/",
"rules": [
{
"id": "SHELLCHECK_WARNING: warning[SC2034]",
"properties": {
"tags": [
"ShellCheck"
]
},
"name": "SC2034",
"shortDescription": {
"text": "SC2034"
},
"help": {
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2034",
"markdown": "Defect reference: [SC2034](https://github.com/koalaman/shellcheck/wiki/SC2034)"
},
"fullDescription": {
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2034"
}
},
{
"id": "SHELLCHECK_WARNING: warning[SC2115]",
"properties": {
"tags": [
"ShellCheck"
]
},
"name": "SC2115",
"shortDescription": {
"text": "SC2115"
},
"help": {
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2115",
"markdown": "Defect reference: [SC2115](https://github.com/koalaman/shellcheck/wiki/SC2115)"
},
"fullDescription": {
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2115"
}
}
]
}
},
"results": [
{
"ruleId": "SHELLCHECK_WARNING: warning[SC2034]",
"level": "warning",
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 7,
"endLine": 7
}
}
}
],
"message": {
"text": "UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 7,
"endLine": 7
}
},
"message": {
"text": "UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
}
},
"nestingLevel": 0,
"kinds": [
"warning[SC2034]"
]
}
]
}
]
}
],
"fingerprints": {
"csdiff/v0": "64c37c2cd555f4d61c6e05ebd224beb8147d77bf"
}
},
{
"ruleId": "SHELLCHECK_WARNING: warning[SC2115]",
"level": "warning",
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
}
}
],
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
},
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
}
},
"nestingLevel": 0,
"kinds": [
"warning[SC2115]"
]
}
]
}
]
}
],
"fingerprints": {
"csdiff/v0": "d9a3f3f1027ba2a0ca5dc7eb24d7d8b09dbe2b1d"
}
},
{
"ruleId": "SHELLCHECK_WARNING: warning[SC2115]",
"level": "warning",
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
}
}
],
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
},
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
}
},
"nestingLevel": 0,
"kinds": [
"warning[SC2115]"
]
}
]
}
]
}
],
"fingerprints": {
"csdiff/v0": "d9a3f3f1027ba2a0ca5dc7eb24d7d8b09dbe2b1d"
}
}
]
}
]
}
{"$schema":"https://json.schemastore.org/sarif-2.1.0.json","version":"2.1.0","inlineExternalProperties":[{"externalizedProperties":{"tool":"ShellCheck","tool-url":"https://www.shellcheck.net/wiki/","tool-version":"0.10.0"}}],"runs":[{"tool":{"driver":{"name":"ShellCheck","version":"0.10.0","informationUri":"https://www.shellcheck.net/wiki/","rules":[{"id":"SHELLCHECK_WARNING: warning[SC2034]","properties":{"tags":["ShellCheck"]},"name":"SC2034","shortDescription":{"text":"SC2034"},"help":{"text":"Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2034","markdown":"Defect reference: [SC2034](https://github.com/koalaman/shellcheck/wiki/SC2034)"},"fullDescription":{"text":"Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2034"}},{"id":"SHELLCHECK_WARNING: warning[SC2115]","properties":{"tags":["ShellCheck"]},"name":"SC2115","shortDescription":{"text":"SC2115"},"help":{"text":"Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2115","markdown":"Defect reference: [SC2115](https://github.com/koalaman/shellcheck/wiki/SC2115)"},"fullDescription":{"text":"Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2115"}}]}},"results":[{"ruleId":"SHELLCHECK_WARNING: warning[SC2034]","level":"warning","locations":[{"id":0,"physicalLocation":{"artifactLocation":{"uri":"innocent-script.sh"},"region":{"startLine":7,"endLine":7}}}],"message":{"text":"UNUSED_VAR2 appears unused. Verify use (or export if used externally)."},"codeFlows":[{"threadFlows":[{"locations":[{"location":{"id":0,"physicalLocation":{"artifactLocation":{"uri":"innocent-script.sh"},"region":{"startLine":7,"endLine":7}},"message":{"text":"UNUSED_VAR2 appears unused. Verify use (or export if used externally)."}},"nestingLevel":0,"kinds":["warning[SC2034]"]}]}]}],"fingerprints":{"csdiff/v0":"64c37c2cd555f4d61c6e05ebd224beb8147d77bf"}},{"ruleId":"SHELLCHECK_WARNING: warning[SC2115]","level":"warning","locations":[{"id":0,"physicalLocation":{"artifactLocation":{"uri":"innocent-script.sh"},"region":{"startLine":11,"endLine":11}}}],"message":{"text":"Use \"${var:?}\" to ensure this never expands to / ."},"codeFlows":[{"threadFlows":[{"locations":[{"location":{"id":0,"physicalLocation":{"artifactLocation":{"uri":"innocent-script.sh"},"region":{"startLine":11,"endLine":11}},"message":{"text":"Use \"${var:?}\" to ensure this never expands to / ."}},"nestingLevel":0,"kinds":["warning[SC2115]"]}]}]}],"fingerprints":{"csdiff/v0":"d9a3f3f1027ba2a0ca5dc7eb24d7d8b09dbe2b1d"}},{"ruleId":"SHELLCHECK_WARNING: warning[SC2115]","level":"warning","locations":[{"id":0,"physicalLocation":{"artifactLocation":{"uri":"innocent-script.sh"},"region":{"startLine":11,"endLine":11}}}],"message":{"text":"Use \"${var:?}\" to ensure this never expands to / ."},"codeFlows":[{"threadFlows":[{"locations":[{"location":{"id":0,"physicalLocation":{"artifactLocation":{"uri":"innocent-script.sh"},"region":{"startLine":11,"endLine":11}},"message":{"text":"Use \"${var:?}\" to ensure this never expands to / ."}},"nestingLevel":0,"kinds":["warning[SC2115]"]}]}]}],"fingerprints":{"csdiff/v0":"d9a3f3f1027ba2a0ca5dc7eb24d7d8b09dbe2b1d"}}]}]}
2 changes: 1 addition & 1 deletion test/generate_SARIF.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ setup () {
}

teardown () {
rm -f test.sarif
rm -f test.sarif full.sarif
}
10 changes: 9 additions & 1 deletion test/index.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ setup () {
}

teardown () {
rm -f ../base-shellcheck.err ../changed-files.txt ../defects.log ../fixes.log ../head-shellcheck.err ./output.sarif ./output.xhtml
rm -f \
../base-shellcheck.err \
../changed-files.txt \
../defects.log \
../fixes.log \
../head-shellcheck.err \
./full.sarif \
./output.sarif \
./output.xhtml

export \
SCRIPT_DIR="" \
Expand Down
2 changes: 1 addition & 1 deletion test/print_result.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ teardown () {
export \
INPUT_DISPLAY_ENGINE="" \
UNIT_TESTS=""
rm -f tmp.sarif
rm -f tmp.sarif full.sarif
}
Loading