Skip to content

Commit c8299f3

Browse files
committed
Improve CI docs
1 parent 4ca046c commit c8299f3

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

src/infra/docs/rustc-ci.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# How the Rust CI works
22

3+
Rust CI ensures that the master branch of rust-lang/rust is always in a valid state.
4+
5+
A developer submitting a pull request to rust-lang/rust, experiences the following:
6+
* A small subset of tests and checks are run on each commit to catch common errors.
7+
* When the PR is ready and approved, the "bors" tool enqueues a full CI run.
8+
* The full run is either performed or the PR is "rolled up" with other changes.
9+
* Eventually a CI run containing the changes from the PR is performed and either passes or fails with an error the developer must address.
10+
311
## Which jobs we run
412

5-
The `rust-lang/rust` repository uses GitHub Actions to test [all the other
13+
The `rust-lang/rust` repository uses GitHub Actions to test [all the
614
platforms][platforms] we support. We currently have two kinds of jobs running
715
for each commit we want to merge to master:
816

@@ -12,15 +20,14 @@ for each commit we want to merge to master:
1220
[rustup-toolchain-install-master] tool; The same builds are also used for
1321
actual releases: our release process basically consists of copying those
1422
artifacts from `rust-lang-ci2` to the production endpoint and signing them.
15-
1623
- Non-dist jobs run our full test suite on the platform, and the test suite of
1724
all the tools we ship through rustup; The amount of stuff we test depends on
1825
the platform (for example some tests are run only on Tier 1 platforms), and
1926
some quicker platforms are grouped together on the same builder to avoid
2027
wasting CI resources.
2128

2229
All the builds except those on macOS and Windows are executed inside that
23-
platform’s custom Docker container. This has a lot of advantages for us:
30+
platform’s custom [Docker container]. This has a lot of advantages for us:
2431

2532
- The build environment is consistent regardless of the changes of the
2633
underlying image (switching from the trusty image to xenial was painless for
@@ -31,14 +38,20 @@ platform’s custom Docker container. This has a lot of advantages for us:
3138
time thanks to Docker image caching.
3239
- Users can run the same tests in the same environment locally by just running
3340
`src/ci/docker/run.sh image-name`, which is awesome to debug failures.
41+
- Forces the use of portable scripts to drive the CI process which keeps the CI fairly platform independent (i.e., we are not overly reliant on GitHub Actions).
42+
43+
The docker images prefixed with `dist-` are used for building artifacts while those without that prefix run tests and checks.
3444

3545
We also run tests for less common architectures (mainly Tier 2 and Tier 3
3646
platforms) in CI. Since those platforms are not x86 we either run
3747
everything inside QEMU or just cross-compile if we don’t want to run the tests
3848
for that platform.
3949

50+
These builders are running on a special pool of builders set up and maintained for us by GitHub.
51+
4052
[platforms]: https://doc.rust-lang.org/nightly/rustc/platform-support.html
4153
[rustup-toolchain-install-master]: https://github.com/kennytm/rustup-toolchain-install-master
54+
[Docker container]: https://github.com/rust-lang/rust/tree/master/src/ci/docker
4255
[dist-x86_64-linux]: https://github.com/rust-lang/rust/blob/master/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
4356

4457
## Merging PRs serially with bors
@@ -63,25 +76,39 @@ Since the merge commit is based on the latest master and only one can be tested
6376
at the same time, when the results are green master is fast-forwarded to that
6477
merge commit.
6578

79+
The `auto` branch and other branches used by bors live on a fork of the rust-lang/rust: [rust-lang-ci/rust]. This as originally done to some security limitations in GitHub Actions. These limitations have been addressed, but we've not yet done the work of removing the use of a fork.
80+
6681
Unfortunately testing a single PR at the time, combined with our long CI (~3
67-
hours for a full run), means we can’t merge too many PRs in a single day, and a
82+
hours for a full run)[^1], means we can’t merge too many PRs in a single day, and a
6883
single failure greatly impacts our throughput for the day. The maximum number
6984
of PRs we can merge in a day is around 8.
7085

86+
The large CI run times and requirement for a large builder pool is worth it because it:
87+
* allows perf testing even at a later date
88+
* allows bisection when bugs are discover later
89+
* ensures release quality since if we're always releasing, we catch problems very early
90+
91+
Bors [runs on ecs](https://github.com/rust-lang/simpleinfra/blob/master/terraform/bors/app.tf) and uses a sqlite database running in a volume as storage.
92+
93+
[^1]: As of December 2022, the bottleneck are the macOS builders. Hopefully faster macOS builders will be coming soon!
94+
7195
[bors]: https://github.com/bors
7296
[homu]: https://github.com/rust-lang/homu
7397
[homu-queue]: https://bors.rust-lang.org/queue/rust
98+
[rust-lang-ci/rust]: https://github.com/rust-lang-ci/rust
7499

75100
### Rollups
76101

77102
Some PRs don’t need the full test suite to be executed: trivial changes like
78103
typo fixes or README improvements *shouldn’t* break the build, and testing
79104
every single one of them for 2 to 3 hours is a big waste of time. To solve this
80105
we do a "rollup", a PR where we merge all the trivial PRs so they can be tested
81-
together. Rollups are created manually by a team member who uses their
82-
judgement to decide if a PR is risky or not, and are the best tool we have at
106+
together. Rollups are created manually by a team member using the "create a rollup" button on the [bors queue]. The team member uses their
107+
judgment to decide if a PR is risky or not, and are the best tool we have at
83108
the moment to keep the queue in a manageable state.
84109

110+
[bors queue]: https://bors.rust-lang.org/queue/rust
111+
85112
### Try builds
86113

87114
Sometimes we need a working compiler build before approving a PR, usually for
@@ -91,6 +118,8 @@ a separate branch (`try`), and they basically work the same as normal builds,
91118
without the actual merge at the end. Any number of try builds can happen at the
92119
same time, even if there is a normal PR in progress.
93120

121+
You can see the CI configuration for try builds [here](https://github.com/rust-lang/rust/blob/9d46c7a3e69966782e163877151c1f0cea8b630a/src/ci/github-actions/ci.yml#L728-L741).
122+
94123
[perf]: https://perf.rust-lang.org
95124
[crater]: https://github.com/rust-lang/crater
96125

@@ -179,8 +208,8 @@ automatically, posting it on the PR.
179208
The bot is not hardcoded to look for error strings, but was trained with a
180209
bunch of build failures to recognize which lines are common between builds and
181210
which are not. While the generated snippets can be weird sometimes, the bot is
182-
pretty good at identifying the relevant lines even if it’s an error we never
183-
saw before.
211+
pretty good at identifying the relevant lines even if it’s an error we've never
212+
seen before.
184213

185214
[rla]: https://github.com/rust-lang/rust-log-analyzer
186215

@@ -206,5 +235,18 @@ few days before we promote nightly to beta.
206235

207236
More information is available in the [toolstate documentation].
208237

238+
### GitHub Actions Templating
239+
240+
GitHub Actions does not natively support templating which can cause configurations to be large and difficult to change. We use YAML anchors for templating and a custom tool, [`expand-yaml-anchors`], to expand [the template] into the CI configuration that [GitHub uses][ci config].
241+
242+
This templating language is fairly straightforward:
243+
244+
* `&` indicates a template section
245+
* `*` expands the indicated template in place
246+
* `<<` merges yaml dictionaries
247+
209248
[rust-toolstate]: https://rust-lang-nursery.github.io/rust-toolstate
210249
[toolstate documentation]: ../toolstate.md
250+
[`expand-yaml-anchors`]: https://github.com/rust-lang/rust/tree/master/src/tools/expand-yaml-anchors
251+
[the template]: https://github.com/rust-lang/rust/blob/736c675d2ab65bcde6554e1b73340c2dbc27c85a/src/ci/github-actions/ci.yml
252+
[ci config]: https://github.com/rust-lang/rust/blob/master/.github/workflows/ci.yml

0 commit comments

Comments
 (0)