-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_release.sh
executable file
·163 lines (137 loc) · 4.91 KB
/
make_release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Fail on error.
set -e
# Confirm the supplied version bump is valid.
version_bump=$1
case $version_bump in
"patch" | "minor" | "major")
echo "valid version bump: $version_bump"
;;
*)
echo "invalid version bump: \"$version_bump\""
echo "Usage:"
echo ""
echo " bash make_release.sh <version bump>"
echo ""
echo "List of valid version bumps: patch, minor, major, prepatch, preminor, premajor, prerelease"
exit 1
;;
esac
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
echo "The repository has uncommitted changes."
echo "This will lead to problems with git checkout."
exit 2
fi
if [ $(git symbolic-ref --short -q HEAD) != "main" ]; then
echo "not on main branch"
exit 3
fi
echo ""
echo "######################################"
echo "# ensure main branch is up-to-date #"
echo "######################################"
git pull
bump_build_publish() {
echo "#######################################"
echo "# entering '$1' #"
echo "#######################################"
pushd $1
echo "#######################################"
echo "# bump version #"
echo "#######################################"
# First remove the `.dev0` suffix.
if [[ $(rye version) == *.dev0 ]]; then
# This just removes all pre-release suffixes.
rye version --bump patch
else
echo "Invalid version suffix. Expected '.dev0'."
exit 4
fi
# If the version bump wasn't "patch", we need to apply the correct bump.
if [[ $version_bump != "patch" ]]; then
rye version --bump $version_bump
fi
echo "#######################################"
echo "# stage pyroject.toml #"
echo "#######################################"
git add pyproject.toml
echo "#######################################"
echo "# do new build #"
echo "#######################################"
rye build
echo ""
echo "#######################################"
echo "# publish package #"
echo "#######################################"
# to use this, set up an API token with
# `poetry config pypi-token.pypi <api token>`
rye publish
echo "#######################################"
echo "# leaving '$1' #"
echo "#######################################"
popd # Switch back to previous directory.
}
cp README.md ./type-enum/
bump_build_publish "type-enum"
rm ./type-enum/README.md
bump_build_publish "type-enum-plugin"
# Get the version from 'type_enum'.
pushd type-enum
new_version=$(rye version)
popd
echo "#######################################"
echo "# create new branch #"
echo "#######################################"
branch_name=release-$new_version
git checkout -b $branch_name
echo "#######################################"
echo "# commit version change #"
echo "#######################################"
git commit -m "Bump version"
echo "#######################################"
echo "# new tag: $new_tag #"
echo "#######################################"
new_tag=v${new_version}
git tag $new_tag
bump_to_prerelease() {
echo "#######################################"
echo "# entering '$1' #"
echo "#######################################"
pushd $1
echo "#######################################"
echo "# bump prerelease version #"
echo "#######################################"
rye version --bump patch
next_version=$(rye version)
rye version ${next_version}.dev0
echo "#######################################"
echo "# commit version change #"
echo "#######################################"
git add pyproject.toml
echo "#######################################"
echo "# leaving '$1' #"
echo "#######################################"
popd # switch back to previous directory
}
bump_to_prerelease "type-enum"
bump_to_prerelease "type-enum-plugin"
git commit -m "Bump version to prerelease"
echo "#######################################"
echo "# commit version change #"
echo "#######################################"
git push origin $branch_name $new_tag
echo "#######################################"
echo "# create PR for version bump #"
echo "#######################################"
gh pr create --title "Version bump $new_tag" --body "__Please do not squash merge this PR__ !" --base "main" --label version-bump
# the following command is allowed to fail; hence the "||:" at the end
gh pr merge $branch_name --merge --admin || :
echo "#######################################"
echo "# create release #"
echo "#######################################"
gh release create $new_tag --generate-notes
# clean up
echo "#######################################"
echo "# go back to main branch #"
echo "#######################################"
git checkout main