Skip to content

Merge pull request #851 from GSA/tdlowden-patch-1 #1176

Merge pull request #851 from GSA/tdlowden-patch-1

Merge pull request #851 from GSA/tdlowden-patch-1 #1176

Workflow file for this run

---
name: Snyk Security
on:
workflow_dispatch:
schedule:
# Run weekly on Sundays at 2:00 AM EST (7:00 AM UTC)
- cron: '0 7 * * 0'
push:
branches:
- main
jobs:
snyk-test:
name: snyk test
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
permissions:
contents: write
pull-requests: write
security-events: write
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() }}
id: scpr
uses: peter-evans/create-pull-request@v7
with:
commit-message: Update Pip Requirements
signoff: false
sign-commits: true
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
snyk-monitor:
name: snyk monitor
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
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
- name: Run Snyk Monitor
run: |
# Authenticate with Snyk
snyk auth ${{ secrets.SNYK_TOKEN }}
# Run snyk monitor to track dependencies
snyk monitor --file=requirements.txt