@@ -28,15 +28,19 @@ CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"../target"}
28
28
export CARGO_TARGET_DIR
29
29
30
30
# Temporary build directory
31
- BUILD_DIR=" . /build"
31
+ BUILD_DIR=" $SCRIPT_DIR /build"
32
32
# Successfully built (and signed) artifacts
33
- DIST_DIR=" ../dist"
33
+ DIST_DIR=" $SCRIPT_DIR / ../dist"
34
34
35
35
BUNDLE_NAME=" MullvadVPNInstaller"
36
36
BUNDLE_ID=" net.mullvad.$BUNDLE_NAME "
37
37
38
38
FILENAME=" Install Mullvad VPN"
39
39
40
+ # When --upload is passed, git verify-tag looks for a signed tag with the prefix below.
41
+ # The signed tag must be named $TAG_PREFIX/<version>.
42
+ TAG_PREFIX=" desktop/installer-downloader/"
43
+
40
44
rm -rf " $BUILD_DIR "
41
45
mkdir -p " $BUILD_DIR "
42
46
@@ -45,6 +49,9 @@ mkdir -p "$DIST_DIR"
45
49
# Whether to sign and notarized produced binaries
46
50
SIGN=" false"
47
51
52
+ # Whether to upload signed binaries
53
+ UPLOAD=" false"
54
+
48
55
# Temporary keychain to store the .p12 in.
49
56
# This is automatically created/replaced when signing on macOS.
50
57
SIGN_KEYCHAIN_PATH=" $HOME /Library/Keychains/mv-metadata-keychain-db"
@@ -55,6 +62,9 @@ while [[ "$#" -gt 0 ]]; do
55
62
--sign)
56
63
SIGN=" true"
57
64
;;
65
+ --upload)
66
+ UPLOAD=" true"
67
+ ;;
58
68
* )
59
69
log_error " Unknown parameter: $1 "
60
70
exit 1
@@ -63,6 +73,11 @@ while [[ "$#" -gt 0 ]]; do
63
73
shift
64
74
done
65
75
76
+ if [[ " $UPLOAD " == " true" && " $SIGN " != " true" ]]; then
77
+ log_error " '--upload' requires '--sign' to be specified"
78
+ exit 1
79
+ fi
80
+
66
81
# Check that we have the correct environment set for signing
67
82
function assert_can_sign {
68
83
if [[ " $( uname -s) " == " Darwin" ]]; then
@@ -305,6 +320,76 @@ function dist_windows_app {
305
320
mv " $BUILD_DIR /$FILENAME .exe" " $DIST_DIR /"
306
321
}
307
322
323
+ # Upload whatever matches the first argument to the Linux build server
324
+ # Arguments:
325
+ # - local file
326
+ # - version
327
+ function upload_sftp {
328
+ local local_path=$1
329
+ local version=$2
330
+ echo " Uploading \" $local_path \" to app-build-linux:upload/installer-downloader/$version "
331
+ sftp app-build-linux << EOF
332
+ mkdir upload/installer-downloader
333
+ mkdir upload/installer-downloader/$version
334
+ chmod 770 upload/installer-downloader
335
+ chmod 770 upload/installer-downloader/$version
336
+ cd upload/installer-downloader/$version
337
+ put "$local_path "
338
+ bye
339
+ EOF
340
+ }
341
+
342
+ # Upload latest build and checksum in the dist directory to Linux build server
343
+ # The artifacts MUST have been built already
344
+ # The working directory MUST be $DIST_DIR
345
+ #
346
+ # Arguments:
347
+ # - version
348
+ function upload {
349
+ local version=$1
350
+ local files=( " $FILENAME ." * )
351
+
352
+ local checksums_path
353
+ checksums_path=" installer-downloader+$( hostname) +$version .sha256"
354
+
355
+ sha256sum " ${files[@]} " > " $checksums_path "
356
+
357
+ for file in " ${files[@]} " ; do
358
+ upload_sftp " $file " " $version " || return 1
359
+ done
360
+ upload_sftp " $checksums_path " " $version " || return 1
361
+ }
362
+
363
+ # Check if the current commit has a signed tag
364
+ #
365
+ # Arguments:
366
+ # - version
367
+ function verify_version_tag {
368
+ local version=$1
369
+
370
+ local expect_tag=" ${TAG_PREFIX}${version} "
371
+ log_info " Current commit must have tag: $expect_tag "
372
+
373
+ local tag
374
+ set +e
375
+ tag=$( git describe --exact-match --tags)
376
+ local describe_exit=$?
377
+ set -e
378
+
379
+ if [[ $describe_exit -ne 0 ]]; then
380
+ log_error " 'git describe' failed for the current commit (no tag?). Expected tag $expect_tag "
381
+ exit 1
382
+ fi
383
+
384
+ if [[ " $tag " != " $expect_tag " ]]; then
385
+ log_error " Unexpected tag found for current commit. Expected $expect_tag . Found: $tag "
386
+ exit 1
387
+ fi
388
+
389
+ log_info " Verifying tag $tag ..."
390
+ git verify-tag " $tag "
391
+ }
392
+
308
393
function main {
309
394
if [[ " $SIGN " != " false" ]]; then
310
395
assert_can_sign
@@ -327,6 +412,15 @@ function main {
327
412
build_executable
328
413
dist_windows_app
329
414
fi
415
+
416
+ if [[ " $UPLOAD " == " true" ]]; then
417
+ local version
418
+ version=$( product_version)
419
+
420
+ verify_version_tag " $version "
421
+
422
+ (cd " $DIST_DIR " && upload " $version " ) || return 1
423
+ fi
330
424
}
331
425
332
426
main
0 commit comments