Skip to content

Commit 036bf57

Browse files
authored
Rollup merge of #124327 - Kobzol:ci-skip-jobs, r=pietroalbini
CI: implement job skipping in Python matrix calculation This removes the `step` YAML anchor and the corresponding bash script. Best reviewed commit-by-commit. r? ```@pietroalbini```
2 parents fc6070c + c36d78e commit 036bf57

File tree

5 files changed

+31
-98
lines changed

5 files changed

+31
-98
lines changed

.github/workflows/ci.yml

+2-29
Original file line numberDiff line numberDiff line change
@@ -88,96 +88,70 @@ jobs:
8888
run: "echo \"[CI_PR_NUMBER=$num]\""
8989
env:
9090
num: "${{ github.event.number }}"
91-
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
91+
if: "success() && github.event_name == 'pull_request'"
9292
- name: add extra environment variables
9393
run: src/ci/scripts/setup-environment.sh
9494
env:
9595
EXTRA_VARIABLES: "${{ toJson(matrix.env) }}"
96-
if: success() && !env.SKIP_JOB
97-
- name: decide whether to skip this job
98-
run: src/ci/scripts/should-skip-this.sh
99-
if: success() && !env.SKIP_JOB
10096
- name: ensure the channel matches the target branch
10197
run: src/ci/scripts/verify-channel.sh
102-
if: success() && !env.SKIP_JOB
10398
- name: collect CPU statistics
10499
run: src/ci/scripts/collect-cpu-stats.sh
105-
if: success() && !env.SKIP_JOB
106100
- name: show the current environment
107101
run: src/ci/scripts/dump-environment.sh
108-
if: success() && !env.SKIP_JOB
109102
- name: install awscli
110103
run: src/ci/scripts/install-awscli.sh
111-
if: success() && !env.SKIP_JOB
112104
- name: install sccache
113105
run: src/ci/scripts/install-sccache.sh
114-
if: success() && !env.SKIP_JOB
115106
- name: select Xcode
116107
run: src/ci/scripts/select-xcode.sh
117-
if: success() && !env.SKIP_JOB
118108
- name: install clang
119109
run: src/ci/scripts/install-clang.sh
120-
if: success() && !env.SKIP_JOB
121110
- name: install tidy
122111
run: src/ci/scripts/install-tidy.sh
123-
if: success() && !env.SKIP_JOB
124112
- name: install WIX
125113
run: src/ci/scripts/install-wix.sh
126-
if: success() && !env.SKIP_JOB
127114
- name: disable git crlf conversion
128115
run: src/ci/scripts/disable-git-crlf-conversion.sh
129-
if: success() && !env.SKIP_JOB
130116
- name: checkout submodules
131117
run: src/ci/scripts/checkout-submodules.sh
132-
if: success() && !env.SKIP_JOB
133118
- name: install MSYS2
134119
run: src/ci/scripts/install-msys2.sh
135-
if: success() && !env.SKIP_JOB
136120
- name: install MinGW
137121
run: src/ci/scripts/install-mingw.sh
138-
if: success() && !env.SKIP_JOB
139122
- name: install ninja
140123
run: src/ci/scripts/install-ninja.sh
141-
if: success() && !env.SKIP_JOB
142124
- name: enable ipv6 on Docker
143125
run: src/ci/scripts/enable-docker-ipv6.sh
144-
if: success() && !env.SKIP_JOB
145126
- name: disable git crlf conversion
146127
run: src/ci/scripts/disable-git-crlf-conversion.sh
147-
if: success() && !env.SKIP_JOB
148128
- name: ensure line endings are correct
149129
run: src/ci/scripts/verify-line-endings.sh
150-
if: success() && !env.SKIP_JOB
151130
- name: ensure backported commits are in upstream branches
152131
run: src/ci/scripts/verify-backported-commits.sh
153-
if: success() && !env.SKIP_JOB
154132
- name: ensure the stable version number is correct
155133
run: src/ci/scripts/verify-stable-version-number.sh
156-
if: success() && !env.SKIP_JOB
157134
- name: run the build
158135
run: src/ci/scripts/run-build-from-ci.sh 2>&1
159136
env:
160137
AWS_ACCESS_KEY_ID: "${{ env.CACHES_AWS_ACCESS_KEY_ID }}"
161138
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
162139
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
163-
if: success() && !env.SKIP_JOB
164140
- name: create github artifacts
165141
run: src/ci/scripts/create-doc-artifacts.sh
166-
if: success() && !env.SKIP_JOB
167142
- name: upload artifacts to github
168143
uses: actions/upload-artifact@v4
169144
with:
170145
name: "${{ env.DOC_ARTIFACT_NAME }}"
171146
path: obj/artifacts/doc
172147
if-no-files-found: ignore
173148
retention-days: 5
174-
if: success() && !env.SKIP_JOB
175149
- name: upload artifacts to S3
176150
run: src/ci/scripts/upload-artifacts.sh
177151
env:
178152
AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}"
179153
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
180-
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
154+
if: "success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
181155
master:
182156
name: master
183157
runs-on: ubuntu-latest
@@ -202,7 +176,6 @@ jobs:
202176
shell: bash
203177
env:
204178
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
205-
if: success() && !env.SKIP_JOB
206179
try-success:
207180
needs:
208181
- job

src/ci/github-actions/calculate-job-matrix.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
import yaml
1919

20+
CI_DIR = Path(__file__).absolute().parent.parent
2021
JOBS_YAML_PATH = Path(__file__).absolute().parent / "jobs.yml"
2122

23+
Job = Dict[str, Any]
2224

23-
def name_jobs(jobs: List[Dict], prefix: str) -> List[Dict]:
25+
26+
def name_jobs(jobs: List[Dict], prefix: str) -> List[Job]:
2427
"""
2528
Add a `name` attribute to each job, based on its image and the given `prefix`.
2629
"""
@@ -29,7 +32,7 @@ def name_jobs(jobs: List[Dict], prefix: str) -> List[Dict]:
2932
return jobs
3033

3134

32-
def add_base_env(jobs: List[Dict], environment: Dict[str, str]) -> List[Dict]:
35+
def add_base_env(jobs: List[Job], environment: Dict[str, str]) -> List[Job]:
3336
"""
3437
Prepends `environment` to the `env` attribute of each job.
3538
The `env` of each job has higher precedence than `environment`.
@@ -77,7 +80,7 @@ def find_job_type(ctx: GitHubCtx) -> Optional[JobType]:
7780
return None
7881

7982

80-
def calculate_jobs(job_type: JobType, job_data: Dict[str, Any]) -> List[Dict[str, Any]]:
83+
def calculate_jobs(job_type: JobType, job_data: Dict[str, Any]) -> List[Job]:
8184
if job_type == JobType.PR:
8285
return add_base_env(name_jobs(job_data["pr"], "PR"), job_data["envs"]["pr"])
8386
elif job_type == JobType.Try:
@@ -88,6 +91,13 @@ def calculate_jobs(job_type: JobType, job_data: Dict[str, Any]) -> List[Dict[str
8891
return []
8992

9093

94+
def skip_jobs(jobs: List[Dict[str, Any]], channel: str) -> List[Job]:
95+
"""
96+
Skip CI jobs that are not supposed to be executed on the given `channel`.
97+
"""
98+
return [j for j in jobs if j.get("only_on_channel", channel) == channel]
99+
100+
91101
def get_github_ctx() -> GitHubCtx:
92102
return GitHubCtx(
93103
event_name=os.environ["GITHUB_EVENT_NAME"],
@@ -107,9 +117,13 @@ def get_github_ctx() -> GitHubCtx:
107117
job_type = find_job_type(github_ctx)
108118
logging.info(f"Job type: {job_type}")
109119

120+
with open(CI_DIR / "channel") as f:
121+
channel = f.read().strip()
122+
110123
jobs = []
111124
if job_type is not None:
112125
jobs = calculate_jobs(job_type, data)
126+
jobs = skip_jobs(jobs, channel)
113127

114128
logging.info(f"Output:\n{yaml.dump(jobs, indent=4)}")
115129
print(f"jobs={json.dumps(jobs)}")

src/ci/github-actions/ci.yml

+2-34
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ x--expand-yaml-anchors--remove:
107107
- &job-aarch64-linux
108108
os: [self-hosted, ARM64, linux]
109109

110-
- &step
111-
if: success() && !env.SKIP_JOB
112-
113110
- &base-ci-job
114111
defaults:
115112
run:
@@ -151,7 +148,7 @@ x--expand-yaml-anchors--remove:
151148
run: echo "[CI_PR_NUMBER=$num]"
152149
env:
153150
num: ${{ github.event.number }}
154-
if: success() && !env.SKIP_JOB && github.event_name == 'pull_request'
151+
if: success() && github.event_name == 'pull_request'
155152

156153
- name: add extra environment variables
157154
run: src/ci/scripts/setup-environment.sh
@@ -161,71 +158,51 @@ x--expand-yaml-anchors--remove:
161158
# are passed to the `setup-environment.sh` script encoded in JSON,
162159
# which then uses log commands to actually set them.
163160
EXTRA_VARIABLES: ${{ toJson(matrix.env) }}
164-
<<: *step
165-
166-
- name: decide whether to skip this job
167-
run: src/ci/scripts/should-skip-this.sh
168-
<<: *step
169161

170162
- name: ensure the channel matches the target branch
171163
run: src/ci/scripts/verify-channel.sh
172-
<<: *step
173164

174165
- name: collect CPU statistics
175166
run: src/ci/scripts/collect-cpu-stats.sh
176-
<<: *step
177167

178168
- name: show the current environment
179169
run: src/ci/scripts/dump-environment.sh
180-
<<: *step
181170

182171
- name: install awscli
183172
run: src/ci/scripts/install-awscli.sh
184-
<<: *step
185173

186174
- name: install sccache
187175
run: src/ci/scripts/install-sccache.sh
188-
<<: *step
189176

190177
- name: select Xcode
191178
run: src/ci/scripts/select-xcode.sh
192-
<<: *step
193179

194180
- name: install clang
195181
run: src/ci/scripts/install-clang.sh
196-
<<: *step
197182

198183
- name: install tidy
199184
run: src/ci/scripts/install-tidy.sh
200-
<<: *step
201185

202186
- name: install WIX
203187
run: src/ci/scripts/install-wix.sh
204-
<<: *step
205188

206189
- name: disable git crlf conversion
207190
run: src/ci/scripts/disable-git-crlf-conversion.sh
208-
<<: *step
209191

210192
- name: checkout submodules
211193
run: src/ci/scripts/checkout-submodules.sh
212-
<<: *step
213194

214195
- name: install MSYS2
215196
run: src/ci/scripts/install-msys2.sh
216-
<<: *step
217197

218198
- name: install MinGW
219199
run: src/ci/scripts/install-mingw.sh
220-
<<: *step
221200

222201
- name: install ninja
223202
run: src/ci/scripts/install-ninja.sh
224-
<<: *step
225203

226204
- name: enable ipv6 on Docker
227205
run: src/ci/scripts/enable-docker-ipv6.sh
228-
<<: *step
229206

230207
# Disable automatic line ending conversion (again). On Windows, when we're
231208
# installing dependencies, something switches the git configuration directory or
@@ -234,19 +211,15 @@ x--expand-yaml-anchors--remove:
234211
# appropriate line endings.
235212
- name: disable git crlf conversion
236213
run: src/ci/scripts/disable-git-crlf-conversion.sh
237-
<<: *step
238214

239215
- name: ensure line endings are correct
240216
run: src/ci/scripts/verify-line-endings.sh
241-
<<: *step
242217

243218
- name: ensure backported commits are in upstream branches
244219
run: src/ci/scripts/verify-backported-commits.sh
245-
<<: *step
246220

247221
- name: ensure the stable version number is correct
248222
run: src/ci/scripts/verify-stable-version-number.sh
249-
<<: *step
250223

251224
- name: run the build
252225
# Redirect stderr to stdout to avoid reordering the two streams in the GHA logs.
@@ -255,11 +228,9 @@ x--expand-yaml-anchors--remove:
255228
AWS_ACCESS_KEY_ID: ${{ env.CACHES_AWS_ACCESS_KEY_ID }}
256229
AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}
257230
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
258-
<<: *step
259231

260232
- name: create github artifacts
261233
run: src/ci/scripts/create-doc-artifacts.sh
262-
<<: *step
263234

264235
- name: upload artifacts to github
265236
uses: actions/upload-artifact@v4
@@ -269,7 +240,6 @@ x--expand-yaml-anchors--remove:
269240
path: obj/artifacts/doc
270241
if-no-files-found: ignore
271242
retention-days: 5
272-
<<: *step
273243

274244
- name: upload artifacts to S3
275245
run: src/ci/scripts/upload-artifacts.sh
@@ -281,8 +251,7 @@ x--expand-yaml-anchors--remove:
281251
# adding the condition is helpful as this way CI will not silently skip
282252
# deploying artifacts from a dist builder if the variables are misconfigured,
283253
# erroring about invalid credentials instead.
284-
if: success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')
285-
<<: *step
254+
if: success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')
286255

287256
# These snippets are used by the try-success, try-failure, auto-success and auto-failure jobs.
288257
# Check out their documentation for more information on why they're needed.
@@ -399,7 +368,6 @@ jobs:
399368
shell: bash
400369
env:
401370
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
402-
<<: *step
403371

404372
# These jobs don't actually test anything, but they're used to tell bors the
405373
# build completed, as there is no practical way to detect when a workflow is

src/ci/github-actions/jobs.yml

+10-11
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pr:
7979
<<: *job-linux-16c
8080

8181
# Jobs that run when you perform a try build (@bors try)
82-
# These jobs automatically inherit envs.production, to avoid repeating
82+
# These jobs automatically inherit envs.try, to avoid repeating
8383
# it in each job definition.
8484
try:
8585
- image: dist-x86_64-linux
@@ -88,7 +88,7 @@ try:
8888
<<: *job-linux-16c
8989

9090
# Main CI jobs that have to be green to merge a commit into master
91-
# These jobs automatically inherit envs.production, to avoid repeating
91+
# These jobs automatically inherit envs.auto, to avoid repeating
9292
# it in each job definition.
9393
auto:
9494
#############################
@@ -200,24 +200,23 @@ auto:
200200
# channel name on the output), and this builder prevents landing
201201
# changes that would result in broken builds after a promotion.
202202
- image: x86_64-gnu-stable
203+
# Only run this job on the nightly channel. Running this on beta
204+
# could cause failures when `dev: 1` in `stage0.txt`, and running
205+
# this on stable is useless.
206+
only_on_channel: nightly
203207
env:
204208
IMAGE: x86_64-gnu
205209
RUST_CI_OVERRIDE_RELEASE_CHANNEL: stable
206-
# Only run this job on the nightly channel. Running this on beta
207-
# could cause failures when `dev: 1` in `stage0.txt`, and running
208-
# this on stable is useless.
209-
CI_ONLY_WHEN_CHANNEL: nightly
210210
<<: *job-linux-4c
211211

212212
- image: x86_64-gnu-aux
213213
<<: *job-linux-4c
214214

215215
- image: x86_64-gnu-integration
216-
env:
217-
# Only run this job on the nightly channel. Fuchsia requires
218-
# nightly features to compile, and this job would fail if
219-
# executed on beta and stable.
220-
CI_ONLY_WHEN_CHANNEL: nightly
216+
# Only run this job on the nightly channel. Fuchsia requires
217+
# nightly features to compile, and this job would fail if
218+
# executed on beta and stable.
219+
only_on_channel: nightly
221220
<<: *job-linux-8c
222221

223222
- image: x86_64-gnu-debug

src/ci/scripts/should-skip-this.sh

-21
This file was deleted.

0 commit comments

Comments
 (0)