forked from gitbutlerapp/gitbutler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·302 lines (260 loc) · 7.68 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·302 lines (260 loc) · 7.68 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
PWD="$(dirname "$(readlink -f -- "$0")")"
CHANNEL=""
DO_SIGN="false"
VERSION=""
TARGET="${CARGO_BUILD_TARGET:-}"
function help() {
local to
to="$1"
echo "Usage: $0 <flags>" 1>&"$to"
echo 1>&"$to"
echo "flags:" 1>&"$to"
echo " --version release version." 1>&"$to"
echo " --dist path to store artifacts in." 1>&"$to"
echo " --sign if set, will sign the app." 1>&"$to"
echo " --channel the channel to use for the release (release | nightly)." 1>&"$to"
echo " --help display this message." 1>&"$to"
}
function error() {
echo "error: $*" 1>&2
echo 1>&2
help 2
exit 1
}
function info() {
echo "$@"
}
function os() {
local os
os="$(uname -s)"
case "$os" in
Darwin)
echo "macos"
;;
Linux)
echo "linux"
;;
Windows | MSYS* | MINGW*)
echo "windows"
;;
*)
error "$os: unsupported"
;;
esac
}
function arch() {
local arch
# If TARGET is specified, extract architecture from it
if [ -n "${TARGET:-}" ]; then
case "$TARGET" in
*aarch64* | *arm64*)
echo "aarch64"
return
;;
*x86_64* | *amd64*)
echo "x86_64"
return
;;
esac
fi
# Otherwise, detect from system
arch="$(uname -m)"
case "$arch" in
arm64 | aarch64)
echo "aarch64"
;;
x86_64)
echo "x86_64"
;;
*)
error "$arch: unsupported architecture"
;;
esac
}
ARCH="$(arch)"
OS="$(os)"
DIST="release"
# the OS is used for certain build decisions and signing
export OS
function tauri() {
(cd "$PWD/.." && pnpm tauri-for-release "$@")
}
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
help 1
exit 1
;;
--version)
VERSION="$2"
shift
shift
;;
--dist)
DIST="$2"
shift
shift
;;
--sign)
DO_SIGN="true"
shift
;;
--channel)
CHANNEL="$2"
shift
shift
;;
*)
error "unknown flag $1"
;;
esac
done
# Recalculate ARCH after TARGET is set
ARCH="$(arch)"
[ -z "${VERSION-}" ] && error "--version is not set"
[ -z "${TAURI_SIGNING_PRIVATE_KEY-}" ] && error "$TAURI_SIGNING_PRIVATE_KEY is not set"
[ -z "${TAURI_SIGNING_PRIVATE_KEY_PASSWORD-}" ] && error "$TAURI_SIGNING_PRIVATE_KEY_PASSWORD is not set"
if [ "$CHANNEL" != "release" ] && [ "$CHANNEL" != "nightly" ]; then
error "--channel must be either 'release' or 'nightly'"
fi
if [ "$DO_SIGN" = "true" ]; then
if [ "$OS" = "macos" ]; then
[ -z "${APPLE_CERTIFICATE-}" ] && error "$APPLE_CERTIFICATE is not set"
[ -z "${APPLE_CERTIFICATE_PASSWORD-}" ] && error "$APPLE_CERTIFICATE_PASSWORD is not set"
[ -z "${APPLE_ID-}" ] && error "$APPLE_ID is not set"
[ -z "${APPLE_TEAM_ID-}" ] && error "$APPLE_TEAM_ID is not set"
[ -z "${APPLE_PASSWORD-}" ] && error "$APPLE_PASSWORD is not set"
export APPLE_CERTIFICATE="$APPLE_CERTIFICATE"
export APPLE_CERTIFICATE_PASSWORD="$APPLE_CERTIFICATE_PASSWORD"
export APPLE_ID="$APPLE_ID"
export APPLE_TEAM_ID="$APPLE_TEAM_ID"
export APPLE_PASSWORD="$APPLE_PASSWORD"
elif [ "$OS" == "linux" ]; then
[ -z "${APPIMAGE_KEY_ID-}" ] && error "$APPIMAGE_KEY_ID is not set"
[ -z "${APPIMAGE_KEY_PASSPHRASE-}" ] && error "$APPIMAGE_KEY_PASSPHRASE is not set"
export SIGN=1
export SIGN_KEY="$APPIMAGE_KEY_ID"
export APPIMAGETOOL_SIGN_PASSPHRASE="$APPIMAGE_KEY_PASSPHRASE"
elif [ "$OS" == "windows" ]; then
: # nothing to do on windows
else
error "signing is not supported on $(uname -s)"
fi
fi
info "building:"
info " channel: $CHANNEL"
info " version: $VERSION"
info " os: $OS"
info " arch: $ARCH"
info " dist: $DIST"
info " sign: $DO_SIGN"
info " target: ${TARGET:-default}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' exit
CONFIG_PATH=$(readlink -f "$PWD/../crates/gitbutler-tauri/tauri.conf.$CHANNEL.json")
if [ "$OS" = "windows" ]; then
# WARNING: `builtin-but` doesn't work on Windows, see https://github.com/gitbutlerapp/gitbutler/issues/11461.
# Should it be re-added, please ensure that `but` is built
# as part of the 'beforeBuildCommand' in tauri.conf AND it must be injected
# via 'inject-git-binaries.sh'.
EXTERNAL_BIN='["gitbutler-git-askpass", "but"]'
FEATURES="windows"
elif [ "$OS" = "linux" ]; then
EXTERNAL_BIN='["gitbutler-git-askpass"]'
FEATURES="builtin-but packaged-but-distribution"
elif [ "$OS" = "macos" ]; then
EXTERNAL_BIN='["gitbutler-git-askpass"]'
FEATURES="builtin-but"
else
echo "Unsupported OS: $OS"
exit 1
fi
# Enable experimental features
if [ "$CHANNEL" != "release" ]; then
FEATURES="$FEATURES irc but-2"
fi
# update the version in the tauri release config
jq --arg version "$VERSION"\
--argjson externalBin "$EXTERNAL_BIN"\
'.version = $version | .bundle.externalBin = $externalBin' "$CONFIG_PATH" >"$TMP_DIR/tauri.conf.json"
# Useful for understanding exactly what goes into the tauri build/bundle.
cat "$TMP_DIR/tauri.conf.json"
# set the VERSION and CHANNEL as an environment variables so that they available in the but CLI
export VERSION
export CHANNEL
# Build the app with release config
if [ -n "$TARGET" ]; then
# Export TARGET for cargo to use
export CARGO_BUILD_TARGET="$TARGET"
# Build with specified target
# Note: passing --target is necessary to let tauri find the binaries,
# it ignores CARGO_BUILD_TARGET and is more of a hack.
tauri build \
--verbose \
--features "$FEATURES" \
--config "$TMP_DIR/tauri.conf.json" \
--target "$TARGET"
BUNDLE_DIR=$(readlink -f "$PWD/../target/$TARGET/release/bundle")
BUILD_DIR=$(readlink -f "$PWD/../target/$TARGET/release")
else
# Build with default target
tauri build \
--verbose \
--features "$FEATURES" \
--config "$TMP_DIR/tauri.conf.json"
BUNDLE_DIR=$(readlink -f "$PWD/../target/release/bundle")
BUILD_DIR=$(readlink -f "$PWD/../target/release")
fi
RELEASE_DIR="$DIST/$OS/$ARCH"
mkdir -p "$RELEASE_DIR"
if [ "$OS" = "macos" ]; then
MACOS_DMG="$(find "$BUNDLE_DIR/dmg" -depth 1 -type f -name "*.dmg")"
MACOS_UPDATER="$(find "$BUNDLE_DIR/macos" -depth 1 -type f -name "*.tar.gz")"
MACOS_UPDATER_SIG="$(find "$BUNDLE_DIR/macos" -depth 1 -type f -name "*.tar.gz.sig")"
cp "$MACOS_DMG" "$RELEASE_DIR"
cp "$MACOS_UPDATER" "$RELEASE_DIR"
cp "$MACOS_UPDATER_SIG" "$RELEASE_DIR"
info "built:"
info " - $RELEASE_DIR/$(basename "$MACOS_DMG")"
info " - $RELEASE_DIR/$(basename "$MACOS_UPDATER")"
info " - $RELEASE_DIR/$(basename "$MACOS_UPDATER_SIG")"
elif [ "$OS" = "linux" ]; then
APPIMAGE="$(find "$BUNDLE_DIR/appimage" -name \*.AppImage)"
APPIMAGE_UPDATER="$(find "$BUNDLE_DIR/appimage" -name \*.AppImage.tar.gz)"
APPIMAGE_UPDATER_SIG="$(find "$BUNDLE_DIR/appimage" -name \*.AppImage.tar.gz.sig)"
DEB="$(find "$BUNDLE_DIR/deb" -name \*.deb)"
RPM="$(find "$BUNDLE_DIR/rpm" -name \*.rpm)"
BUT_CLI="$(readlink -f "$BUILD_DIR/but")"
"$PWD/add-but-symlink-to-deb.sh" "$DEB"
cp "$APPIMAGE" "$RELEASE_DIR"
cp "$APPIMAGE_UPDATER" "$RELEASE_DIR"
cp "$APPIMAGE_UPDATER_SIG" "$RELEASE_DIR"
cp "$DEB" "$RELEASE_DIR"
cp "$RPM" "$RELEASE_DIR"
cp "$BUT_CLI" "$RELEASE_DIR"
info "built:"
info " - $RELEASE_DIR/$(basename "$APPIMAGE")"
info " - $RELEASE_DIR/$(basename "$APPIMAGE_UPDATER")"
info " - $RELEASE_DIR/$(basename "$APPIMAGE_UPDATER_SIG")"
info " - $RELEASE_DIR/$(basename "$DEB")"
info " - $RELEASE_DIR/$(basename "$RPM")"
info " - $RELEASE_DIR/$(basename "$BUT_CLI")"
elif [ "$OS" = "windows" ]; then
WINDOWS_INSTALLER="$(find "$BUNDLE_DIR/msi" -name \*.msi)"
WINDOWS_UPDATER="$(find "$BUNDLE_DIR/msi" -name \*.msi.zip)"
WINDOWS_UPDATER_SIG="$(find "$BUNDLE_DIR/msi" -name \*.msi.zip.sig)"
cp "$WINDOWS_INSTALLER" "$RELEASE_DIR"
cp "$WINDOWS_UPDATER" "$RELEASE_DIR"
cp "$WINDOWS_UPDATER_SIG" "$RELEASE_DIR"
info "built:"
info " - $RELEASE_DIR/$(basename "$WINDOWS_INSTALLER")"
info " - $RELEASE_DIR/$(basename "$WINDOWS_UPDATER")"
info " - $RELEASE_DIR/$(basename "$WINDOWS_UPDATER_SIG")"
else
error "unsupported os: $OS"
fi
info "done! bye!"