Skip to content

Commit 476d4ae

Browse files
committed
Use a dynamic environment for PR jobs
1 parent 05f3c0a commit 476d4ae

File tree

15 files changed

+82
-34
lines changed

15 files changed

+82
-34
lines changed

.github/workflows/ci.yml

+5-11
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,15 @@ jobs:
4545
- name: Checkout the source code
4646
uses: actions/checkout@v4
4747
- name: Calculate the CI job matrix
48-
run: python3 src/ci/scripts/calculate-job-matrix.py >> $GITHUB_OUTPUT
48+
env:
49+
GITHUB_CTX: "${{ toJSON(github) }}"
50+
run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT
4951
id: jobs
5052
pr:
51-
name: "PR - ${{ matrix.name }}"
53+
name: "${{ matrix.name }}"
5254
needs:
5355
- calculate_matrix
54-
env:
55-
PR_CI_JOB: 1
56-
CI_JOB_NAME: "${{ matrix.name }}"
57-
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
58-
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
59-
DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
60-
SCCACHE_BUCKET: rust-lang-ci-sccache2
61-
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
62-
CACHE_DOMAIN: ci-caches.rust-lang.org
56+
env: "${{ matrix.env }}"
6357
if: "github.event_name == 'pull_request'"
6458
continue-on-error: "${{ matrix.name == 'mingw-check-tidy' }}"
6559
strategy:

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

+19-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import json
14+
import os
1415
from pathlib import Path
1516

1617
import yaml
@@ -19,7 +20,23 @@
1920

2021

2122
if __name__ == "__main__":
23+
github_ctx = json.loads(os.environ["GITHUB_CTX"])
24+
25+
print(github_ctx)
26+
2227
with open(JOBS_YAML_PATH) as f:
2328
jobs = yaml.safe_load(f)
24-
job_output = jobs["pr"]
25-
print(f"jobs={json.dumps(job_output)}")
29+
selected_jobs = jobs["pr"]
30+
31+
for job in selected_jobs:
32+
name = job.get("name")
33+
if name is None:
34+
raise Exception(f"Job {job} has no `name` attribute")
35+
env = job.get("env", {})
36+
env["CI_JOB_NAME"] = name
37+
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
38+
env["HEAD_SHA"] = "" # ${{ github.event.pull_request.head.sha || github.sha }}
39+
# env["DOCKER_TOKEN"] = secrets["github_token"]
40+
job["env"] = env
41+
42+
print(f"jobs={json.dumps(selected_jobs)}")

src/ci/github-actions/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ jobs:
351351
- name: Checkout the source code
352352
uses: actions/checkout@v4
353353
- name: Calculate the CI job matrix
354-
run: python3 src/ci/scripts/calculate-job-matrix.py >> $GITHUB_OUTPUT
354+
env:
355+
GITHUB_CTX: ${{ toJSON(github) }}
356+
run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT
355357
id: jobs
356358
pr:
357359
<<: *base-ci-job
358-
name: PR - ${{ matrix.name }}
360+
name: ${{ matrix.name }}
359361
needs: [ calculate_matrix ]
360-
env:
361-
<<: [*shared-ci-variables, *public-variables]
362-
PR_CI_JOB: 1
362+
env: ${{ matrix.env }}
363363
if: github.event_name == 'pull_request'
364364
continue-on-error: ${{ matrix.name == 'mingw-check-tidy' }}
365365
strategy:

src/ci/github-actions/jobs.yml

+42-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@
22
# dynamically in CI from ci.yml.
33
# You *do not* need to re-run `src/tools/expand-yaml-anchors` when you
44
# modify this file.
5-
shared_defs:
5+
variables:
6+
- &shared-ci-variables
7+
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
8+
9+
- &public-variables
10+
SCCACHE_BUCKET: rust-lang-ci-sccache2
11+
TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate
12+
CACHE_DOMAIN: ci-caches.rust-lang.org
13+
14+
- &prod-variables
15+
SCCACHE_BUCKET: rust-lang-ci-sccache2
16+
DEPLOY_BUCKET: rust-lang-ci2
17+
TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate
18+
TOOLSTATE_ISSUES_API_URL: https://api.github.com/repos/rust-lang/rust/issues
19+
TOOLSTATE_PUBLISH: 1
20+
# AWS_SECRET_ACCESS_KEYs are stored in GitHub's secrets storage, named
21+
# AWS_SECRET_ACCESS_KEY_<keyid>. Including the key id in the name allows to
22+
# rotate them in a single branch while keeping the old key in another
23+
# branch, which wouldn't be possible if the key was named with the kind
24+
# (caches, artifacts...).
25+
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL
26+
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55
27+
AWS_REGION: us-west-1
28+
CACHE_DOMAIN: ci-caches.rust-lang.org
29+
30+
runners:
631
- &base-job
732
env: { }
833

@@ -37,14 +62,26 @@ shared_defs:
3762
- &job-aarch64-linux
3863
os: [ self-hosted, ARM64, linux ]
3964

65+
envs:
66+
- &pr-env
67+
<<: [ *shared-ci-variables, *public-variables ]
68+
PR_CI_JOB: 1
69+
4070
pr:
41-
- name: mingw-check
71+
- name: PR - mingw-check
72+
env:
73+
<<: *pr-env
4274
<<: *job-linux-4c
43-
- name: mingw-check-tidy
75+
- name: PR - mingw-check-tidy
76+
env:
77+
<<: *pr-env
4478
<<: *job-linux-4c
45-
- name: x86_64-gnu-llvm-17
79+
- name: PR - x86_64-gnu-llvm-17
4680
env:
4781
ENABLE_GCC_CODEGEN: "1"
82+
<<: *pr-env
4883
<<: *job-linux-16c
49-
- name: x86_64-gnu-tools
84+
- name: PR - x86_64-gnu-tools
85+
env:
86+
<<: *pr-env
5087
<<: *job-linux-16c

src/llvm-project

Submodule llvm-project updated 82 files

src/tools/cargo

Submodule cargo updated 307 files

0 commit comments

Comments
 (0)