Skip to content

Check for Snyk Vulnerabilities #732

Check for Snyk Vulnerabilities

Check for Snyk Vulnerabilities #732

Workflow file for this run

---
name: Check for Snyk Vulnerabilities
on: # yamllint disable-line rule:truthy
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.14
cache: 'pip'
- 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
# yamllint disable rule:line-length
- name: Run Snyk Scan
run: |
# Run scan
snyk auth ${{ secrets.SNYK_TOKEN }}
snyk test --severity-threshold=medium --file=requirements.txt --json-file-output=/tmp/scan.json || echo "Scan complete"
# Exit if no vulnerabilities
# Succeed, so that PR is NOT created
[[ "$(jq '.ok' /tmp/scan.json)" == "true" ]] && exit 0
# Update requirements.in with the snyk fix suggestions
python bin/snyk-update.py
# Update requirements.txt
make requirements
# Check if there are any changes
if [ -z "$(git status --porcelain)" ]; then
echo "Found vulnerable issues but no upgrade or patch available"
cat /tmp/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/inventory-app/.github/workflows/snyk.yml
labels: |
requirements
automated pr
snyk
draft: false
# yamllint enable rule:line-length