Skip to content

Commit

Permalink
chore(ci): determine if it is a backport by listing branches
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed May 25, 2023
1 parent a085f16 commit 6a973cf
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions ci/which-channel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,34 @@ set -euo pipefail
# 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)
# Assumption: Cargo branches are always in the format of `rust-1.*.0`,
# otherwise `git name-rev` will return "undefined".
ref=$(git name-rev --name-only --refs='origin/rust-1.*.0' $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)"
# Get the latest `rust-1.*.0` branch from remote origin.
# Assumption: The latest branch is always beta branch.
beta=$(git branch --remotes --list 'origin/rust-1.*.0' | sort | tail -n1 | tr -d "[:space:]")

if [[ "$beta" == "rustc ${version}"* ]]
then
CHANNEL="beta"
fi
master=$(git rev-parse origin/master)

if [[ "$stable" = "rustc ${version}"* ]]
# Backport pull requests always target at a `rust-1.*.0` branch.
if [[ "$ref" = "undefined" ]] || [[ "$base_sha" = "$master" ]]
then
channel="nightly"
else
if [[ "$ref" = "$beta" ]]
then
CHANNEL="stable"
channel="beta"
else
channel="stable"
fi
fi

echo "Base sha: $base_sha"
echo "Possible ref: $ref"
echo "Channel: $CHANNEL"
echo "Base sha: $base_sha"
echo "Git Ref: $ref"
echo "master: $master"
echo "beta: $beta"
echo "Channel: $channel"

echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT"
echo "CHANNEL=$channel" >> "$GITHUB_OUTPUT"

0 comments on commit 6a973cf

Please sign in to comment.