-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_release.sh
executable file
·110 lines (92 loc) · 3.37 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
#!/bin/bash
# fail on error
set -e
# confirm the supplied version bump is valid
version_bump=$1
case $version_bump in
"patch" | "minor" | "major" | "prepatch" | "preminor" | "premajor" | "prerelease")
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
echo "#######################################"
echo "# bump version #"
echo "#######################################"
poetry version $version_bump
new_version=$(poetry version -s)
echo "#######################################"
echo "# do new build #"
echo "#######################################"
poetry build
echo ""
echo "#######################################"
echo "# publish package #"
echo "#######################################"
# to use this, set up an API token with
# `poetry config pypi-token.pypi <api token>`
poetry publish
echo "#######################################"
echo "# create new branch #"
echo "#######################################"
branch_name=release-$new_version
git checkout -b $branch_name
echo "#######################################"
echo "# commit version change #"
echo "#######################################"
git add pyproject.toml
git commit -m "Bump version"
echo "#######################################"
echo "# new tag: $new_tag #"
echo "#######################################"
new_tag=v${new_version}
git tag $new_tag
echo "#######################################"
echo "# bump prerelease version #"
echo "#######################################"
poetry version prerelease
echo "#######################################"
echo "# commit version change #"
echo "#######################################"
git add pyproject.toml
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 "__Do not use squash merge!__" --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