Skip to content

Commit

Permalink
Automate python version matrix on gitub actions
Browse files Browse the repository at this point in the history
pyproject.toml is the source of truth for supported Python versions. No other files need to be kept in sync.
  • Loading branch information
millerdev committed Feb 21, 2025
1 parent 27ef347 commit f602ff0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,29 @@ on:
pull_request:

jobs:
build:
configure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Read Python versions from pyproject.toml
id: read-versions
# produces output like: python_versions=[ "3.9", "3.10", "3.11", "3.12" ]
run: >-
python_versions=$(
grep -oP '(?<=Language :: Python :: )\d\.\d+' pyproject.toml
| jq --raw-input .
| jq --slurp .
) >> $GITHUB_OUTPUT
outputs:
python_versions: ${{ steps.read-versions.outputs.python_versions }}

build:
needs: [configure]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ${{ fromJSON(needs.configure.outputs.python_versions) }}

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ requires-python = ">= 3.9"
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",

# The following classifiers are parsed by Github Actions workflows.
# Precise formatting is important (no extra spaces, etc.)
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",

"License :: OSI Approved :: BSD License",
]

Expand Down

0 comments on commit f602ff0

Please sign in to comment.