Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 19 additions & 19 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ jobs:
run: pnpm install --frozen-lockfile
working-directory: ./dashboard

lint-js:
if: github.event.pull_request.draft != true
needs: setup-node
pre-commit-checks:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: setup-node
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: 3.12

- name: Fetch node_modules
uses: actions/cache@v4
Expand All @@ -68,9 +70,15 @@ jobs:
with:
node-version-file: './dashboard/.nvmrc'

- name: Run eslint
run: pnpm lint-staged
working-directory: ./dashboard
- name: Cache Pre-Commit Hooks
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Setup pre-commit
run: pip install pre-commit
- name: Run pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure

build-front:
if: github.event.pull_request.draft != true
Expand Down Expand Up @@ -104,7 +112,7 @@ jobs:
run: pnpm build
working-directory: ./dashboard

lint-and-unit-test-django:
unit-test-django:
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
timeout-minutes: 3
Expand All @@ -114,14 +122,6 @@ jobs:
- name: Setup Backend
uses: ./.github/actions/setup-backend

- name: Check Lint
run: poetry run ruff check .
working-directory: ./backend

- name: Check Format
run: poetry run ruff format --check .
working-directory: ./backend

- name: Run unit tests with coverage
run: |
poetry run pytest -m unit --cov=kernelCI_app --cov=kernelCI_cache --cov-report=term-missing
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
needs:
- lint-and-unit-test-django
- unit-test-django
- integration-test-django
permissions:
contents: write
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:

# Call job in a a split file
call-deploy-staging:
needs: [lint-js, build-front, lint-and-unit-test-django, integration-test-django]
needs: [pre-commit-checks, build-front, unit-test-django, integration-test-django]
# This 'if' ensures it only runs on pushes to main (the production requirement)
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
uses: ./.github/workflows/deploy-staging.yaml
Expand Down
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,25 @@ repos:
- --
language: system
always_run: true

- id: api-schema
name: API schema is up-to-date
entry: |
python -c '
import os, subprocess, sys;
os.chdir("backend")
subprocess.run(["poetry", "install"], capture_output=True)
spectacular = subprocess.run(["poetry", "run", "python", "manage.py", "spectacular"], capture_output=True, text=True)
new_schema = spectacular.stdout
with open("schema.yml") as f:
old_schema = f.read()
if new_schema != old_schema:
print("Schema is not up-to-date. Run \"python manage.py spectacular --file schema.yml\" to regenerate it")
sys.exit(1)
'
files: 'backend/(.*\.py|schema.yml)'
pass_filenames: false
language: python
language_version: '3.12'
additional_dependencies: [poetry]
stages: [pre-commit]
Comment on lines +78 to +98

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use python+subprocess instead of sh?

Suggested change
- id: api-schema
name: API schema is up-to-date
entry: |
python -c '
import os, subprocess, sys;
os.chdir("backend")
subprocess.run(["poetry", "install"], capture_output=True)
spectacular = subprocess.run(["poetry", "run", "python", "manage.py", "spectacular"], capture_output=True, text=True)
new_schema = spectacular.stdout
with open("schema.yml") as f:
old_schema = f.read()
if new_schema != old_schema:
print("Schema is not up-to-date. Run \"python manage.py spectacular --file schema.yml\" to regenerate it")
sys.exit(1)
'
files: 'backend/(.*\.py|schema.yml)'
pass_filenames: false
language: python
language_version: '3.12'
additional_dependencies: [poetry]
stages: [pre-commit]
- id: api-schema
name: API schema is up-to-date
entry: |
bash -c '
cd backend || exit 1
poetry install --quiet
NEW_SCHEMA=$(poetry run python manage.py spectacular)
OLD_SCHEMA=$(cat schema.yml 2>/dev/null)
if [ "$NEW_SCHEMA" != "$OLD_SCHEMA" ]; then
echo "Schema is not up-to-date. Run \"python manage.py spectacular --file schema.yml\" to regenerate it"
exit 1
fi
'
files: '^backend/(.*\.py|schema\.yml)$'
pass_filenames: false
language: system
stages: [pre-commit]

-- Assisted-by: Gemini

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also warned about poetry install --quiet causing commits to become slow, but I doubt it's a problem

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, it suggested using --validate --fail-on-warn instead of diffing the schema

Loading