Skip to content

Commit f9c44d6

Browse files
committed
Merge branch 'add-upload-option-build-sh'
2 parents e5b0413 + 45c92e3 commit f9c44d6

File tree

4 files changed

+117
-15
lines changed

4 files changed

+117
-15
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci/buildserver-upload.sh

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -eu
4-
shopt -s nullglob
4+
shopt -s nullglob globstar
55

66
CODE_SIGNING_KEY_FINGERPRINT="A1198702FC3E0A09A9AE5B75D5A1D4F266DE8DDF"
77

@@ -23,35 +23,42 @@ function rsync_upload {
2323

2424
while true; do
2525
sleep 10
26-
for checksums_path in *.sha256; do
26+
for checksums_path in **/*.sha256; do
2727
sleep 1
2828

29+
checksums_dir=$(dirname "$checksums_path")
30+
checksums_filename=$(basename "$checksums_path")
31+
2932
# Parse the platform name and version out of the filename of the checksums file.
30-
platform="$(echo "$checksums_path" | cut -d + -f 1)"
31-
version="$(echo "$checksums_path" | cut -d + -f 3,4 | sed 's/\.sha256//')"
32-
if ! sha256sum --quiet -c "$checksums_path"; then
33+
platform="$(echo "$checksums_filename" | cut -d + -f 1)"
34+
version="$(echo "$checksums_filename" | cut -d + -f 3,4 | sed 's/\.sha256//')"
35+
if ! (cd "$checksums_dir" && sha256sum --quiet -c "$checksums_filename"); then
3336
echo "Failed to verify checksums for $version"
3437
continue
3538
fi
3639

37-
if [[ $version == *"-dev-"* ]]; then
40+
if [[ "$platform" == "installer-downloader" ]]; then
41+
upload_path="desktop/installer-downloader"
42+
elif [[ $version == *"-dev-"* ]]; then
3843
upload_path="$platform/builds"
3944
else
4045
upload_path="$platform/releases"
4146
fi
4247

43-
files=$(awk '{print $2}' < "$checksums_path")
44-
for file in $files; do
48+
readarray -t files < <(cut -f 2- -d ' ' < "$checksums_path" | sed 's/^\*\(.*\)/\1/')
49+
for filename in "${files[@]}"; do
50+
file="$checksums_dir/$filename"
51+
4552
file_upload_dir="$upload_path/$version"
46-
if [[ $platform == "desktop" && ! $file == MullvadVPN-* ]]; then
53+
if [[ $platform == "desktop" && ! $filename == MullvadVPN-* ]]; then
4754
file_upload_dir="$file_upload_dir/additional-files"
48-
elif [[ $platform == "android" && ! $file =~ MullvadVPN-"$version"(.apk|.play.apk|.play.aab) ]]; then
55+
elif [[ $platform == "android" && ! $filename =~ MullvadVPN-"$version"(.apk|.play.apk|.play.aab) ]]; then
4956
file_upload_dir="$file_upload_dir/additional-files"
5057
fi
5158

5259
rsync_upload "$file" "$file_upload_dir/" || continue
5360

54-
if [[ $file == MullvadVPN-* ]]; then
61+
if [[ $filename == MullvadVPN-* || $filename == Install* ]]; then
5562
rm -f "$file.asc"
5663
gpg -u $CODE_SIGNING_KEY_FINGERPRINT --pinentry-mode loopback --sign --armor --detach-sign "$file"
5764
rsync_upload "$file.asc" "$file_upload_dir/" || continue

installer-downloader/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "installer-downloader"
33
description = "A secure minimal web installer for the Mullvad app"
4-
version = "1.0.0"
4+
version = "0.1.0"
5+
publish = false
56
authors.workspace = true
67
repository.workspace = true
78
license.workspace = true

installer-downloader/build.sh

+96-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"../target"}
2828
export CARGO_TARGET_DIR
2929

3030
# Temporary build directory
31-
BUILD_DIR="./build"
31+
BUILD_DIR="$SCRIPT_DIR/build"
3232
# Successfully built (and signed) artifacts
33-
DIST_DIR="../dist"
33+
DIST_DIR="$SCRIPT_DIR/../dist"
3434

3535
BUNDLE_NAME="MullvadVPNInstaller"
3636
BUNDLE_ID="net.mullvad.$BUNDLE_NAME"
3737

3838
FILENAME="Install Mullvad VPN"
3939

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+
4044
rm -rf "$BUILD_DIR"
4145
mkdir -p "$BUILD_DIR"
4246

@@ -45,6 +49,9 @@ mkdir -p "$DIST_DIR"
4549
# Whether to sign and notarized produced binaries
4650
SIGN="false"
4751

52+
# Whether to upload signed binaries
53+
UPLOAD="false"
54+
4855
# Temporary keychain to store the .p12 in.
4956
# This is automatically created/replaced when signing on macOS.
5057
SIGN_KEYCHAIN_PATH="$HOME/Library/Keychains/mv-metadata-keychain-db"
@@ -55,6 +62,9 @@ while [[ "$#" -gt 0 ]]; do
5562
--sign)
5663
SIGN="true"
5764
;;
65+
--upload)
66+
UPLOAD="true"
67+
;;
5868
*)
5969
log_error "Unknown parameter: $1"
6070
exit 1
@@ -63,6 +73,11 @@ while [[ "$#" -gt 0 ]]; do
6373
shift
6474
done
6575

76+
if [[ "$UPLOAD" == "true" && "$SIGN" != "true" ]]; then
77+
log_error "'--upload' requires '--sign' to be specified"
78+
exit 1
79+
fi
80+
6681
# Check that we have the correct environment set for signing
6782
function assert_can_sign {
6883
if [[ "$(uname -s)" == "Darwin" ]]; then
@@ -305,6 +320,76 @@ function dist_windows_app {
305320
mv "$BUILD_DIR/$FILENAME.exe" "$DIST_DIR/"
306321
}
307322

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+
308393
function main {
309394
if [[ "$SIGN" != "false" ]]; then
310395
assert_can_sign
@@ -327,6 +412,15 @@ function main {
327412
build_executable
328413
dist_windows_app
329414
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
330424
}
331425

332426
main

0 commit comments

Comments
 (0)