Skip to content

Commit

Permalink
Add optional run_pre and run_post commands to tox workflow (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Oct 4, 2024
1 parent 082cc65 commit 93ac79f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 57 deletions.
62 changes: 10 additions & 52 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,18 @@
---
name: test
name: tox
on:
pull_request:
jobs:
pre:
name: pre
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.generate_matrix.outputs.matrix }}
steps:
- name: Determine matrix
id: generate_matrix
uses: coactions/dynamic-matrix@v3
with:
min_python: "3.12"
max_python: "3.12"
default_python: "3.12"
other_names: |
lint
docs
test:
needs: pre
name: ${{ matrix.name || matrix.tox_env }}
runs-on: ${{ matrix.runs-on || 'ubuntu-latest' }}
strategy:
fail-fast: true
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
steps:
- name: Check out src from Git
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed by setuptools-scm
submodules: recursive

- name: Install a default Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}

- name: Install dependencies
run: |
python3 -m pip install 'tox>=4.0.0'
- run: ${{ matrix.command }}

- run: ${{ matrix.command2 }}
if: ${{ matrix.command2 }}

- run: ${{ matrix.command3 }}
if: ${{ matrix.command3 }}

- run: ${{ matrix.command4 }}
if: ${{ matrix.command4 }}

- run: ${{ matrix.command5 }}
if: ${{ matrix.command5 }}
# tests reusable tox workflow
uses: ./.github/workflows/tox.yml
with:
default_python: "3.10"
jobs_producing_coverage: 0
max_python: "3.13"
min_python: "3.10"
run_post: echo 'Running post'
run_pre: echo 'Running pre'

check: # This job does nothing and is only used for the branch protection
if: always()
Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ on:
description: Additional names for the matrix
required: false
type: string
run_pre:
default: ""
description: Preparatory command to run before test commands.
required: false
type: string
run_post:
default: ""
description: Command to run after test commands.
required: false
type: string

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # might be needed by tox commands
Expand All @@ -49,11 +59,10 @@ jobs:
min_python: ${{ inputs.min_python }}
max_python: ${{ inputs.max_python }}
default_python: ${{ inputs.default_python }}
# we must use tox to query these
other_names: |
docs
lint
pkg
py312-milestone
${{ inputs.other_names_also }}
platforms: linux,macos

Expand Down Expand Up @@ -86,12 +95,16 @@ jobs:
key: pre-commit-${{ matrix.name }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up Python ${{ matrix.python_version || '3.12' }}
if: "!contains(matrix.shell, 'wsl')"
if: ${{ !contains(matrix.shell, 'wsl') }}
uses: actions/setup-python@v5
with:
cache: pip
cache: ${{ hashFiles('requirements.txt', 'pyproject.toml') && 'pip' || '' }}
python-version: ${{ matrix.python_version || '3.12' }}

- name: Run pre
if: ${{ inputs.run_pre }}
run: ${{ inputs.run_pre }}

- name: Install tox
run: |
python3 -m pip install --upgrade pip
Expand All @@ -114,6 +127,10 @@ jobs:
- run: ${{ matrix.command5 }}
if: ${{ matrix.command5 }}

- name: Run post
if: ${{ inputs.run_post }}
run: ${{ inputs.run_post }}

- name: Archive logs and coverage data
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -176,14 +193,15 @@ jobs:
fi
- name: Upload coverage data
if: ${{ inputs.jobs_producing_coverage }}
uses: codecov/codecov-action@v4
with:
name: ${{ matrix.name }}
fail_ci_if_error: true
use_oidc: true

- name: Check codecov.io status
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request' && inputs.jobs_producing_coverage
uses: coactions/codecov-status@main

- name: Decide whether the needed jobs succeeded or failed
Expand Down

0 comments on commit 93ac79f

Please sign in to comment.