Skip to content

Commit 7316721

Browse files
let's try this?
1 parent e54a428 commit 7316721

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ jobs:
2525
generate-matrix:
2626
runs-on: ubuntu-latest
2727
outputs:
28-
include: ${{ steps.set-version-matrix.outputs.include }}
29-
os: ${{ steps.set-os-matrix.outputs.os }}
28+
matrix: ${{ steps.set-matrix.outputs.include }}
3029
steps:
3130
- uses: actions/checkout@v4
3231

@@ -36,25 +35,17 @@ jobs:
3635
enable-cache: true
3736
pyproject-file: pyproject.toml
3837

39-
- id: set-version-matrix
38+
- id: set-matrix
4039
run: |
4140
uv run noxfile.py --session gha_matrix
4241
43-
- id: set-os-matrix
44-
run: |
45-
os_input="${{ inputs.os || 'ubuntu-latest' }}"
46-
# -R reads raw string, split(",") creates array, map(gsub(...)) trims whitespace, -c outputs compact JSON
47-
echo "os=$(echo '${{ inputs.os || 'ubuntu-latest' }}' | jq -R -c 'split(",") | map(gsub("^ *| *$"; ""))')" >> "$GITHUB_OUTPUT"
48-
4942
test:
5043
name: Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }} (${{ matrix.os }})
5144
runs-on: ${{ matrix.os }}
5245
needs: generate-matrix
5346
strategy:
5447
fail-fast: false
55-
matrix:
56-
os: ${{ fromJSON(needs.generate-matrix.outputs.os) }}
57-
include: ${{ fromJSON(needs.generate-matrix.outputs.include) }}
48+
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
5849
steps:
5950
- uses: actions/checkout@v4
6051

noxfile.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,28 @@ def lint(session):
124124

125125
@nox.session
126126
def gha_matrix(session):
127+
os_args = session.posargs[0]
128+
os_list = [os.strip() for os in os_args.split(",") if os_args.strip()] or [
129+
"ubuntu-latest"
130+
]
131+
127132
sessions = session.run("nox", "-l", "--json", external=True, silent=True)
128-
matrix = [
133+
versions_list = [
129134
{
130135
"django-version": session["call_spec"]["django"],
131136
"python-version": session["python"],
132137
}
133138
for session in json.loads(sessions)
134139
if session["name"] == "tests"
135140
]
136-
with Path(os.environ["GITHUB_OUTPUT"]).open("a") as fh:
137-
print(f"include={matrix}", file=fh)
141+
142+
matrix = [{**combo, "os": os} for os in os_list for combo in versions_list]
143+
144+
if os.environ.get("GITHUB_OUTPUT"):
145+
with Path(os.environ["GITHUB_OUTPUT"]).open("a") as fh:
146+
print(f"matrix={matrix}", file=fh)
147+
else:
148+
print(matrix)
138149

139150

140151
if __name__ == "__main__":

0 commit comments

Comments
 (0)