Skip to content

Commit

Permalink
Update trivy-scan.yml
Browse files Browse the repository at this point in the history
Signed-off-by: rajapandi1234 <[email protected]>
  • Loading branch information
rajapandi1234 authored Sep 25, 2024
1 parent 2ffa0e6 commit 5de1fbc
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- develop
- '1.2.*'
- master
- patch-1
- MOSIP-35889
pull_request:
branches:
- main
Expand All @@ -35,40 +35,14 @@ jobs:
cd "${{ env.SERVICE_LOCATION }}"
docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }}:${{ env.VERSION }}
- name: Obtain template file
shell: bash
run: curl -o trivy-pr-comment.tpl https://raw.githubusercontent.com/domstolene/trivy-pr-report/main/trivy-pr-comment.tpl

- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
id: scan
with:
scan-type: 'fs'
image-ref: 'docker.io/${{ env.SERVICE_NAME }}:${{ env.VERSION }}'
format: 'template'
template: '@trivy-pr-comment.tpl'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
output: 'trivy.json'
exit-code: 1
scanners: 'vuln'

- name: Report vulnerabilities in PR
env:
GITHUB_TOKEN: ${{ secrets.T }}
shell: bash
run: |
echo -n "{\"body\":\"### Vulnerabilities detected\nThe following vulnerabilities of HIGH or CRITICAL severity has been detected in the code. Please resolve these before merging the pull request.\n\n" > result.json
cat trivy.json | sort | uniq | tr -d '\n' >> result.json
echo "\"}" >> result.json
curl -X POST -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${{ secrets.T }}" \
${{ github.event.pull_request.comments_url }} \
-d @result.json
format: 'sarif'
output: 'trivy-results.sarif'

# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'

0 comments on commit 5de1fbc

Please sign in to comment.