-
Notifications
You must be signed in to change notification settings - Fork 11
/
release.sh
executable file
·49 lines (38 loc) · 1.09 KB
/
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
#!/bin/bash
set -euo pipefail
# read version + ensure non-empty
VERSION="$1"
[ -z "$VERSION" ] && echo "Error: No version specified" && exit 1
# ensure work tree is clean (aside from CHANGELOG.md)
if [[ ! $(git status --porcelain | grep -vc "CHANGELOG.md") -eq 0 ]]; then
echo "Error: Uncommitted changes in work tree"
exit 1
fi
# ensure we're on default branch
if [[ ! "$(git branch --show-current)" =~ ^(main|master)$ ]]; then
echo "Error: Not on default branch"
exit 1
fi
# ensure the changelog is up-to-date
if ! (grep -q "$VERSION" CHANGELOG.md)
then
echo "Error: CHANGELOG.md is not up to date"
exit 1
fi
# confirm
read -r -p "Bump version from $(poetry version --short) to $VERSION. Are you sure? [y/n] " response
response=${response,,} # tolower
if [[ ! "$response" =~ ^(yes|y)$ ]]; then
exit 1
fi
# checks done, now publish the release...
# bump version
poetry version "$VERSION"
# commit
git add pyproject.toml
git add CHANGELOG.md
git commit -m "version $VERSION"
# tag
git tag "$VERSION"
# push to GitHub
git push origin "$(git branch --show-current)" --tags