Skip to content

Commit d2139f7

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 d2139f7

File tree

2 files changed

+57
-38
lines changed

2 files changed

+57
-38
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

+46-27
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,30 @@ 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+
github.repository != github.event.pull_request.head.repo.full_name &&
32+
! contains(github.event.pull_request.labels.*.name, env.label)
33+
run: |
34+
echo "Pytest workflow will not run for branch in fork without label \`${{ env.label }}\`." >>$GITHUB_STEP_SUMMARY
35+
exit 1
36+
1637
warm-lfs-cache:
38+
needs: check
39+
1740
strategy:
1841
matrix:
1942
os: [ macos-13, macos-latest, ubuntu-latest, windows-latest ]
@@ -73,20 +96,20 @@ jobs:
7396
- name: Check out message-ix-models
7497
uses: francisbilham11/action-cached-lfs-checkout@v3
7598

76-
- uses: actions/setup-python@v5
99+
- name: Set up uv, Python
100+
uses: astral-sh/setup-uv@v5
77101
with:
102+
cache-dependency-glob: "**/pyproject.toml"
78103
python-version: ${{ matrix.version.python }}
79-
cache: pip
80-
cache-dependency-path: "**/pyproject.toml"
81104

82105
- uses: iiasa/actions/setup-gams@main
83106
with:
84-
version: 43.4.1
107+
version: ${{ env.gams-version }}
85108
license: ${{ secrets.GAMS_LICENSE }}
86109

87110
- uses: ts-graphviz/setup-graphviz@v2
88111
# Work around ts-graphviz/setup-graphviz#630
89-
if: ${{ matrix.os != 'macos-13' }}
112+
if: matrix.os != 'macos-13'
90113

91114
- name: Determine extra dependencies
92115
id: extra-deps
@@ -116,31 +139,26 @@ jobs:
116139
# for open PRs), temporarily uncomment, add, or edit lines below
117140
# as needed. DO NOT merge such changes to `main`.
118141
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
142+
uv pip install --upgrade \
143+
"ixmp @ git+https://github.com/iiasa/ixmp.git@${{ matrix.version.upstream }}" \
144+
"message-ix @ git+https://github.com/iiasa/message_ix.git@${{ matrix.version.upstream }}" \
145+
.[docs,tests] \
146+
${{ steps.extra-deps.outputs.value }}
127147
128148
- name: Configure local data path
129149
run: |
130150
mkdir -p message-local-data/cache
131151
mix-models config set "message local data" "$(realpath message-local-data)"
132152
mix-models config show
133-
shell: bash
134153
135154
- name: Run test suite using pytest
136155
run: |
137156
pytest message_ix_models \
138157
-m "not (ece_db or snapshot)" \
139-
-rA --verbose --color=yes --durations=20 \
158+
--color=yes --durations=20 -rA --verbose \
140159
--cov-report=term-missing --cov-report=xml \
141160
--numprocesses=auto \
142161
--local-cache --jvmargs="-Xmx6G"
143-
shell: bash
144162
145163
- name: Upload test coverage to Codecov.io
146164
uses: codecov/codecov-action@v5
@@ -154,12 +172,13 @@ jobs:
154172

155173
steps:
156174
- 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]
175+
- uses: astral-sh/setup-uv@v5
176+
with:
177+
cache-dependency-glob: "**/pyproject.toml"
178+
python-version: ${{ env.python-version }}
179+
- uses: actions/cache@v4
180+
with:
181+
path: ~/.cache/pre-commit
182+
key: pre-commit|${{ env.UV_PYTHON }}|${{ hashFiles('.pre-commit-config.yaml') }}
183+
lookup-only: ${{ github.event_name == 'schedule' }} # Set 'true' to recreate cache
184+
- run: uvx pre-commit run --all-files --color=always --show-diff-on-failure

0 commit comments

Comments
 (0)