upload-nightly

 1#!/usr/bin/env bash
 2
 3# Based on the template in: https://docs.digitalocean.com/reference/api/spaces-api/
 4bash -euo pipefail
 5source script/lib/blob-store.sh
 6
 7allowed_targets=("linux-targz" "macos")
 8is_allowed_target() {
 9    for val in "${allowed_targets[@]}"; do
10        if [[ "$1" == "$val" ]]; then
11            return 0
12        fi
13    done
14    return 1
15}
16
17if [[ -n "${1:-}" ]]; then
18    if is_allowed_target "$1"; then
19        target="$1"
20    else
21        echo "Error: Target '$1' is not allowed"
22        echo "Usage: $0 [${allowed_targets[@]}]"
23        exit 1
24    fi
25else
26echo "Error: Target is not specified"
27echo "Usage: $0 [${allowed_targets[@]}]"
28exit 1
29fi
30echo "Uploading nightly for target: $target"
31
32bucket_name="zed-nightly-host"
33
34sha=$(git rev-parse HEAD)
35echo ${sha} > target/latest-sha
36case "$target" in
37    macos)
38        upload_to_blob_store $bucket_name "target/aarch64-apple-darwin/release/Zed.dmg" "nightly/Zed-aarch64.dmg"
39        upload_to_blob_store $bucket_name "target/x86_64-apple-darwin/release/Zed.dmg" "nightly/Zed-x86_64.dmg"
40        upload_to_blob_store $bucket_name "target/release/Zed.dmg" "nightly/Zed.dmg"
41        upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha"
42        rm -f "target/aarch64-apple-darwin/release/Zed.dmg" "target/x86_64-apple-darwin/release/Zed.dmg" "target/release/Zed.dmg"
43        rm -f "target/latest-sha"
44        ;;
45    linux-targz)
46        find . -type f -name "zed-*.tar.gz" -print0 | while IFS= read -r -d '' bundle_file; do
47            upload_to_blob_store $bucket_name "$bundle_file" "nightly/$(basename "$bundle_file")"
48            rm -f "$bundle_file"
49        done
50        upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha-linux-targz"
51        rm -f "target/latest-sha"
52        ;;
53    *)
54        echo "Error: Unknown target '$target'"
55        exit 1
56        ;;
57esac