@@ -13,36 +13,34 @@ set -euo pipefail
13
13
# so hope `HEAD~` to find the previous commit on master branch.
14
14
base_sha=$( git rev-parse " ${BASE_SHA:- HEAD~1} " )
15
15
16
- # Default to nightly channel
17
- CHANNEL=" nightly"
18
-
19
16
# 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 )
22
20
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:]" )
32
24
33
- if [[ " $beta " == " rustc ${version} " * ]]
34
- then
35
- CHANNEL=" beta"
36
- fi
25
+ master=$( git rev-parse origin/master)
37
26
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 " ]]
39
33
then
40
- CHANNEL=" stable"
34
+ channel=" beta"
35
+ else
36
+ channel=" stable"
41
37
fi
42
38
fi
43
39
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 "
47
45
48
- echo " CHANNEL=$CHANNEL " >> " $GITHUB_OUTPUT "
46
+ echo " CHANNEL=$channel " >> " $GITHUB_OUTPUT "
0 commit comments