From 93ac79ffbb0305cb278b29148ce50538691c45c1 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 4 Oct 2024 13:32:27 +0100 Subject: [PATCH] Add optional run_pre and run_post commands to tox workflow (#224) --- .github/workflows/test.yml | 62 ++++++-------------------------------- .github/workflows/tox.yml | 28 ++++++++++++++--- 2 files changed, 33 insertions(+), 57 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f0c86d3..7d2e42f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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() diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d97b566..fd14adb 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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 @@ -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 @@ -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 @@ -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: @@ -176,6 +193,7 @@ jobs: fi - name: Upload coverage data + if: ${{ inputs.jobs_producing_coverage }} uses: codecov/codecov-action@v4 with: name: ${{ matrix.name }} @@ -183,7 +201,7 @@ jobs: 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