Skip to content

Lookup github action values from nox #1084

Lookup github action values from nox

Lookup github action values from nox #1084

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
# allow manual runs on branches without a PR
env:
FORCE_COLOR: "1"
OS_LIST: '["ubuntu-20.04", "windows-latest", "macos-latest"]'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
nox_data:
name: Query nox
runs-on: ubuntu-latest
outputs:
tests_matrix: ${{ steps.generate.outputs.tests_matrix }}
lint_python_version: ${{ steps.generate.outputs.lint_python_version }}
# our noxfile does not have an opinion about the python version for these:
docs_python_version: "3.9"
cover_python_version: "3.11"
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Nox-under-test
run: |
python -m pip install --disable-pip-version-check .
- name: Save nox sessions to json
run: |
nox -l --json >> nox_sessions.json
- name: Generate output variables
id: generate
run: |
jq 'map(select(.name == "tests")) | map({"python-version": .python, "tox-version": .call_spec.tox_version})' nox_sessions.json >> tests.json
: # Unfortunately, Adding OSes to `strategy:matrix:os` and the python/tox versions to `strategy:matrix:include` does not
: # combine as advertised so we have to make the combinations ourselves.
: # https://github.com/orgs/community/discussions/67591#discussioncomment-7402927
echo $OS_LIST | jq 'map({"os": .})' >> oses.json
: # -s places the contents of each json file (each of which contains a list) into the first two elements of a list.
: # 'combinations' loops creates a pair of objects for each combination in the two lists.
: # 'add' fuses each of the pairs of objects into a single object.
: # -c -j creates single line output.
OUTPUT=$(jq -c -j -s '[ combinations | add ]' tests.json oses.json)
echo "tests_matrix=$OUTPUT" >> "$GITHUB_OUTPUT"
echo $OUTPUT
OUTPUT=$(jq -c -j 'map(select(.name == "lint")) | map(.python) | .[0]' nox_sessions.json)
echo "lint_python_version=$OUTPUT" >> "$GITHUB_OUTPUT"
echo $OUTPUT
build:
needs: nox_data
name: build (${{ matrix.os }}, py-${{ matrix.python-version }}, tox ${{ matrix.tox-version }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include: ${{ fromJSON(needs.nox_data.outputs.tests_matrix) }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
use-mamba: true
- name: Install Nox-under-test
run: |
python -m pip install --disable-pip-version-check .
- name: Run tests on ${{ matrix.os }} (tox ${{ matrix.tox-version }})
run: |
nox --non-interactive --error-on-missing-interpreter --session "tests(python='${{ matrix.python-version }}', tox_version='${{ matrix.tox-version }}')" -- --full-trace
- name: Save coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-${{ github.job }}-${{ strategy.job-index }}
path: .coverage.*
coverage:
needs: [build, nox_data]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ needs.nox_data.outputs.cover_python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ fromJSON(needs.nox_data.outputs.cover_python_version) }}
- name: Install Nox-under-test
run: |
python -m pip install --disable-pip-version-check .
- name: Download individual coverage reports
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
- name: Display structure of downloaded files
run: ls -aR
- name: Run coverage
run: nox --non-interactive --session "cover"
lint:
needs: nox_data
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ needs.nox_data.outputs.lint_python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ fromJSON(needs.nox_data.outputs.lint_python_version) }}
- name: Install Nox-under-test
run: |
python -m pip install --disable-pip-version-check .
- name: Lint
run: nox --non-interactive --error-on-missing-interpreter --session "lint"
docs:
needs: nox_data
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ needs.nox_data.outputs.docs_python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ fromJSON(needs.nox_data.outputs.docs_python_version) }}
- name: Install Nox-under-test
run: |
python -m pip install --disable-pip-version-check .
- name: Docs
run: nox --non-interactive --error-on-missing-interpreter --session "docs"
deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Build sdist and wheel
run: pipx run build
- name: Publish distribution PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}