Skip to content

Commit 6a973cf

Browse files
committed
chore(ci): determine if it is a backport by listing branches
1 parent a085f16 commit 6a973cf

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

ci/which-channel.sh

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,34 @@ set -euo pipefail
1313
# so hope `HEAD~` to find the previous commit on master branch.
1414
base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}")
1515

16-
# Default to nightly channel
17-
CHANNEL="nightly"
18-
1916
# Get symbolic names for the base_sha.
20-
# We only care about `rust-1.y.z` branches
21-
ref=$(git name-rev --name-only --refs="origin/rust-1.*" $base_sha)
17+
# Assumption: Cargo branches are always in the format of `rust-1.*.0`,
18+
# otherwise `git name-rev` will return "undefined".
19+
ref=$(git name-rev --name-only --refs='origin/rust-1.*.0' $base_sha)
2220

23-
# Remove the patch version `.0` and keep only `1.y`,
24-
# so that rustup can install the correct patched toolchain
25-
if [[ "$ref" =~ ^origin/rust-(.*).0$ ]]
26-
then
27-
rustup update
28-
rustup toolchain install stable beta
29-
version="${BASH_REMATCH[1]}"
30-
beta="$(rustc +beta -V)"
31-
stable="$(rustc +stable -V)"
21+
# Get the latest `rust-1.*.0` branch from remote origin.
22+
# Assumption: The latest branch is always beta branch.
23+
beta=$(git branch --remotes --list 'origin/rust-1.*.0' | sort | tail -n1 | tr -d "[:space:]")
3224

33-
if [[ "$beta" == "rustc ${version}"* ]]
34-
then
35-
CHANNEL="beta"
36-
fi
25+
master=$(git rev-parse origin/master)
3726

38-
if [[ "$stable" = "rustc ${version}"* ]]
27+
# Backport pull requests always target at a `rust-1.*.0` branch.
28+
if [[ "$ref" = "undefined" ]] || [[ "$base_sha" = "$master" ]]
29+
then
30+
channel="nightly"
31+
else
32+
if [[ "$ref" = "$beta" ]]
3933
then
40-
CHANNEL="stable"
34+
channel="beta"
35+
else
36+
channel="stable"
4137
fi
4238
fi
4339

44-
echo "Base sha: $base_sha"
45-
echo "Possible ref: $ref"
46-
echo "Channel: $CHANNEL"
40+
echo "Base sha: $base_sha"
41+
echo "Git Ref: $ref"
42+
echo "master: $master"
43+
echo "beta: $beta"
44+
echo "Channel: $channel"
4745

48-
echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT"
46+
echo "CHANNEL=$channel" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)