Skip to content

Add new JSON output: supported Python versions #8

Add new JSON output: supported Python versions

Add new JSON output: supported Python versions #8

---
name: Use JSON output to build job matrix
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
env:
FORCE_COLOR: "1" # Make tools pretty.
jobs:
build-package:
name: Build & verify package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: pypa/sampleproject
path: sampleproject
- uses: actions/checkout@v4
with:
path: action
- uses: ./action
id: baipp
with:
path: sampleproject
outputs:
python-versions: ${{ steps.baipp.outputs.supported_pythons_json_array }}
# If your matrix consists only of Python versions, you can use the
# following, too:
# python-versions: ${{ steps.baipp.outputs.supported_pythons_json_job_matrix_value }}
test-package:
needs: build-package
runs-on: ubuntu-latest
strategy:
matrix:
# Create matrix from the 'python-versions' output from the build-package
# job.
python-version: ${{ fromJson(needs.build-package.outputs.python-versions) }}
# If you set 'python-versions' to
# 'supported_pythons_json_job_matrix_value'
# above, you would set the matrix like this instead:
# matrix: ${{ fromJson(needs.build-package.outputs.python-versions) }}
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# We have to check the project out because it doesn't include tox.ini in
# its SDist. If you include it, you can just unpack your SDist instead.
- uses: actions/checkout@v4
with:
repository: pypa/sampleproject
- name: Download wheels from the build-package job.
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- name: Prepare for tox
run: |
# We use tox together with the fast tox-uv plugin.
python -Im pip install tox-uv
# Ensure tests run against wheel.
rm -rf src
- run: python -Im tox run --installpkg dist/*.whl -f py$(echo ${{ matrix.python-version }} | tr -d .)
...