-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease
executable file
·64 lines (54 loc) · 1.62 KB
/
release
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
#!/bin/sh
# This script is used to create a new release of the project.
#
# Requirements: github-cli, jq
print_help() {
echo "Usage: $0 [options]"
echo "Options:"
echo " -h, --help Print this help message"
echo " --patch Bump patch version"
echo " --minor Bump minor version"
echo " --major Bump major version"
}
bump_patch() {
echo "$1" | awk -F. '{print $1"."$2"."$3+1}'
}
bump_minor() {
echo "$1" | awk -F. '{print $1"."$2+1".0"}'
}
bump_major() {
echo "$1" | awk -F. '{print $1+1".0.0"}'
}
[ "$#" -eq 0 ] && print_help && exit 0
version_file_path="$(git ls-files | grep version.py)"
version="$(cat "$version_file_path" | awk -F= '{print $2}' | tr -d " '")"
latest_release="$(gh release view --json tagName | jq -r .tagName)"
for arg in "$@"; do
case "$arg" in
-h|--help)
print_help
exit 0
;;
--patch)
new_release="$(bump_patch "$latest_release")"
new_version="$(bump_patch "$version")"
;;
--minor)
new_release="$(bump_minor "$latest_release")"
new_version="$(bump_minor "$version")"
;;
--major)
new_release="$(bump_major "$latest_release")"
new_version="$(bump_major "$version")"
;;
*)
echo "Unknown option: $arg"
print_help
exit 1
;;
esac
done
echo "__version__ = '${new_version}'" > "$version_file_path"
git add . && git commit -m "Release ${new_version}" && git push origin main
gh release create --generate-notes "$new_release"
exit 0