forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not run snyk pr comment workflow on forks (grafana#11240)
Only run the snyk pr comment workflow on PRs from branches, not on forks. We can't run this `on: pull_request_target` because in needs access to the `SNYK_TOKEN` secret, and when run `on: pull_request`, forks don't have permissions to comment on the PR (because they don't get the `GITHUB_TOKEN` secret.
- Loading branch information
1 parent
7c46bf3
commit 8038e1d
Showing
2 changed files
with
49 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: PR Vulnerability Scan | ||
on: pull_request | ||
|
||
permissions: | ||
pull-requests: write | ||
issues: write | ||
|
||
jobs: | ||
snyk: | ||
name: Snyk Scan | ||
runs-on: ubuntu-latest | ||
if: ${{ !github.event.pull_request.head.repo.fork }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@master | ||
- name: Run Snyk to check for vulnerabilities | ||
uses: snyk/actions/golang@master | ||
continue-on-error: true # To make sure that PR comment is made | ||
env: | ||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | ||
with: | ||
command: test | ||
args: --severity-threshold=high --json-file-output=snyk.json | ||
|
||
- name: Prepare Snyk message | ||
run: | | ||
echo "Snyk scan found the following vulnerabilities:" > snyk.txt | ||
- name: Format Snyk Message | ||
uses: sergeysova/jq-action@v2 | ||
continue-on-error: true | ||
with: | ||
cmd: jq -r '.vulnerabilities[] | "* **\(.severity)** - [\(.identifiers.CVE[0])] \(.title) in `\(.moduleName)` v\(.version). Fixed in \(.fixedIn)"' snyk.json >> snyk.txt | ||
|
||
- name: Determine whether to comment | ||
continue-on-error: true | ||
id: should-comment | ||
run: | | ||
if [[ $(wc -l < snyk.txt) -gt 1 ]]; then exit 0; fi | ||
exit 1 | ||
- name: Comment on PR with Snyk scan results | ||
uses: mshick/add-pr-comment@v2 | ||
if: ${{ steps.should-comment.outcome == 'success' }} | ||
with: | ||
message-id: snyk-${{ github.event.number }} | ||
message-path: snyk.txt |
48 changes: 2 additions & 46 deletions
48
.github/workflows/vulnerability-scan.yml → .github/workflows/trivy-pr-comment.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters