Skip to content

Commit 251f946

Browse files
authored
[ci] Roll pinned nightly toolchain automatically (#408)
1 parent 9041ec1 commit 251f946

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Once a day, attempt to roll the pinned nightly and stable toolchain versions
2+
# and update the codebase as necessary (in particular, by regenerating the files
3+
# which store expected compiler output for UI tests; this output is not stable
4+
# and may change between compiler versions). On success, submit the changes as a
5+
# new PR. Note that this does not guarantee that the roll will succeed: PRs go
6+
# through many tests which are not exercised here, and so the generated PR may
7+
# still fail CI. In particular, some nightly releases do not support all of the
8+
# target architectures that we use in CI; attempting to roll to any such release
9+
# will fail.
10+
11+
name: Roll pinned toolchain versions
12+
on:
13+
schedule:
14+
- cron: '29 12 * * *'
15+
16+
permissions: read-all
17+
18+
jobs:
19+
roll:
20+
name: Roll pinned toolchain versions
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
25+
with:
26+
ref: main
27+
persist-credentials: false
28+
- name: Calculate target nightly version
29+
# Use yesterday's date (`-d '-1 day'`) so we're sure the nightly for that
30+
# date has actually been published yet. This allows us to not worry
31+
# about what time of day this job runs.
32+
run: echo "ZC_TARGET_NIGHTLY=nightly-$(date -d '-1 day' +%Y-%m-%d)" >> $GITHUB_ENV
33+
- name: Install Rust with ${{ env.ZC_TARGET_NIGHTLY }} toolchain
34+
uses: dtolnay/rust-toolchain@00b49be78f40fba4e87296b2ead62868750bdd83 # stable
35+
with:
36+
toolchain: ${{ env.ZC_TARGET_NIGHTLY }}
37+
# Install whatever the latest stable release is. This has the side
38+
# effect of determining the latest stable release so that we can update
39+
# `Cargo.toml`.
40+
- name: Install Rust with stable toolchain
41+
uses: dtolnay/rust-toolchain@00b49be78f40fba4e87296b2ead62868750bdd83 # stable
42+
with:
43+
toolchain: stable
44+
- name: Update files
45+
run: |
46+
set -eo pipefail
47+
48+
function validate-file {
49+
REGEX="$1"
50+
FILE="$2"
51+
grep "$REGEX" "$FILE" >/dev/null || { echo "Failed to find line matching regex '$REGEX' in $FILE" >&2; exit 1; }
52+
}
53+
54+
function update-pinned-version {
55+
VERSION_NAME="$1"
56+
VERSION="$2"
57+
# For nightly, this is the same as `$VERSION`. For stable, it's
58+
# `stable` because `rustup` doesn't recognize that `x.y.z` refers to
59+
# the same thing as `stable` even if they're the same toolchain.
60+
VERSION_FOR_CARGO="$3"
61+
ZEROCOPY_FEATURES="$4"
62+
63+
# Confirm that `Cargo.toml` lists the pinned version in the expected
64+
# format. This is a prerequisite for the subsequent `sed` command.
65+
REGEX="^pinned-$VERSION_NAME = \"[a-z0-9\.-]*\"$"
66+
validate-file "$REGEX" Cargo.toml
67+
sed -i -e "s/$REGEX/pinned-$VERSION_NAME = \"$VERSION\"/" Cargo.toml
68+
69+
# Confirm that the update didn't bork `Cargo.toml`.
70+
validate-file "$REGEX" Cargo.toml
71+
72+
# Update `.stderr` files as needed for the new version.
73+
TRYBUILD=overwrite cargo "+$VERSION_FOR_CARGO" test --package zerocopy $ZEROCOPY_FEATURES
74+
TRYBUILD=overwrite cargo "+$VERSION_FOR_CARGO" test --package zerocopy-derive
75+
}
76+
77+
STABLE_VERSION="$(cargo +stable version | sed -e 's/^cargo \([0-9\.]*\) .*/\1/')"
78+
update-pinned-version stable "$STABLE_VERSION" stable '--features __internal_use_only_features_that_work_on_stable'
79+
update-pinned-version nightly "$ZC_TARGET_NIGHTLY" "$ZC_TARGET_NIGHTLY" --all-features
80+
81+
# Used as part of the branch name created by the "Submit PR" step.
82+
echo "ZC_TARGET_STABLE=$STABLE_VERSION" >> $GITHUB_ENV
83+
84+
- name: Submit PR
85+
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
86+
with:
87+
commit-message: "[ci] Roll pinned toolchains"
88+
author: Google PR Creation Bot <github-pull-request-creation-bot@google.com>
89+
committer: Google PR Creation Bot <github-pull-request-creation-bot@google.com>
90+
title: "[ci] Roll pinned toolchains"
91+
branch: roll-pinned-toolchain-to-${{ env.ZC_TARGET_STABLE }}-and-${{ env.ZC_TARGET_NIGHTLY }}
92+
push-to-fork: google-pr-creation-bot/zerocopy
93+
token: ${{ secrets.GOOGLE_PR_CREATION_BOT_TOKEN }}

0 commit comments

Comments
 (0)