Skip to content

Commit 120ca94

Browse files
Update instance repo from cookiecutter template
1 parent 99a0f24 commit 120ca94

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

.github/workflows/env-matrix.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# /// script
2+
# requires-python = ">=3.11"
3+
# dependencies = [ "packaging", "hatch" ]
4+
# ///
5+
6+
import json
7+
from pathlib import Path
8+
from subprocess import check_output
9+
10+
import tomllib
11+
from packaging.specifiers import Specifier
12+
13+
conf = tomllib.loads(Path("pyproject.toml").read_text())
14+
spec = Specifier(conf["project"]["requires-python"])
15+
envs = json.loads(check_output(["hatch", "env", "show", "--json"]))
16+
matrix = dict(
17+
include=[
18+
dict(
19+
name=(
20+
f"{env_name} (PRE-RELEASE DEPENDENCIES)"
21+
if "pre" in env_name.split(".")
22+
else env_name
23+
),
24+
env_name=env_name,
25+
python=env["python"],
26+
)
27+
for env_name, env in envs.items()
28+
if env_name.startswith("hatch-test")
29+
if spec.contains(env["python"])
30+
]
31+
)
32+
print(json.dumps(matrix))

.github/workflows/test.yaml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,15 @@ jobs:
3131
uses: astral-sh/setup-uv@v5
3232
- name: Get test environments
3333
id: get-envs
34-
run: |
35-
MATRIX_JSON=$(uvx hatch env show --json | jq -c 'to_entries
36-
| map(
37-
select(.key | startswith("hatch-test"))
38-
| {
39-
env_name: .key,
40-
name: (if (.key | contains("pre")) then .key + " (PRE-RELEASE DEPENDENCIES)" else .key end),
41-
python: .value.python
42-
}
43-
)')
44-
echo "matrix=${MATRIX_JSON}" | tee $GITHUB_OUTPUT
34+
run: echo "matrix=$(uv run .workflows/envs-matrix.py)" | tee $GITHUB_OUTPUT
4535

4636
test:
4737
needs: get-environments
4838
runs-on: ubuntu-latest
4939

5040
strategy:
5141
fail-fast: false
52-
matrix:
53-
include: ${{ fromJSON(needs.get-environments.outputs.matrix) }}
42+
matrix: ${{ fromJSON(needs.get-environments.outputs.matrix) }}
5443

5544
name: ${{ matrix.name }}
5645

0 commit comments

Comments
 (0)