This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
/
release.sh
executable file
·157 lines (123 loc) · 3.98 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#
# This tiny script helps me not to mess up the procedure of releasing a new
# version of cordless.
#
# Build dependencies:
# * sha256sum
# * envsubst
# * git
# * date
# * go
#
# While this script runs on Linux, it creates binaries for Linux, Windows and
# MacOS. On top of that, new manifests for brew and scoop are created.
# The binaries get pushed into a new GitHub release, using the previous commits
# as the tag message. The scoop and brew manifests have to be uplaod manually.
#
#
# This will cause a script failure in case any of the commands below fail.
#
set -e
#
# RELEASE_DATE is the current date in format Year-Month-Day, since cordless
# uses dates for versioning.
#
RELEASE_DATE="$(date +%Y-%m-%d)"
export RELEASE_DATE
#
# Setting the cordless version-number to the current release date.
# This number can be requested on startup and is only used for that purpose.
#
# This has to happen before building, since version numbers are incorrect otherwise.
#
envsubst < version.go_template > version/version.go
git commit version/version.go -m "Bump cordless versionnumber to version $RELEASE_DATE"
#
# Define executable names for later usage.
#
BIN_LINUX="cordless_linux_64"
BIN_DARWIN="cordless_darwin"
BIN_WINDOWS_64="cordless_64.exe"
BIN_WINDOWS_32="cordless_32.exe"
#
# Building cordless for darwin, linux and windows.
#
# The binaries are built without debug symbols in order to save filesize.
#
GOOS=linux go build -o $BIN_LINUX -ldflags="-s -w"
GOOS=darwin go build -o $BIN_DARWIN -ldflags="-s -w"
GOOS=windows go build -o $BIN_WINDOWS_64 -ldflags="-s -w"
GOOS=windows GOARCH=386 go build -o $BIN_WINDOWS_32 -ldflags="-s -w"
#
# EXE_HASH is sha256 of the previously built cordless.exe and is required
# for scoop to properly work.
#
# Since envsubst can not see the unexported variables, we export them here
# and unexport them at a later point and time.
#
EXE_64_HASH="$(sha256sum ./$BIN_WINDOWS_64 | cut -f 1 -d " ")"
export EXE_64_HASH
EXE_32_HASH="$(sha256sum ./$BIN_WINDOWS_32 | cut -f 1 -d " ")"
export EXE_32_HASH
#
# Substituting the variables in the scoop manifest template into the actual
# manifest.
#
envsubst < cordless.json_template > cordless.json
#
# Create a new tag and push it.
#
git tag -s "$RELEASE_DATE"
#
# Copies the changelog for pasting into the github release. The changes will
# include all commits between the latest and the previous tag.
#
RELEASE_BODY="$(git log --pretty=oneline --abbrev-commit "$(git describe --abbrev=0 "$(git describe --abbrev=0)"^)".."$(git describe --abbrev=0)")"
#
# Push both previously created commits and the tag.
# We push as late as possible, to avoid pushing with
# errors happening afterwards.
#
git push --follow-tags
#
# Temporarily disable that the script exists on subcommand failure.
#
set +e
#
# Look up the release to create and save whether the lookup was successful.
# This has to be manually saved due to the fact that the next `set -e` would
# reset the `$?` variable.
#
hub release show "$RELEASE_DATE"
RELEASE_EXISTS=$?
#
# Let script exit again on subcommand failure.
#
set -e
#
# If the release already exists, we edit the existing one instead of creating a
# new one.
#
if [ $RELEASE_EXISTS -eq 0 ]
then
hub release edit -a "$BIN_LINUX" -a "$BIN_DARWIN" -a "$BIN_WINDOWS_64" -a "$BIN_WINDOWS_32" -m "" -m "${RELEASE_BODY}" "$RELEASE_DATE"
else
hub release create -a "$BIN_LINUX" -a "$BIN_DARWIN" -a "$BIN_WINDOWS_64" -a "$BIN_WINDOWS_32" -m "${RELEASE_DATE}" -m "${RELEASE_BODY}" "$RELEASE_DATE"
fi
#
# Substitutes the manifest template for the homebrew package. We need to
# download the latest tarball in order to get its sha256 sum.
#
wget https://github.com/Bios-Marcel/cordless/archive/$RELEASE_DATE.tar.gz
TAR_HASH="$(sha256sum ./$RELEASE_DATE.tar.gz | cut -f 1 -d " ")"
export TAR_HASH
rm ./$RELEASE_DATE.tar.gz
envsubst < cordless.rb_template > cordless.rb
#
# Unsetting (and unexporting) previously exported environment variables.
#
unset RELEASE_DATE
unset EXE_64_HASH
unset EXE_32_HASH
unset TAR_HASH