Skip to content

Commit 804b5b8

Browse files
committed
ci: fix GitHub SARIF upload error by providing valid run object in empty results
1 parent f7f51f2 commit 804b5b8

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

.github/workflows/snyk-security.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,28 @@ jobs:
3939
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
4040
steps:
4141
- uses: actions/checkout@v4
42+
- name: Set up Snyk CLI
43+
uses: snyk/actions/setup@master
44+
4245
- name: Snyk Code test
43-
uses: snyk/actions/node@master
44-
continue-on-error: true
45-
with:
46-
command: code test
47-
args: --sarif-file-output=snyk-code.sarif
46+
run: |
47+
snyk code test --sarif-file-output=snyk-code.sarif || true
4848
env:
4949
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
5050

51-
- name: Verify SARIF file
51+
- name: Verify and Patch SARIF file
5252
run: |
53-
if [ -f snyk-code.sarif ]; then
54-
echo "SARIF file found."
55-
ls -l snyk-code.sarif
53+
if [ -s snyk-code.sarif ]; then
54+
echo "SARIF file found and not empty."
55+
# If the file exists but has an empty runs array, GitHub will reject it.
56+
# We check for the specific pattern of an empty runs array.
57+
if grep -q '"runs":\[\]' snyk-code.sarif || grep -q '"runs": \[\]' snyk-code.sarif; then
58+
echo "Patching empty runs array for GitHub compatibility..."
59+
sed -i 's/"runs":\s*\[\]/"runs":\[{"tool":{"driver":{"name":"SnykCode"}},"results":[]}\]/g' snyk-code.sarif
60+
fi
5661
else
57-
echo "SARIF file NOT found. Creating empty valid SARIF to prevent crash."
58-
echo '{"$schema":"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json","version":"2.1.0","runs":[]}' > snyk-code.sarif
62+
echo "SARIF file NOT found or empty. Creating valid placeholder SARIF."
63+
echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"SnykCode"}},"results":[]}]}' > snyk-code.sarif
5964
fi
6065
6166
# Runs Snyk Open Source (SCA) analysis and uploads result to Snyk.

0 commit comments

Comments
 (0)