Skip to content

Commit f9aa7f0

Browse files
committed
fix grype commit status when error occurs
1 parent 61e4cb1 commit f9aa7f0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

.github/workflows/grype_scan.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,18 @@ jobs:
132132
with:
133133
github-token: ${{ secrets.GITHUB_TOKEN }}
134134
script: |
135+
const totalHighCritical = '${{ steps.create_summary.outputs.total_high_critical }}';
136+
const hasError = totalHighCritical === '';
137+
const hasVulnerabilities = parseInt(totalHighCritical) > 0;
135138
github.rest.repos.createCommitStatus({
136139
owner: context.repo.owner,
137140
repo: context.repo.repo,
138141
sha: '${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}',
139-
state: '${{ steps.create_summary.outputs.total_high_critical > 0 && 'failure' || 'success' }}',
142+
state: hasError ? 'error' : hasVulnerabilities ? 'failure' : 'success',
140143
target_url: '${{ steps.upload_results.outputs.https_s3_path }}/results.html',
141-
description: 'Grype Scan Completed with ${{ steps.create_summary.outputs.total_high_critical }} high/critical vulnerabilities',
144+
description: hasError ? 'An error occurred' : `Grype Scan Completed with ${totalHighCritical} high/critical vulnerabilities`,
142145
context: 'Grype Scan ${{ steps.set_version.outputs.docker_image || inputs.docker_image }}'
143-
})
146+
});
144147
145148
- name: Upload artifacts
146149
if: always()

0 commit comments

Comments
 (0)