Check for Snyk Vulnerabilities #827
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
--- | |
name: Check for Snyk Vulnerabilities | |
on: | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
schedule: | |
- cron: '0 12 * * *' # every day at 12pm UTC | |
jobs: | |
snyk: | |
name: snyk test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Display Python version | |
run: python -c "import sys; print(sys.version)" | |
- name: Install Dependencies | |
run: | | |
npm install snyk -g | |
sudo apt-get update -y | |
sudo apt-get install -y \ | |
openssl libssl-dev libffi-dev pkg-config libxml2-dev \ | |
libxmlsec1-dev libxmlsec1-openssl libgeos-dev proj-bin \ | |
libpq-dev | |
pip3 install -r requirements.txt | |
- name: Run Snyk Scan | |
run: | | |
# Run scan | |
snyk auth ${{ secrets.SNYK_TOKEN }} | |
snyk test --severity-threshold=medium --file=ckan/requirements.txt --json-file-output=scan.json || echo "Scan complete" | |
# Exit if no vulnerabilities | |
# Succeed, so that PR is NOT created | |
[[ "$(jq '.ok' scan.json)" == "true" ]] && exit 0 | |
# Update requirements.in with the snyk fix suggestions | |
python tools/snyk-update.py | |
# Update requirements.txt | |
make update-dependencies | |
# Check if there are any changes | |
if [ -z "$(git status --porcelain)" ]; then | |
echo "Found vulnerable issues but no upgrade or patch available" | |
cat scan.json | jq '[.vulnerabilities[] | .id] | unique[]' | |
else | |
echo "Changes made to add into PR: " | |
git diff | |
fi | |
# Fail so that PR is created | |
exit 1 | |
- name: Create Pull Request | |
if: ${{ failure() && github.event_name == 'schedule' }} | |
id: scpr | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.ADD_TO_PROJECT_PAT }} | |
commit-message: Update Pip Requirements | |
committer: Data.gov Github <datagovhelp@gsa.gov> | |
author: ${{ github.actor }} <datagovhelp@gsa.gov> | |
signoff: false | |
branch: requirement-patches | |
delete-branch: true | |
title: '[Snyk + GH Actions] Update requirements' | |
body: | | |
Update requirements | |
- Updated `requirements.in` + `requirements.txt` | |
- Auto-generated by [snyk.yml][1] | |
[1]: https://github.com/gsa/catalog.data.gov/.github/workflows/snyk.yml | |
labels: | | |
requirements | |
automated pr | |
snyk | |
draft: false |