Skip to content

test pr output trivy-scan.yml #10

test pr output trivy-scan.yml

test pr output trivy-scan.yml #10

Workflow file for this run

name: Trivy Scan
on:
push:
branches:
- main
- 'release-1*'
- develop
- '1.2.*'
- master
- patch-1
pull_request:
branches:
- main
- 'release-1*'
- develop
- '1.2.*'
- master
- MOSIP-35889
jobs:
trivy-scan:
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.dev_namespace_docker_hub }}
SERVICE_NAME: partner-onboarder
VERSION: latest # Modify this as needed or set dynamically based on your versioning scheme
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build Docker image
run: |
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
if: failure() && steps.scan.outcome == 'failure'
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
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 $GITHUB_TOKEN" \
${{ github.event.pull_request.comments_url }} \
-d @result.json
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: 'trivy-results.sarif'