Skip to content

Commit 09ac95b

Browse files
committed
Use uv in "pytest*" GHA workflows; update
- Use env.python-version in both workflows. - Run "pytest" on pull_request_target trigger to protect secrets; add "check permissions" job. - Use defaults.shell.run to set bash shell. - Rename env.gams → env.gams-version for clarity.
1 parent c782c30 commit 09ac95b

File tree

2 files changed

+65
-44
lines changed

2 files changed

+65
-44
lines changed

.github/workflows/pytest-snapshots.yaml

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ concurrency:
1414
cancel-in-progress: true
1515

1616
env:
17-
gams: "43.4.1"
18-
python: "3.12"
17+
gams-version: 43.4.1
18+
python-version: "3.13"
1919
upstream: main
2020

2121
jobs:
@@ -35,15 +35,15 @@ jobs:
3535
with:
3636
lfs: true
3737

38-
- uses: actions/setup-python@v5
38+
- name: Set up uv, Python
39+
uses: astral-sh/setup-uv@v5
3940
with:
41+
cache-dependency-glob: "**/pyproject.toml"
4042
python-version: ${{ env.python }}
41-
cache: pip
42-
cache-dependency-path: "**/pyproject.toml"
4343

4444
- uses: iiasa/actions/setup-gams@main
4545
with:
46-
version: ${{ env.gams }}
46+
version: ${{ env.gams-version }}
4747
license: ${{ secrets.GAMS_LICENSE }}
4848

4949
- uses: ts-graphviz/setup-graphviz@v2
@@ -59,12 +59,12 @@ jobs:
5959
# for open PRs), temporarily uncomment, add, or edit lines below
6060
# as needed. DO NOT merge such changes to `main`.
6161
run: |
62-
# pip install --upgrade "genno @ git+https://github.com/khaeru/genno.git@main"
63-
pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@${{ env.upstream }}"
64-
# pip install --upgrade "message-ix @ git+https://github.com/iiasa/message_ix.git@${{ env.upstream }}"
65-
pip install --upgrade "message-ix @ git+https://github.com/iiasa/message_ix.git@issue/723"
62+
# uv pip install --upgrade "genno @ git+https://github.com/khaeru/genno.git@main"
63+
uv pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@${{ env.upstream }}"
64+
# uv pip install --upgrade "message-ix @ git+https://github.com/iiasa/message_ix.git@${{ env.upstream }}"
65+
uv pip install --upgrade "message-ix @ git+https://github.com/iiasa/message_ix.git@issue/723"
6666
67-
pip install .[docs,tests] dask[dataframe]
67+
uv pip install .[docs,tests] dask[dataframe]
6868
6969
- name: Configure local data path
7070
run: |

.github/workflows/pytest.yaml

+54-33
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Test
22

33
on:
4-
pull_request:
5-
branches: [ main , "migrate**"]
4+
pull_request_target:
5+
branches: [ main, "migrate**" ]
6+
types: [ labeled, opened, reopened, synchronize ]
67
schedule:
78
# 05:00 UTC = 06:00 CET = 07:00 CEST
89
- cron: "0 5 * * *"
@@ -12,8 +13,33 @@ concurrency:
1213
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
1314
cancel-in-progress: true
1415

16+
defaults:
17+
run:
18+
shell: bash
19+
20+
env:
21+
gams-version: 43.4.1
22+
label: "safe to test"
23+
python-version: "3.13"
24+
1525
jobs:
26+
check:
27+
name: check permissions
28+
runs-on: ubuntu-latest
29+
steps:
30+
- if: >
31+
!(
32+
github.event_name == 'schedule'
33+
|| github.repository == github.event.pull_request.head.repo.full_name
34+
|| contains(github.event.pull_request.labels.*.name, env.label)
35+
)
36+
run: |
37+
echo "Pytest workflow will not run for branch in fork without label \`${{ env.label }}\`." >>$GITHUB_STEP_SUMMARY
38+
exit 1
39+
1640
warm-lfs-cache:
41+
needs: check
42+
1743
strategy:
1844
matrix:
1945
os: [ macos-13, macos-latest, ubuntu-latest, windows-latest ]
@@ -73,23 +99,23 @@ jobs:
7399
- name: Check out message-ix-models
74100
uses: francisbilham11/action-cached-lfs-checkout@v3
75101

76-
- uses: actions/setup-python@v5
102+
- name: Set up uv, Python
103+
uses: astral-sh/setup-uv@v5
77104
with:
105+
cache-dependency-glob: "**/pyproject.toml"
78106
python-version: ${{ matrix.version.python }}
79-
cache: pip
80-
cache-dependency-path: "**/pyproject.toml"
81107

82108
- uses: iiasa/actions/setup-gams@main
83109
with:
84-
version: 43.4.1
110+
version: ${{ env.gams-version }}
85111
license: ${{ secrets.GAMS_LICENSE }}
86112

87113
- uses: ts-graphviz/setup-graphviz@v2
88114
# Work around ts-graphviz/setup-graphviz#630
89-
if: ${{ matrix.os != 'macos-13' }}
115+
if: matrix.os != 'macos-13'
90116

91117
- name: Determine extra dependencies
92-
id: extra-deps
118+
id: dependencies
93119
run : |
94120
from os import environ
95121
from pathlib import Path
@@ -110,42 +136,36 @@ jobs:
110136
- name: Install packages and dependencies
111137
# By default, install:
112138
# - ixmp, message_ix: from GitHub branches/tags per matrix.version.upstream (above)
113-
# - other dependencies including genno: from PyPI.
139+
# - other dependencies: from PyPI.
114140
#
115-
# To test against unreleased code (on `main`, or other branches
116-
# for open PRs), temporarily uncomment, add, or edit lines below
117-
# as needed. DO NOT merge such changes to `main`.
141+
# To test against unreleased code (on `main`, or other branches for open PRs),
142+
# temporarily edit or add lines below as needed. DO NOT merge such changes to `main`.
118143
run: |
119-
pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@${{ matrix.version.upstream }}"
120-
pip install --upgrade "message-ix @ git+https://github.com/iiasa/message_ix.git@${{ matrix.version.upstream }}"
121-
122-
pip install .[docs,tests] ${{ steps.extra-deps.outputs.value }}
123-
124-
# TEMPORARY With Python 3.13 pyam-iamc resolves to 1.3.1, which in turn
125-
# limits pint < 0.17. Override.
126-
pip install --upgrade pint
144+
uv pip install --upgrade \
145+
${{ steps.dependencies.outputs.value }} \
146+
"ixmp @ git+https://github.com/iiasa/ixmp.git@${{ matrix.version.upstream }}" \
147+
"message-ix @ git+https://github.com/iiasa/message_ix.git@${{ matrix.version.upstream }}" \
148+
.[docs,tests]
127149
128150
- name: Configure local data path
129151
run: |
130152
mkdir -p message-local-data/cache
131153
mix-models config set "message local data" "$(realpath message-local-data)"
132154
mix-models config show
133-
shell: bash
134155
135156
- name: Run test suite using pytest
136157
run: |
137158
pytest message_ix_models \
138159
-m "not (ece_db or snapshot)" \
139-
-rA --verbose --color=yes --durations=20 \
160+
--color=yes --durations=20 -rA --verbose \
140161
--cov-report=term-missing --cov-report=xml \
141162
--numprocesses=auto \
142163
--local-cache --jvmargs="-Xmx6G"
143-
shell: bash
144164
145165
- name: Upload test coverage to Codecov.io
146166
uses: codecov/codecov-action@v5
147167
with:
148-
token: ${{ secrets.CODECOV_TOKEN }} # required
168+
token: ${{ secrets.CODECOV_TOKEN }} # Required
149169

150170
pre-commit:
151171
name: Code quality
@@ -154,12 +174,13 @@ jobs:
154174

155175
steps:
156176
- uses: actions/checkout@v4
157-
- uses: actions/setup-python@v5
158-
with: { python-version: "3.13" }
159-
160-
- name: Force recreation of pre-commit virtual environment for mypy
161-
if: github.event_name == 'schedule' # Comment this line to run on a PR
162-
run: gh cache list -L 999 | cut -f2 | grep pre-commit | xargs -I{} gh cache delete "{}" || true
163-
env: { GH_TOKEN: "${{ github.token }}" }
164-
165-
- uses: pre-commit/[email protected]
177+
- uses: astral-sh/setup-uv@v5
178+
with:
179+
cache-dependency-glob: "**/pyproject.toml"
180+
python-version: ${{ env.python-version }}
181+
- uses: actions/cache@v4
182+
with:
183+
path: ~/.cache/pre-commit
184+
key: pre-commit|${{ env.UV_PYTHON }}|${{ hashFiles('.pre-commit-config.yaml') }}
185+
lookup-only: ${{ github.event_name == 'schedule' }} # Set 'true' to recreate cache
186+
- run: uvx pre-commit run --all-files --color=always --show-diff-on-failure

0 commit comments

Comments
 (0)