-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·82 lines (66 loc) · 1.56 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
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
#!/usr/bin/env bash
## Stop on errors:
set -eo pipefail
## Helper function to print log messages.
_log() {
echo "[RELEASE LOG]" "${@}"
}
## Helper function to print errors.
_error() {
echo 1>&2 "[RELEASE ERROR]" "${@}"
}
## Helper function to print usage.
_usage() {
echo "Usage: $0 [-h] -n <VERSION>"
}
## Declare variables:
_version=""
_appname="teloshost"
## Parse command line arguments:
while getopts "n:h" o; do
case "${o}" in
n)
_version="${OPTARG}"
;;
h)
_usage
exit 0
;;
*)
_usage 1>&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
_log "Checking variables..."
if [ -z "${_version}" ]; then
_usage 1>&2
exit 1
else
_log "Version is \"${_version}\". Proceeding..."
_log "Application name is \"${_appname}\". Proceeding..."
fi
_log "Checking git repository state..."
if [[ -z "$(git status --porcelain)" ]]; then
_log "Git repository is clean. Proceeding..."
else
_error "Git repository is not clean. Aborting..."
exit 1
fi
_log "Updating application version..."
sed -i -E "s/^version:([ ]+).*/version:\\1${_version}/g" version
hpack
_log "Generating changelog..."
git-chglog --output CHANGELOG.md --next-tag "${_version}"
_log "Staging changes..."
git add version CHANGELOG.md
_log "Committing changes..."
git commit -m "chore(release): ${_version}"
_log "Tagging version..."
git tag -a -m "Release ${_version}" "${_version}"
_log "Pushing changes to remote..."
git push --follow-tags origin main
_log "Creating the release..."
gh release create "${_version}" --title "v${_version}" --generate-notes
_log "Finished!"