Skip to content

Commit cc303ab

Browse files
authored
fix Publisher Workflow to successfully create new branches (#3117)
The publisher tool was unable to create new branches because it attempted to determine if the current commit was on main. However, this didn't work! Since main was never checked out (ever) in the repo, there was no ref to look for. This fixes the issue in (perhaps not the best) way by simply checking out main first. The logic was also refactored to have dry run and non-dry run behave in a way that is closer to identical. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 7a30766 commit cc303ab

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

.github/scripts/get-or-create-release-branch.sh

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ set -eux
1414
# is the beginning of a new release series.
1515

1616
if [ -z "$SEMANTIC_VERSION" ]; then
17-
echo "'SEMANTIC_VERSION' must be populated."
18-
exit 1
17+
echo "'SEMANTIC_VERSION' must be populated."
18+
exit 1
1919
fi
2020

2121
if [ -z "$1" ]; then
22-
echo "You need to specify the path of the file where you want to collect the output"
23-
exit 1
22+
echo "You need to specify the path of the file where you want to collect the output"
23+
exit 1
2424
else
25-
output_file="$1"
25+
output_file="$1"
2626
fi
2727

2828
# Split on the dots
@@ -31,41 +31,50 @@ major=${version_array[0]}
3131
minor=${version_array[1]}
3232
patch=${version_array[2]}
3333
if [[ "${major}" == "" || "${minor}" == "" || "${patch}" == "" ]]; then
34-
echo "'${SEMANTIC_VERSION}' is not a valid semver tag"
35-
exit 1
34+
echo "'${SEMANTIC_VERSION}' is not a valid semver tag"
35+
exit 1
3636
fi
3737
if [[ $major == 0 ]]; then
38-
branch_name="smithy-rs-release-${major}.${minor}.x"
39-
if [[ $patch == 0 ]]; then
40-
echo "new_release_series=true" >"${output_file}"
41-
fi
38+
branch_name="smithy-rs-release-${major}.${minor}.x"
39+
if [[ $patch == 0 ]]; then
40+
echo "new_release_series=true" >"${output_file}"
41+
fi
4242
else
43-
branch_name="smithy-rs-release-${major}.x.y"
44-
if [[ $minor == 0 && $patch == 0 ]]; then
45-
echo "new_release_series=true" >"${output_file}"
46-
fi
43+
branch_name="smithy-rs-release-${major}.x.y"
44+
if [[ $minor == 0 && $patch == 0 ]]; then
45+
echo "new_release_series=true" >"${output_file}"
46+
fi
4747
fi
4848

4949
if [[ "${DRY_RUN}" == "true" ]]; then
50-
branch_name="${branch_name}-preview"
50+
branch_name="${branch_name}-preview"
5151
fi
5252
echo "release_branch=${branch_name}" >"${output_file}"
5353

54-
if [[ "${DRY_RUN}" == "true" ]]; then
55-
git push --force origin "HEAD:refs/heads/${branch_name}"
56-
else
57-
commit_sha=$(git rev-parse --short HEAD)
58-
if ! git ls-remote --exit-code --heads origin "${branch_name}"; then
59-
# The release branch does not exist.
60-
# We need to make sure that the commit SHA that we are releasing is on `main`.
61-
git fetch origin main
62-
if git branch --contains "${commit_sha}" | grep main; then
63-
# We can then create the release branch and set the current commit as its tip
64-
git checkout -b "${branch_name}"
65-
git push origin "${branch_name}"
66-
else
67-
echo "You must choose a commit from main to create a new release branch!"
68-
exit 1
69-
fi
54+
commit_sha=$(git rev-parse --short HEAD)
55+
# the git repo is in a weird state because **main has never been checked out**!
56+
# This prevents the `git branch --contains` from working because there is no _local_ ref for main
57+
git checkout main
58+
git checkout "${commit_sha}"
59+
if ! git ls-remote --exit-code --heads origin "${branch_name}"; then
60+
# The release branch does not exist.
61+
# We need to make sure that the commit SHA that we are releasing is on `main`.
62+
git fetch origin main
63+
echo "Branches: "
64+
git branch --contains "${commit_sha}"
65+
git show origin/main | head -n 1
66+
if git branch --contains "${commit_sha}" | grep main; then
67+
# We can then create the release branch and set the current commit as its tip
68+
if [[ "${DRY_RUN}" == "true" ]]; then
69+
git push --force origin "HEAD:refs/heads/${branch_name}"
70+
else
71+
git checkout -b "${branch_name}"
72+
git push origin "${branch_name}"
7073
fi
74+
else
75+
echo "You must choose a commit from main to create a new release branch!"
76+
exit 1
77+
fi
78+
else
79+
echo "Patch release ${branch_name} already exists"
7180
fi

0 commit comments

Comments
 (0)