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" "freebsd")
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
36
37find target -type f -name "zed-remote-server-*.gz" -print0 | while IFS= read -r -d '' file_to_upload; do
38 upload_to_blob_store $bucket_name "$file_to_upload" "nightly/$(basename "$file_to_upload")"
39 rm -f "$file_to_upload"
40done
41
42case "$target" in
43 macos)
44 upload_to_blob_store $bucket_name "target/aarch64-apple-darwin/release/Zed.dmg" "nightly/Zed-aarch64.dmg"
45 upload_to_blob_store $bucket_name "target/x86_64-apple-darwin/release/Zed.dmg" "nightly/Zed-x86_64.dmg"
46 upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha"
47 rm -f "target/aarch64-apple-darwin/release/Zed.dmg" "target/x86_64-apple-darwin/release/Zed.dmg" "target/release/Zed.dmg"
48 rm -f "target/latest-sha"
49 ;;
50 linux-targz)
51 find . -type f -name "zed-*.tar.gz" -print0 | while IFS= read -r -d '' file_to_upload; do
52 upload_to_blob_store $bucket_name "$file_to_upload" "nightly/$(basename "$file_to_upload")"
53 rm -f "$file_to_upload"
54 done
55 upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha-linux-targz"
56 rm -f "target/latest-sha"
57 ;;
58 freebsd)
59 echo "No freebsd client build (yet)."
60 ;;
61 *)
62 echo "Error: Unknown target '$target'"
63 exit 1
64 ;;
65esac