Skip to content

Commit c22c81c

Browse files
committed
Generate CI job matrix for PR jobs in Python
1 parent 99c42d2 commit c22c81c

File tree

4 files changed

+98
-28
lines changed

4 files changed

+98
-28
lines changed

.github/workflows/ci.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,21 @@ concurrency:
3636
group: "${{ github.workflow }}-${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}"
3737
cancel-in-progress: true
3838
jobs:
39+
calculate_matrix:
40+
name: Calculate job matrix
41+
runs-on: ubuntu-latest
42+
outputs:
43+
jobs: "${{ steps.jobs.outputs.jobs }}"
44+
steps:
45+
- name: Checkout the source code
46+
uses: actions/checkout@v4
47+
- name: Calculate the CI job matrix
48+
run: python3 src/ci/scripts/calculate-job-matrix.py >> $GITHUB_OUTPUT
49+
id: jobs
3950
pr:
4051
name: "PR - ${{ matrix.name }}"
52+
needs:
53+
- calculate_matrix
4154
env:
4255
PR_CI_JOB: 1
4356
CI_JOB_NAME: "${{ matrix.name }}"
@@ -51,20 +64,7 @@ jobs:
5164
continue-on-error: "${{ matrix.name == 'mingw-check-tidy' }}"
5265
strategy:
5366
matrix:
54-
include:
55-
- name: mingw-check
56-
os: ubuntu-20.04-4core-16gb
57-
env: {}
58-
- name: mingw-check-tidy
59-
os: ubuntu-20.04-4core-16gb
60-
env: {}
61-
- name: x86_64-gnu-llvm-17
62-
env:
63-
ENABLE_GCC_CODEGEN: "1"
64-
os: ubuntu-20.04-16core-64gb
65-
- name: x86_64-gnu-tools
66-
os: ubuntu-20.04-16core-64gb
67-
env: {}
67+
include: "${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}"
6868
defaults:
6969
run:
7070
shell: "${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}"

src/ci/github-actions/ci.yml

+13-14
Original file line numberDiff line numberDiff line change
@@ -340,30 +340,29 @@ concurrency:
340340
cancel-in-progress: true
341341

342342
jobs:
343+
calculate_matrix:
344+
name: Calculate job matrix
345+
runs-on: ubuntu-latest
346+
outputs:
347+
jobs: ${{ steps.jobs.outputs.jobs }}
348+
steps:
349+
- name: Checkout the source code
350+
uses: actions/checkout@v4
351+
- name: Calculate the CI job matrix
352+
run: python3 src/ci/scripts/calculate-job-matrix.py >> $GITHUB_OUTPUT
353+
id: jobs
343354
pr:
344355
<<: *base-ci-job
345356
name: PR - ${{ matrix.name }}
357+
needs: [ calculate_matrix ]
346358
env:
347359
<<: [*shared-ci-variables, *public-variables]
348360
PR_CI_JOB: 1
349361
if: github.event_name == 'pull_request'
350362
continue-on-error: ${{ matrix.name == 'mingw-check-tidy' }}
351363
strategy:
352364
matrix:
353-
include:
354-
- name: mingw-check
355-
<<: *job-linux-4c
356-
357-
- name: mingw-check-tidy
358-
<<: *job-linux-4c
359-
360-
- name: x86_64-gnu-llvm-17
361-
env:
362-
ENABLE_GCC_CODEGEN: "1"
363-
<<: *job-linux-16c
364-
365-
- name: x86_64-gnu-tools
366-
<<: *job-linux-16c
365+
include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}
367366

368367
auto:
369368
<<: *base-ci-job

src/ci/github-actions/jobs.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
x--expand-yaml-anchors--remove:
2+
- &base-job
3+
env: { }
4+
5+
- &job-linux-4c
6+
os: ubuntu-20.04-4core-16gb
7+
<<: *base-job
8+
9+
- &job-linux-8c
10+
os: ubuntu-20.04-8core-32gb
11+
<<: *base-job
12+
13+
- &job-linux-16c
14+
os: ubuntu-20.04-16core-64gb
15+
<<: *base-job
16+
17+
- &job-macos-xl
18+
os: macos-13 # We use the standard runner for now
19+
<<: *base-job
20+
21+
- &job-macos-m1
22+
os: macos-14
23+
<<: *base-job
24+
25+
- &job-windows-8c
26+
os: windows-2019-8core-32gb
27+
<<: *base-job
28+
29+
- &job-windows-16c
30+
os: windows-2019-16core-64gb
31+
<<: *base-job
32+
33+
- &job-aarch64-linux
34+
os: [ self-hosted, ARM64, linux ]
35+
36+
pr:
37+
- name: mingw-check
38+
<<: *job-linux-4c
39+
- name: mingw-check-tidy
40+
<<: *job-linux-4c
41+
- name: x86_64-gnu-llvm-17
42+
env:
43+
ENABLE_GCC_CODEGEN: "1"
44+
<<: *job-linux-16c
45+
- name: x86_64-gnu-tools
46+
<<: *job-linux-16c
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
This script serves for generating a matrix of jobs that should
5+
be executed on CI.
6+
7+
It reads job definitions from `src/ci/github-actions/jobs.yml`
8+
and filters them based on the event that happened on CI.
9+
10+
Currently, it only supports PR builds.
11+
"""
12+
13+
import json
14+
from pathlib import Path
15+
16+
import yaml
17+
18+
JOBS_YAML_PATH = Path(__file__).absolute().parent.parent / "github-actions" / "jobs.yml"
19+
20+
21+
if __name__ == "__main__":
22+
with open(JOBS_YAML_PATH) as f:
23+
jobs = yaml.safe_load(f)
24+
job_output = jobs["pr"]
25+
print(f"jobs={json.dumps(job_output)}")

0 commit comments

Comments
 (0)