Skip to content

Commit 8cd9af3

Browse files
authored
Rollup merge of #84997 - pietroalbini:ci-verify-channel, r=Mark-Simulacrum
Error out if a PR is sent to the wrong channel It happened multiple times that a PR meant to go on beta ends up being opened (and occasionally merged) to master. This PR does two things: * Moves the definition of the channel in `src/ci/channel` so it's easier for tools to read it. I was not sure whether to move it to `src/channel` (like `src/version`): ended up with `src/ci` as it's currently only used for CI, but I'm open to moving it to `src`. We'll need to update the release process after this. * Adds a check on **non-bors** builds that errors out if the base branch is not the expected one for the currently defined channel. This will not cause problems for promotion PRs, as those PRs are meant to also update the channel name. r? ``@Mark-Simulacrum``
2 parents d7b06ae + 392723e commit 8cd9af3

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

.github/workflows/ci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
- name: decide whether to skip this job
7373
run: src/ci/scripts/should-skip-this.sh
7474
if: success() && !env.SKIP_JOB
75+
- name: ensure the channel matches the target branch
76+
run: src/ci/scripts/verify-channel.sh
77+
if: success() && !env.SKIP_JOB
7578
- name: configure GitHub Actions to kill the build when outdated
7679
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
7780
with:
@@ -434,6 +437,9 @@ jobs:
434437
- name: decide whether to skip this job
435438
run: src/ci/scripts/should-skip-this.sh
436439
if: success() && !env.SKIP_JOB
440+
- name: ensure the channel matches the target branch
441+
run: src/ci/scripts/verify-channel.sh
442+
if: success() && !env.SKIP_JOB
437443
- name: configure GitHub Actions to kill the build when outdated
438444
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
439445
with:
@@ -541,6 +547,9 @@ jobs:
541547
- name: decide whether to skip this job
542548
run: src/ci/scripts/should-skip-this.sh
543549
if: success() && !env.SKIP_JOB
550+
- name: ensure the channel matches the target branch
551+
run: src/ci/scripts/verify-channel.sh
552+
if: success() && !env.SKIP_JOB
544553
- name: configure GitHub Actions to kill the build when outdated
545554
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
546555
with:

src/ci/channel

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nightly

src/ci/github-actions/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ x--expand-yaml-anchors--remove:
126126
run: src/ci/scripts/should-skip-this.sh
127127
<<: *step
128128

129+
- name: ensure the channel matches the target branch
130+
run: src/ci/scripts/verify-channel.sh
131+
<<: *step
132+
129133
- name: configure GitHub Actions to kill the build when outdated
130134
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
131135
with:

src/ci/run.sh

+1-8
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,10 @@ if [ "$DIST_SRC" = "" ]; then
6262
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src"
6363
fi
6464

65-
# If we're deploying artifacts then we set the release channel, otherwise if
66-
# we're not deploying then we want to be sure to enable all assertions because
67-
# we'll be running tests
68-
#
69-
# FIXME: need a scheme for changing this `nightly` value to `beta` and `stable`
70-
# either automatically or manually.
71-
export RUST_RELEASE_CHANNEL=nightly
72-
7365
# Always set the release channel for bootstrap; this is normally not important (i.e., only dist
7466
# builds would seem to matter) but in practice bootstrap wants to know whether we're targeting
7567
# master, beta, or stable with a build to determine whether to run some checks (notably toolstate).
68+
export RUST_RELEASE_CHANNEL="$(cat "${ci_dir}/channel")"
7669
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
7770

7871
if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then

src/ci/scripts/verify-channel.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# We want to make sure all PRs are targeting the right branch when they're
3+
# opened, otherwise we risk (for example) to land a beta-specific change to the
4+
# master branch. This script ensures the branch of the PR matches the channel.
5+
6+
set -euo pipefail
7+
IFS=$'\n\t'
8+
9+
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10+
11+
declare -A CHANNEL_BRANCH
12+
CHANNEL_BRANCH["nightly"]="master"
13+
CHANNEL_BRANCH["beta"]="beta"
14+
CHANNEL_BRANCH["stable"]="stable"
15+
16+
if isCiBranch auto || isCiBranch try; then
17+
echo "channel verification is only executed on PR builds"
18+
exit
19+
fi
20+
21+
channel=$(cat "$(ciCheckoutPath)/src/ci/channel")
22+
branch="$(ciBaseBranch)"
23+
if [[ "${branch}" != "${CHANNEL_BRANCH[$channel]}" ]]; then
24+
echo "error: PRs changing the \`${channel}\` channel should be sent to the \
25+
\`${CHANNEL_BRANCH[$channel]}\` branch!"
26+
27+
exit 1
28+
fi

src/ci/shared.sh

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ function isCiBranch {
7373
fi
7474
}
7575

76+
function ciBaseBranch {
77+
if isAzurePipelines; then
78+
echo "unsupported on Azure Pipelines"
79+
exit 1
80+
elif isGitHubActions; then
81+
echo "${GITHUB_BASE_REF#refs/heads/}"
82+
else
83+
echo "ciBaseBranch only works inside CI!"
84+
exit 1
85+
fi
86+
}
87+
7688
function ciCommit {
7789
if isAzurePipelines; then
7890
echo "${BUILD_SOURCEVERSION}"

0 commit comments

Comments
 (0)