forked from Bios-Marcel/cordless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·167 lines (130 loc) · 3.85 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
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
#
# This tiny script helps me not to mess up the procedure of releasing a new
# version of cordless.
#
# Dependencies:
# * sha256sum
# * envsubst
# * snapcraft
# * git
# * date
# * go
# * xclip
#
#
# 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 versionnumber 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="cordless.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 -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_HASH="$(sha256sum ./$BIN_WINDOWS | cut -f 1 -d " ")"
export EXE_HASH
#
# Substituting the variables in the scoop manifest tempalte into the actual
# manifest.
#
envsubst < cordless.json_template > cordless.json
#
# Commit and push the new scoop manifest.
#
git commit cordless.json -m "Bump scoop package to version $RELEASE_DATE"
git push
#
# Create a new tag and push it.
#
git tag -s "$RELEASE_DATE" -m "Update scoop package to version ${RELEASE_DATE}"
git push --tags
#
# Build and push the snap package.
#
# It is important that this happens after pusing the tag, because otherwise
# the version of the built snap package will end up being `DATE_dirty`.
#
snapcraft clean cordless
snapcraft
snapcraft push "cordless_${RELEASE_DATE}_amd64.snap"
#
# 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)")"
#
# Temprarily 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" -m "" -m "${RELEASE_BODY}" "$RELEASE_DATE"
else
hub release create -a "$BIN_LINUX" -a "$BIN_DARWIN" -a "$BIN_WINDOWS" -m "${RELEASE_DATE}" -m "${RELEASE_BODY}" "$RELEASE_DATE"
fi
#
# Substitutes the manifest template for the homebrew package. We need to
# download the latets 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_HASH
unset TAR_HASH
#
# Cleanup snap stuff so I can still run unit tests for cordless only.
#
rm -rf stage/
rm -rf parts/
rm -rf prime/