Skip to content

Commit bf6a0fc

Browse files
dynamically test with all supported Python versions
1 parent a83ab45 commit bf6a0fc

2 files changed

Lines changed: 183 additions & 85 deletions

File tree

.github/workflows/tests.yml

Lines changed: 93 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
name: tests
22

33
on:
4-
push:
4+
pull_request:
55
branches:
66
- main
77
- 'release/*.x'
8-
tags:
9-
- '*'
10-
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
- ready_for_review
13+
push:
1114
branches:
1215
- main
1316
- 'release/*.x'
17+
tags:
18+
- '*'
1419
schedule:
15-
# Weekly Monday 9AM build
16-
- cron: "0 9 * * 1"
20+
- cron: "0 9 * * 1" # every Monday at 9a
1721
workflow_dispatch:
1822
inputs:
1923
crds_context:
@@ -28,57 +32,98 @@ on:
2832
default: https://jwst-crds.stsci.edu
2933

3034
concurrency:
31-
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.crds_context }}
35+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ inputs.crds_context }}
3236
cancel-in-progress: true
3337

38+
permissions: {}
39+
40+
env:
41+
PYTHON_VERSIONS: 3.9 3.10 3.11 3.12 3.13 3.14
42+
CRDS_PATH: /tmp/data/crds_cache
43+
CRDS_OBSERVATORY: jwst
44+
CRDS_SERVER_URL: ${{ inputs.crds_server || 'https://jwst-crds.stsci.edu' }}
45+
CRDS_CLIENT_RETRY_COUNT: 3
46+
CRDS_CLIENT_RETRY_DELAY_SECONDS: 20
47+
3448
jobs:
35-
check:
36-
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@2835f0cacddf3f8de198db9afdb5354a5cebe0ef # v2.6.3
37-
with:
38-
default_python: "3.12"
39-
envs: |
40-
- linux: check-dependencies
41-
latest_crds_contexts:
42-
uses: ./.github/workflows/contexts.yml
43-
crds_context:
44-
needs: [ latest_crds_contexts ]
49+
supported-pythons:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
53+
with:
54+
persist-credentials: false
55+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
56+
with:
57+
python-version: "3"
58+
- run: pip install packaging tomli
59+
- name: convert Python version(s) into JSON list
60+
id: versions
61+
shell: python
62+
run: |
63+
import os
64+
import json
65+
66+
import tomli
67+
from packaging.specifiers import SpecifierSet
68+
from packaging.version import Version
69+
70+
with open("pyproject.toml", "rb") as pyproject_toml_file:
71+
version_requirements = SpecifierSet(tomli.load(pyproject_toml_file)["project"]["requires-python"])
72+
73+
versions = [str(version) for version in sorted([Version(version) for version in os.environ["PYTHON_VERSIONS"].split() if version in version_requirements])]
74+
75+
with open(os.environ["GITHUB_OUTPUT"], "a") as github_output:
76+
print(f"json={json.dumps(versions)}", file=github_output)
77+
print(f"oldest={versions[0]}", file=github_output)
78+
print(f"latest={versions[-1]}", file=github_output)
79+
outputs:
80+
python-version-json: ${{ steps.versions.outputs.json }}
81+
oldest: ${{ steps.versions.outputs.oldest }}
82+
latest: ${{ steps.versions.outputs.latest }}
83+
crds:
4584
runs-on: ubuntu-latest
4685
steps:
47-
- id: context
48-
run: echo context=${{ github.event_name == 'workflow_dispatch' && (inputs.crds_context != '' && inputs.crds_context || needs.latest_crds_contexts.outputs.jwst) || needs.latest_crds_contexts.outputs.jwst }} >> $GITHUB_OUTPUT
86+
- if: inputs.crds_context
87+
id: latest-context
88+
run: >
89+
echo latest-context=$(
90+
curl -s -X POST -d '{"jsonrpc": "1.0", "method": "get_default_context", "params": ["${{ env.CRDS_OBSERVATORY }}", "latest"], "id": 1}' ${{ env.CRDS_SERVER_URL }}/json/ --retry 8 --connect-timeout 10 |
91+
python -c "import sys, json; print(json.load(sys.stdin)['result'])"
92+
) >> $GITHUB_OUTPUT
4993
outputs:
50-
context: ${{ steps.context.outputs.context }}
94+
path: ${{ env.CRDS_PATH }}
95+
server-url: ${{ env.CRDS_SERVER_URL }}
96+
context: ${{ inputs.crds_context || steps.latest-context.outputs.latest-context }}
97+
client-retry-count: ${{ env.CRDS_CLIENT_RETRY_COUNT }}
98+
client-retry-delay-seconds: ${{ env.CRDS_CLIENT_RETRY_DELAY_SECONDS }}
5199
test:
52-
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@2835f0cacddf3f8de198db9afdb5354a5cebe0ef # v2.6.3
53-
needs: [ crds_context ]
54-
secrets:
55-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
100+
needs:
101+
- supported-pythons
102+
- crds
103+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@4193751d511425d4edc1d5657c24b2128d49b017 # v2.6.4
56104
with:
57105
setenv: |
58-
CRDS_PATH: /tmp/data/crds_cache
59-
CRDS_SERVER_URL: ${{ github.event_name == 'workflow_dispatch' && inputs.crds_server || 'https://jwst-crds.stsci.edu' }}
60-
CRDS_CONTEXT: ${{ needs.crds_context.outputs.context }}
61-
CRDS_CLIENT_RETRY_COUNT: 3
62-
CRDS_CLIENT_RETRY_DELAY_SECONDS: 20
63-
cache-path: /tmp/data/crds_cache
64-
cache-key: crds-${{ needs.crds_context.outputs.context }}
65-
artifact-path: |
66-
results.xml
67-
submodules: false
68-
coverage: ''
106+
CRDS_PATH: ${{ needs.crds.outputs.path }}
107+
CRDS_SERVER_URL: ${{ needs.crds.outputs.server-url }}
108+
CRDS_CONTEXT: ${{ needs.crds.outputs.context }}
109+
CRDS_CLIENT_RETRY_COUNT: ${{ needs.crds.outputs.client-retry-count }}
110+
CRDS_CLIENT_RETRY_DELAY_SECONDS: ${{ needs.crds.outputs.client-retry-delay-seconds}}
111+
cache-path: ${{ needs.crds.outputs.path }}
112+
cache-key: crds-${{ needs.crds.outputs.context }}
69113
envs: |
70-
- linux: py311-oldestdeps-xdist-cov
71-
coverage: codecov
72-
pytest-results-summary: true
73-
- linux: py311-xdist
74-
posargs: -vv
114+
- name: run tests (oldest supported Python, ubuntu-latest)
115+
linux: py3-oldestdeps-xdist-cov
116+
python-version: ${{ needs.supported-pythons.outputs.oldest }}
117+
- name: run tests with coverage (latest supported Python, ubuntu-latest)
118+
linux: py3-cov
119+
python-version: ${{ needs.supported-pythons.outputs.latest }}
75120
pytest-results-summary: true
76-
- linux: py312-xdist
77-
pytest-results-summary: true
78-
# `tox` does not currently respect `requires-python` versions when creating testing environments;
79-
# if this breaks, add an upper pin to `requires-python` and revert this py3 to the latest working version
80-
- linux: py313-cov-xdist
81121
coverage: codecov
82-
pytest-results-summary: true
83-
- macos: py314-xdist
84-
pytest-results-summary: true
122+
- name: run tests (latest supported Python, macos-latest)
123+
macos: py3
124+
python-version: ${{ needs.supported-pythons.outputs.latest }}
125+
fill: true
126+
fill_platforms: linux
127+
fill_factors: xdist
128+
artifact-path: |
129+
results.xml

.github/workflows/tests_extra.yml

Lines changed: 90 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ on:
44
pull_request:
55
branches:
66
- main
7-
- '*x'
8-
# We also want this workflow triggered if the 'run devdeps tests' label is added
9-
# or present when PR is updated
7+
- 'release/*.x'
108
types:
9+
- opened
1110
- synchronize
11+
- reopened
12+
- ready_for_review
1213
- labeled
14+
push:
15+
branches:
16+
- main
17+
- 'release/*.x'
18+
tags:
19+
- '*'
1320
schedule:
14-
# Weekly Monday 6AM build
15-
- cron: "0 0 * * 1"
21+
- cron: "0 0 * * 1" # every Monday at 6a
1622
workflow_dispatch:
1723
inputs:
1824
crds_context:
@@ -27,49 +33,96 @@ on:
2733
default: https://jwst-crds.stsci.edu
2834

2935
concurrency:
30-
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.crds_context }}
36+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ inputs.crds_context }}
3137
cancel-in-progress: true
3238

39+
permissions: {}
40+
41+
env:
42+
PYTHON_VERSIONS: 3.9 3.10 3.11 3.12 3.13 3.14
43+
CRDS_PATH: /tmp/data/crds_cache
44+
CRDS_OBSERVATORY: jwst
45+
CRDS_SERVER_URL: ${{ inputs.crds_server || 'https://jwst-crds.stsci.edu' }}
46+
CRDS_CLIENT_RETRY_COUNT: 3
47+
CRDS_CLIENT_RETRY_DELAY_SECONDS: 20
48+
3349
jobs:
34-
latest_crds_contexts:
50+
supported-pythons:
3551
if: (github.repository == 'spacetelescope/jwst' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'run extra tests')))
36-
uses: ./.github/workflows/contexts.yml
37-
crds_context:
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
55+
with:
56+
persist-credentials: false
57+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
58+
with:
59+
python-version: "3"
60+
- run: pip install packaging tomli
61+
- name: convert Python version(s) into JSON list
62+
id: versions
63+
shell: python
64+
run: |
65+
import os
66+
import json
67+
68+
import tomli
69+
from packaging.specifiers import SpecifierSet
70+
from packaging.version import Version
71+
72+
with open("pyproject.toml", "rb") as pyproject_toml_file:
73+
version_requirements = SpecifierSet(tomli.load(pyproject_toml_file)["project"]["requires-python"])
74+
75+
versions = [str(version) for version in sorted([Version(version) for version in os.environ["PYTHON_VERSIONS"].split() if version in version_requirements])]
76+
77+
with open(os.environ["GITHUB_OUTPUT"], "a") as github_output:
78+
print(f"json={json.dumps(versions)}", file=github_output)
79+
print(f"oldest={versions[0]}", file=github_output)
80+
print(f"latest={versions[-1]}", file=github_output)
81+
outputs:
82+
python-version-json: ${{ steps.versions.outputs.json }}
83+
oldest: ${{ steps.versions.outputs.oldest }}
84+
latest: ${{ steps.versions.outputs.latest }}
85+
crds:
3886
if: (github.repository == 'spacetelescope/jwst' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'run extra tests')))
39-
needs: [ latest_crds_contexts ]
4087
runs-on: ubuntu-latest
4188
steps:
42-
- id: context
43-
run: echo context=${{ github.event_name == 'workflow_dispatch' && (inputs.crds_context != '' && inputs.crds_context || needs.latest_crds_contexts.outputs.jwst) || needs.latest_crds_contexts.outputs.jwst }} >> $GITHUB_OUTPUT
89+
- if: inputs.crds_context
90+
id: latest-context
91+
run: >
92+
echo latest-context=$(
93+
curl -s -X POST -d '{"jsonrpc": "1.0", "method": "get_default_context", "params": ["${{ env.CRDS_OBSERVATORY }}", "latest"], "id": 1}' ${{ env.CRDS_SERVER_URL }}/json/ --retry 8 --connect-timeout 10 |
94+
python -c "import sys, json; print(json.load(sys.stdin)['result'])"
95+
) >> $GITHUB_OUTPUT
4496
outputs:
45-
context: ${{ steps.context.outputs.context }}
97+
path: ${{ env.CRDS_PATH }}
98+
server-url: ${{ env.CRDS_SERVER_URL }}
99+
context: ${{ inputs.crds_context || steps.latest-context.outputs.latest-context }}
100+
client-retry-count: ${{ env.CRDS_CLIENT_RETRY_COUNT }}
101+
client-retry-delay-seconds: ${{ env.CRDS_CLIENT_RETRY_DELAY_SECONDS }}
46102
test:
47103
if: (github.repository == 'spacetelescope/jwst' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'run extra tests')))
48-
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@2835f0cacddf3f8de198db9afdb5354a5cebe0ef # v2.6.3
49-
needs: [ crds_context ]
104+
needs:
105+
- supported-pythons
106+
- crds
107+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@4193751d511425d4edc1d5657c24b2128d49b017 # v2.6.4
50108
with:
51109
setenv: |
52-
CRDS_PATH: /tmp/crds_cache
53-
CRDS_SERVER_URL: ${{ github.event_name == 'workflow_dispatch' && inputs.crds_server || 'https://jwst-crds.stsci.edu' }}
54-
CRDS_CONTEXT: ${{ needs.crds_context.outputs.context }}
55-
CRDS_CLIENT_RETRY_COUNT: 3
56-
CRDS_CLIENT_RETRY_DELAY_SECONDS: 20
57-
cache-path: /tmp/crds_cache
58-
cache-key: crds-${{ needs.crds_context.outputs.context }}
59-
artifact-path: |
60-
results.xml
110+
CRDS_PATH: ${{ needs.crds.outputs.path }}
111+
CRDS_SERVER_URL: ${{ needs.crds.outputs.server-url }}
112+
CRDS_CONTEXT: ${{ needs.crds.outputs.context }}
113+
CRDS_CLIENT_RETRY_COUNT: ${{ needs.crds.outputs.client-retry-count }}
114+
CRDS_CLIENT_RETRY_DELAY_SECONDS: ${{ needs.crds.outputs.client-retry-delay-seconds}}
115+
cache-path: ${{ needs.crds.outputs.path }}
116+
cache-key: crds-${{ needs.crds.outputs.context }}
61117
envs: |
62118
- linux: check-docs-links
63-
python-version: '3.13'
64-
- macos: py311-xdist
65-
pytest-results-summary: true
66-
- macos: py312-xdist
67-
pytest-results-summary: true
68-
- linux: py314-stdevdeps-xdist
69-
pytest-results-summary: true
70-
- macos: py313-stdevdeps-xdist
71-
pytest-results-summary: true
72-
- linux: py314-devdeps-xdist
73-
pytest-results-summary: true
74-
- macos: py313-devdeps-xdist
75-
pytest-results-summary: true
119+
python-version: ${{ needs.supported-pythons.outputs.latest }}
120+
- linux: py3-stdevdeps-xdist
121+
- linux: py3-devdeps-xdist
122+
- macos: py3-stdevdeps-xdist
123+
- macos: py3-devdeps-xdist
124+
fill: true
125+
fill_platforms: macos
126+
fill_factors: xdist
127+
artifact-path: |
128+
results.xml

0 commit comments

Comments
 (0)