Skip to content

Add new JSON output: supported Python versions #3

Add new JSON output: supported Python versions

Add new JSON output: supported Python versions #3

---
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(python-versions) }}

Check failure on line 44 in .github/workflows/ci-supported-pythons.yml

View workflow run for this annotation

GitHub Actions / Use JSON output to build job matrix

Invalid workflow file

The workflow is not valid. .github/workflows/ci-supported-pythons.yml (Line: 44, Col: 25): Unrecognized named-value: 'python-versions'. Located at position 10 within expression: fromJson(python-versions) .github/workflows/ci-supported-pythons.yml (Line: 44, Col: 25): Unexpected value '${{ fromJson(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 }}
- name: Download built packages from the build-package job.
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- name: Prepare tests & config
run: |
# We use tox together with the fast tox-uv plugin.
python -mI pip install tox-uv
# Unpack SDist for tests & config files.
tar xf dist/*.tar.gz --strip-components=1
# Ensure tests run against wheel.
rm -rf src
- run: python -Im tox run --installpkg dist/*.whl -f py$(echo ${{ matrix.python-version }} | tr -d .)
...