-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRELEASE.sh
More file actions
executable file
·119 lines (102 loc) · 3.38 KB
/
Copy pathRELEASE.sh
File metadata and controls
executable file
·119 lines (102 loc) · 3.38 KB
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
#!/bin/bash
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION_FILE="${PROJECT_ROOT}/VERSION"
DATE_PREFIX="$(date '+%y.%m.%d')"
BIN_DIR="${PROJECT_ROOT}/bin"
HYPERCTL_BIN="${BIN_DIR}/hyperctl"
usage() {
cat <<USAGE
Usage: ./RELEASE [--set VERSION] [--no-git]
Without arguments, bumps VERSION to the next YY.MM.DD.B value (B increments
within the same day, starting at 0). With --set, writes the provided version
verbatim. Unless --no-git is supplied, the script commits, tags, and pushes the
new version with name v<version>.
USAGE
}
trim() {
local value="$1"
value="${value//$'\r'/}"
value="${value## }"
value="${value%% }"
printf '%s' "$value"
}
MANUAL_VERSION=""
GIT_PUSH=1
while [[ $# -gt 0 ]]; do
case "$1" in
--set)
if [[ $# -lt 2 ]]; then
echo "missing value for --set" >&2
usage
exit 1
fi
MANUAL_VERSION="$(trim "$2")"
shift 2
;;
--no-git)
GIT_PUSH=0
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown argument: $1" >&2
usage
exit 1
;;
esac
done
if (( GIT_PUSH )); then
if [[ -n "$(git -C "${PROJECT_ROOT}" status --porcelain)" ]]; then
echo "git working tree must be clean before bumping version" >&2
exit 1
fi
fi
if [[ -n "${MANUAL_VERSION}" ]]; then
NEW_VERSION="${MANUAL_VERSION}"
else
NEXT_BUILD=0
if [[ -f "${VERSION_FILE}" ]]; then
CURRENT="$(trim "$(<"${VERSION_FILE}")")"
if [[ -n "${CURRENT}" ]]; then
IFS='.' read -r curYY curMM curDD curBuild <<< "${CURRENT}."
CURRENT_PREFIX="${curYY}.${curMM}.${curDD}"
if [[ "${CURRENT_PREFIX}" == "${DATE_PREFIX}" ]]; then
if [[ -n "${curBuild}" && ${curBuild} =~ ^[0-9]+$ ]]; then
NEXT_BUILD=$((curBuild + 1))
fi
fi
fi
fi
NEW_VERSION="${DATE_PREFIX}.${NEXT_BUILD}"
fi
echo "${NEW_VERSION}" > "${VERSION_FILE}"
printf 'VERSION updated to %s\n' "${NEW_VERSION}"
echo "Building hyperctl CLI binary..."
mkdir -p "${BIN_DIR}"
(cd "${PROJECT_ROOT}" && GOCACHE="${PROJECT_ROOT}/tmp/.gocache" go build -o "${HYPERCTL_BIN}" ./cmd/hyperctl)
printf 'hyperctl binary written to %s\n' "${HYPERCTL_BIN}"
if (( GIT_PUSH )); then
git -C "${PROJECT_ROOT}" add VERSION
git -C "${PROJECT_ROOT}" commit -m "release: ${NEW_VERSION}" >/dev/null
git -C "${PROJECT_ROOT}" tag -a "v${NEW_VERSION}" -m "Release ${NEW_VERSION}"
git -C "${PROJECT_ROOT}" push
git -C "${PROJECT_ROOT}" push origin "v${NEW_VERSION}"
printf 'Pushed commit and tag v%s\n' "${NEW_VERSION}"
if ! command -v gh >/dev/null 2>&1; then
echo "GitHub CLI (gh) is required to create releases. Install it or rerun with --no-git." >&2
exit 1
fi
RELEASE_NOTES_FILE="$(mktemp)"
trap 'rm -f "${RELEASE_NOTES_FILE}"' EXIT
git -C "${PROJECT_ROOT}" log -1 --pretty=format:%B > "${RELEASE_NOTES_FILE}"
gh release create "v${NEW_VERSION}" "${HYPERCTL_BIN}" \
--title "bumping to version ${NEW_VERSION}" \
--notes-file "${RELEASE_NOTES_FILE}"
rm -f "${RELEASE_NOTES_FILE}"
trap - EXIT
printf 'Created GitHub release v%s with hyperctl asset\n' "${NEW_VERSION}"
fi