-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_new_gh_release.sh
90 lines (82 loc) · 2.28 KB
/
create_new_gh_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
#!/bin/bash
#
# Calculates new semantic veresion (e.g. v1.0.1) tag, builds Go Lang binary for release,
# generates release notes based on git commits, then creates new Github Release
#
# check for Go Lang compiler and Github CLI binaries
go_bin=$(which go)
[ -n "$go_bin" ] || {
echo "ERROR GoLang binary not available, install it using Reading package lists...
Building dependency tree...
Reading state information..."
exit 2
}
gh_bin=$(which gh)
[ -n "$gh_bin" ] || {
echo "ERROR Github CLI binary not available, https://github.com/cli/cli/blob/trunk/docs/install_linux.md"
exit 2
}
#
# CALCULATE NEW SEMANTIC TAG (vX.Y.Z)
#
if git tag --sort=committerdate | grep -q ^r; then
# get latest semantic version tag, construct patch+1
semantic_version=$(git tag --sort=-committerdate | grep ^r | grep -Po '^r[0-9]*.[0-9]*.[0-9]*' | head -n1)
[ -n "$semantic_version" ] || {
echo "ERROR could not find semantic version rX.Y.Z"
exit 3
}
major_minor=$(echo "" | cut -d'.' -f1-2)
patch=$semantic_version
((patch++))
newtag="${major_minor}.${patch}"
else
semantic_version=""
newtag="r1.0.0"
fi
echo "old version: $semantic_version new_version: ${newtag}"
#
# GOLANG BUILD OF BINARY
#
CUR_DIR=${PWD##*/}
mkdir -p build
cp cmd/httpbench/main.go build/main.go
cd build
[ -f go.mod ] || go mod init rnemeth90/$CUR_DIR
go mod tidy
set -x
go build -o httpbench -ldflags "-X main.Version=$newtag -X main.BuiltBy=bash" main.go
set +x
cd ..
echo "GoLang binary built as build/main"
#
# GENERATE RELEASE NOTES FROM GIT COMMITS
#
if [ -n "$semantic_version" ]; then
git log HEAD...${semantic_version} --pretty="- %s " >/tmp/$newtag.log
[ $? -eq 0 ] || {
echo "ERROR could not retrieve logs for 'git log HEAD...${semantic_version}"
exit 7
}
else
git log --pretty="- %s " >/tmp/$newtag.log
fi
#
# PUSH, COMMIT NEW TAG, CREATE RELEASE
#
echo ""
echo "== RELEASE $newtag =================================="
cat /tmp/$newtag.log
echo "===================================="
echo ""
read -p "Push this new release $newtag [y/n]? " -i y -e answer
if [[ "$answer" == "y" ]]; then
set -x
git commit -a -m "changes for new tag $newtag"
git tag $newtag && git push origin $newtag
git push
gh release create $newtag -F /tmp/$newtag.log build/main.go
set +x
else
echo "aborted release creation"
fi