-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: detect the channel a PR wants to merge into
- Loading branch information
Showing
2 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
# This script outputs the channel where a CI workflow wants to merge into. | ||
# | ||
# Inputs: | ||
# BASE_SHA The commit SHA of the branch where the PR wants to merge into. | ||
# | ||
# GitHub Action Outputs: | ||
# CHANNEL Target channel where the PR wants to merge into. | ||
|
||
set -euo pipefail | ||
|
||
# When `BASE_SHA` is missing, we assume it is from bors merge commit, | ||
# so hope `HEAD~` to find the previous commit on master branch. | ||
base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}") | ||
|
||
# Default to nightly channel | ||
CHANNEL="nightly" | ||
|
||
# Get symbolic names for the base_sha. | ||
# We only care about `rust-1.y.z` branches | ||
ref=$(git name-rev --name-only --refs="origin/rust-1.*" $base_sha) | ||
|
||
# Remove the patch version `.0` and keep only `1.y`, | ||
# so that rustup can install the correct patched toolchain | ||
if [[ "$ref" =~ ^origin/rust-(.*).0$ ]] | ||
then | ||
rustup update | ||
rustup toolchain install stable beta | ||
version="${BASH_REMATCH[1]}" | ||
beta="$(rustc +beta -V)" | ||
stable="$(rustc +stable -V)" | ||
|
||
if [[ "$beta" == "rustc ${version}"* ]] | ||
then | ||
CHANNEL="beta" | ||
fi | ||
|
||
if [[ "$stable" = "rustc ${version}"* ]] | ||
then | ||
CHANNEL="stable" | ||
fi | ||
fi | ||
|
||
echo "Base sha: $base_sha" | ||
echo "Possible ref: $ref" | ||
echo "Channel: $CHANNEL" | ||
|
||
echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT" |