Skip to content

Commit

Permalink
Auto merge of #84997 - pietroalbini:ci-verify-channel, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed May 15, 2021
2 parents 1025db8 + a8da333 commit 428636f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ jobs:
- name: decide whether to skip this job
run: src/ci/scripts/should-skip-this.sh
if: success() && !env.SKIP_JOB
- name: ensure the channel matches the target branch
run: src/ci/scripts/verify-channel.sh
if: success() && !env.SKIP_JOB
- name: configure GitHub Actions to kill the build when outdated
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand Down Expand Up @@ -434,6 +437,9 @@ jobs:
- name: decide whether to skip this job
run: src/ci/scripts/should-skip-this.sh
if: success() && !env.SKIP_JOB
- name: ensure the channel matches the target branch
run: src/ci/scripts/verify-channel.sh
if: success() && !env.SKIP_JOB
- name: configure GitHub Actions to kill the build when outdated
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand Down Expand Up @@ -541,6 +547,9 @@ jobs:
- name: decide whether to skip this job
run: src/ci/scripts/should-skip-this.sh
if: success() && !env.SKIP_JOB
- name: ensure the channel matches the target branch
run: src/ci/scripts/verify-channel.sh
if: success() && !env.SKIP_JOB
- name: configure GitHub Actions to kill the build when outdated
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand Down
1 change: 1 addition & 0 deletions src/ci/channel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
4 changes: 4 additions & 0 deletions src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ x--expand-yaml-anchors--remove:
run: src/ci/scripts/should-skip-this.sh
<<: *step

- name: ensure the channel matches the target branch
run: src/ci/scripts/verify-channel.sh
<<: *step

- name: configure GitHub Actions to kill the build when outdated
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand Down
9 changes: 1 addition & 8 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,10 @@ if [ "$DIST_SRC" = "" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src"
fi

# If we're deploying artifacts then we set the release channel, otherwise if
# we're not deploying then we want to be sure to enable all assertions because
# we'll be running tests
#
# FIXME: need a scheme for changing this `nightly` value to `beta` and `stable`
# either automatically or manually.
export RUST_RELEASE_CHANNEL=nightly

# Always set the release channel for bootstrap; this is normally not important (i.e., only dist
# builds would seem to matter) but in practice bootstrap wants to know whether we're targeting
# master, beta, or stable with a build to determine whether to run some checks (notably toolstate).
export RUST_RELEASE_CHANNEL="$(cat "${ci_dir}/channel")"
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"

if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
Expand Down
38 changes: 38 additions & 0 deletions src/ci/scripts/verify-channel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# We want to make sure all PRs are targeting the right branch when they're
# opened, otherwise we risk (for example) to land a beta-specific change to the
# master branch. This script ensures the branch of the PR matches the channel.

set -euo pipefail
IFS=$'\n\t'

source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"

if isCiBranch auto || isCiBranch try; then
echo "channel verification is only executed on PR builds"
exit
fi

channel=$(cat "$(ciCheckoutPath)/src/ci/channel")
case "${channel}" in
nightly)
channel_branch="master"
;;
beta)
channel_branch="beta"
;;
stable)
channel_branch="stable"
;;
*)
echo "error: unknown channel defined in src/ci/channel: ${channel}"
exit 1
esac

branch="$(ciBaseBranch)"
if [[ "${branch}" != "${channel_branch}" ]]; then
echo "error: PRs changing the \`${channel}\` channel should be sent to the \
\`${channel_branch}\` branch!"

exit 1
fi
12 changes: 12 additions & 0 deletions src/ci/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ function isCiBranch {
fi
}

function ciBaseBranch {
if isAzurePipelines; then
echo "unsupported on Azure Pipelines"
exit 1
elif isGitHubActions; then
echo "${GITHUB_BASE_REF#refs/heads/}"
else
echo "ciBaseBranch only works inside CI!"
exit 1
fi
}

function ciCommit {
if isAzurePipelines; then
echo "${BUILD_SOURCEVERSION}"
Expand Down

0 comments on commit 428636f

Please sign in to comment.