Skip to content

Commit 55550c7

Browse files
committed
Use a dynamic environment for PR jobs
1 parent 05f3c0a commit 55550c7

File tree

15 files changed

+85
-34
lines changed

15 files changed

+85
-34
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,16 @@ 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+
SECRETS: "${{ toJSON(secrets) }}"
50+
GITHUB_CTX: "${{ toJSON(github) }}"
51+
run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT
4952
id: jobs
5053
pr:
51-
name: "PR - ${{ matrix.name }}"
54+
name: "${{ matrix.name }}"
5255
needs:
5356
- 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
57+
env: "${{ matrix.env }}"
6358
if: "github.event_name == 'pull_request'"
6459
continue-on-error: "${{ matrix.name == 'mingw-check-tidy' }}"
6560
strategy:

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

Lines changed: 20 additions & 2 deletions
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,24 @@
1920

2021

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

src/ci/github-actions/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,16 @@ 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+
SECRETS: ${{ toJSON(secrets) }}
356+
GITHUB_CTX: ${{ toJSON(github) }}
357+
run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT
355358
id: jobs
356359
pr:
357360
<<: *base-ci-job
358-
name: PR - ${{ matrix.name }}
361+
name: ${{ matrix.name }}
359362
needs: [ calculate_matrix ]
360-
env:
361-
<<: [*shared-ci-variables, *public-variables]
362-
PR_CI_JOB: 1
363+
env: ${{ matrix.env }}
363364
if: github.event_name == 'pull_request'
364365
continue-on-error: ${{ matrix.name == 'mingw-check-tidy' }}
365366
strategy:

src/ci/github-actions/jobs.yml

Lines changed: 42 additions & 5 deletions
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)