Skip to content

Commit

Permalink
run mypy even if ruff fails
Browse files Browse the repository at this point in the history
Because all the checks are performed in the same job and github
actions will stop at the first step failure within a job, if one of
the ruff checks (formatting or checking) fails then mypy does not run
at all, which is undesirable.

Turns out the steps have an implicit `if success()` if no [status
check function][check] (`success`, `failure`, `always`, `cancelled`)
is used to guard the step.

Thus by gating on `always` and possibly explicitly checking the
conclusion of specific checks it becomes possible to run `mypy` even
though `ruff check` failed, but not run it if *installing* mypy
failed.

[check]: https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions
  • Loading branch information
masklinn committed Mar 26, 2024
1 parent 63eda17 commit a270fe2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,30 @@ on:
jobs:
checks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout working copy
uses: actions/checkout@v4
- name: ruff check
uses: chartboost/ruff-action@v1
- name: ruff format
if: always()
uses: chartboost/ruff-action@v1
with:
args: format --diff
- name: Set up Python
id: setup_python
if: always()
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install mypy
id: install_mypy
if: ${{ always() && steps.setup_python.conclusion == 'success' }}
run: |
python -mpip install --upgrade pip
python -mpip install mypy types-PyYaml
- name: mypy
if: ${{ always() && steps.install_mypy.conclusion == 'success' }}
run: mypy

# REPLACE BY: job which python -mbuild, and uploads the sdist and wheel to artifacts
Expand Down

0 comments on commit a270fe2

Please sign in to comment.