@@ -14,15 +14,15 @@ set -eux
14
14
# is the beginning of a new release series.
15
15
16
16
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
19
19
fi
20
20
21
21
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
24
24
else
25
- output_file=" $1 "
25
+ output_file=" $1 "
26
26
fi
27
27
28
28
# Split on the dots
@@ -31,41 +31,50 @@ major=${version_array[0]}
31
31
minor=${version_array[1]}
32
32
patch=${version_array[2]}
33
33
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
36
36
fi
37
37
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
42
42
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
47
47
fi
48
48
49
49
if [[ " ${DRY_RUN} " == " true" ]]; then
50
- branch_name=" ${branch_name} -preview"
50
+ branch_name=" ${branch_name} -preview"
51
51
fi
52
52
echo " release_branch=${branch_name} " > " ${output_file} "
53
53
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} "
70
73
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"
71
80
fi
0 commit comments