Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Implement Snyk #202

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
eb30382
ci: Add Snyk scan step to test workflows
faucomte97 Feb 17, 2025
4d3518a
Point to branch
faucomte97 Feb 18, 2025
dd9875b
Mojis
faucomte97 Feb 18, 2025
941cf64
Specify working dir everywhere?
faucomte97 Feb 18, 2025
5b4b915
Move arg to with
faucomte97 Feb 18, 2025
e096504
Test specifying working dir at job level
faucomte97 Feb 18, 2025
71f679e
Ls
faucomte97 Feb 18, 2025
c857dfc
Comment out test jobs
faucomte97 Feb 18, 2025
626be7d
Whatever
faucomte97 Feb 18, 2025
47d1c8d
Try scanning using Pipenv
faucomte97 Feb 18, 2025
56051d2
Show everything
faucomte97 Feb 18, 2025
bea68d9
Go back to requirements.txt
faucomte97 Feb 18, 2025
9a40876
Use test and reorder
faucomte97 Feb 18, 2025
32e045e
Try pip with Pipfile
faucomte97 Feb 18, 2025
60764c9
Add fail-fast
faucomte97 Feb 18, 2025
c58c033
Checkout Python
faucomte97 Feb 18, 2025
f2a7921
Checkout Python
faucomte97 Feb 18, 2025
9c9dd82
Stefan magic
faucomte97 Feb 18, 2025
1a4ebe8
Point to pipenv dir
faucomte97 Feb 18, 2025
7d9fc2b
Use outputs
faucomte97 Feb 18, 2025
028755f
Use args not command
faucomte97 Feb 18, 2025
3e0de0a
Bring command back
faucomte97 Feb 18, 2025
1355b40
Bring command back
faucomte97 Feb 18, 2025
383bf1f
Pipenv system
faucomte97 Feb 18, 2025
2773563
Remove command again
faucomte97 Feb 18, 2025
5467744
Pasting old system action cos i hate this
faucomte97 Feb 18, 2025
f666f0d
Remove global working dir setting
faucomte97 Feb 18, 2025
932be5d
LANG
faucomte97 Feb 18, 2025
20cb8cc
Simplify
faucomte97 Feb 18, 2025
699015e
Simplify even more
faucomte97 Feb 18, 2025
17a93bf
Add args
faucomte97 Feb 18, 2025
498171e
Try requirements.txt again
faucomte97 Feb 18, 2025
9fd6247
Skip unresolved
faucomte97 Feb 18, 2025
62a3490
Try Pipfile again one more time
faucomte97 Feb 18, 2025
4aa7c2d
Cleanup and monitor action
faucomte97 Feb 18, 2025
31a19b8
Cleanup frontend Snyk check
faucomte97 Feb 18, 2025
63e4106
Monitor in release job on main branch
faucomte97 Feb 19, 2025
85a9cb9
Remove unused flag
faucomte97 Feb 19, 2025
244108a
Final cleanup
faucomte97 Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ on:
CFL_BOT_GH_TOKEN:
description: "The CFL-bot's GitHub token. Used to release."
required: false
SNYK_TOKEN:
description: "The Snyk token used to connect to the Snyk project."
required: false

jobs:
test:
Expand Down Expand Up @@ -90,6 +93,14 @@ jobs:
with:
cfl-bot-gh-token: ${{ secrets.CFL_BOT_GH_TOKEN }}

- name: 🔎 Run Snyk scan
uses: snyk/actions/python@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --file=requirements.txt --package-manager=pip --skip-unresolved
command: monitor

- name: 📥 Download Build Artifact
uses: actions/download-artifact@v4
with:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
CFL_BOT_GH_TOKEN:
description: "The CFL-bot's GitHub token. Used to release."
required: false
SNYK_TOKEN:
description: "The Snyk token used to connect to the Snyk project."
required: false

jobs:
test:
Expand All @@ -41,6 +44,14 @@ jobs:
with:
cfl-bot-gh-token: ${{ secrets.CFL_BOT_GH_TOKEN }}

- name: 🔎 Run Snyk scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --file=package.json --package-manager=yarn
command: monitor

- name: 🚀 Publish Semantic Release
uses: ocadotechnology/codeforlife-workspace/.github/actions/service/release@main
with:
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/test-javascript-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,35 @@ on:
CODECOV_TOKEN:
description: "The token used to gain access to Codecov."
required: false # Needs to be false to support contributors
SNYK_TOKEN:
description: "The Snyk token used to connect to the Snyk project."
required: false

jobs:
test-js-code:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ${{ inputs.working-directory }}
env:
OCADO_TECH_ORG_ID: 2088731
steps:
- name: 🌐 Set up JavaScript ${{ inputs.node-version }} Environment
uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@main
with:
node-version: ${{ inputs.node-version }}
working-directory: ${{ inputs.working-directory }}
install-args: --production=false

- name: 🔎 Check Code Format
working-directory: ${{ inputs.working-directory }}
run: yarn run prettier --check --write=false .

- name: 🔎 Check Static Type Hints
working-directory: ${{ inputs.working-directory }}
run: yarn run tsc --build tsconfig.json

- name: 🔎 Check Static Code
working-directory: ${{ inputs.working-directory }}
run: yarn run eslint --max-warnings=0 .

- name: 🧪 Test Code Units
working-directory: ${{ inputs.working-directory }}
run: |
if [ ${{ github.repository_owner_id }} = ${{ env.OCADO_TECH_ORG_ID }} ]
then
Expand All @@ -81,5 +82,11 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ inputs.codecov-slug }}
codecov_yml_path: ${{ inputs.codecov-yml-path }}
working-directory: ${{ inputs.working-directory }}
file: ${{ inputs.codecov-file }}

- name: 🔎 Run Snyk to check vulnerabilities in Node and report them here
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --file=package.json --package-manager=yarn --severity-threshold=medium
30 changes: 21 additions & 9 deletions .github/workflows/test-python-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ on:
CODECOV_TOKEN:
description: "The token used to gain access to Codecov."
required: false # Needs to be false to support contributors
SNYK_TOKEN:
description: "The Snyk token used to connect to the Snyk project."
required: false

jobs:
test-py-code:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ${{ inputs.working-directory }}
env:
PYPROJECT_TOML: ${{ inputs.pyproject-toml-directory }}/pyproject.toml
COVERAGE_REPORT: coverage.xml # NOTE: COVERAGE_FILE is reserved - do not use.
LANG: C.UTF-8
OCADO_TECH_ORG_ID: 2088731
DB_NAME: ${{ inputs.postgres-db }}
DB_HOST: localhost
Expand Down Expand Up @@ -97,23 +104,31 @@ jobs:
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main
with:
python-version: ${{ inputs.python-version }}
working-directory: ${{ inputs.working-directory }}
install-args: --dev
install-args: --system

- name: 📝 Generate requirements file
run: pip freeze > requirements.txt

- name: 🔎 Run Snyk to check for vulnerabilities and report them here
uses: snyk/actions/python@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --file=requirements.txt --package-manager=pip --severity-threshold=medium --skip-unresolved

- name: 🧪 Also install dev dependencies
run: pipenv install --dev --system

- name: 🔎 Check Import Sort
working-directory: ${{ inputs.working-directory }}
run: pipenv run isort --settings-file=${{ env.PYPROJECT_TOML }} --check ${{ inputs.source-path }}

- name: 🔎 Check Code Format
working-directory: ${{ inputs.working-directory }}
run: if ! pipenv run black --config=${{ env.PYPROJECT_TOML }} --check ${{ inputs.source-path }}; then exit 1; fi

- name: 🔎 Check Static Type Hints
working-directory: ${{ inputs.working-directory }}
run: pipenv run mypy --config-file=${{ env.PYPROJECT_TOML }} ${{ inputs.source-path }}

- name: 🔎 Check Static Code
working-directory: ${{ inputs.working-directory }}
run: |
echo 'Linting non-test files'

Expand Down Expand Up @@ -143,11 +158,9 @@ jobs:

- name: 🔎 Check Django Migrations
if: inputs.check-django-migrations
working-directory: ${{ inputs.working-directory }}
run: pipenv run python manage.py makemigrations --check --dry-run

- name: 🧪 Test Code Units
working-directory: ${{ inputs.working-directory }}
run: |
if [ ${{ github.repository_owner_id }} = ${{ env.OCADO_TECH_ORG_ID }} ]
then
Expand All @@ -174,5 +187,4 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ inputs.codecov-slug }}
codecov_yml_path: ${{ inputs.codecov-yml-path }}
working-directory: ${{ inputs.working-directory }}
file: ${{ env.COVERAGE_REPORT }}