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
17allowed_arch=("x86_64" "aarch64")
18is_allowed_arch() {
19 for val in "${allowed_arch[@]}"; do
20 if [[ "$1" == "$val" ]]; then
21 return 0
22 fi
23 done
24 return 1
25}
26
27if is_allowed_target "$1"; then
28 target="$1"
29else
30 echo "Error: Target '$1' is not allowed"
31 echo "Usage: $0 [${allowed_targets[*]}] {arch}"
32 exit 1
33fi
34if is_allowed_arch "$2"; then
35 arch="$2"
36else
37 echo "Error: Arch '$2' is not allowed"
38 echo "Usage: $0 $1 [${allowed_arch[*]}]"
39 exit 1
40fi
41echo "Uploading nightly for target: $target $arch"
42
43bucket_name="zed-nightly-host"
44
45sha=$(git rev-parse HEAD)
46echo ${sha} > target/latest-sha
47
48find target -type f -name "zed-remote-server-*.gz" -print0 | while IFS= read -r -d '' file_to_upload; do
49 upload_to_blob_store $bucket_name "$file_to_upload" "nightly/$(basename "$file_to_upload")"
50 rm -f "$file_to_upload"
51done
52
53case "$target" in
54 macos)
55 upload_to_blob_store $bucket_name "target/$arch-apple-darwin/release/Zed.dmg" "nightly/Zed-$arch.dmg"
56 upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha"
57 rm -f "target/$arch-apple-darwin/release/Zed.dmg" "target/release/Zed.dmg"
58 rm -f "target/latest-sha"
59 ;;
60 linux-targz)
61 find . -type f -name "zed-*.tar.gz" -print0 | while IFS= read -r -d '' file_to_upload; do
62 upload_to_blob_store $bucket_name "$file_to_upload" "nightly/$(basename "$file_to_upload")"
63 rm -f "$file_to_upload"
64 done
65 upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha-linux-targz"
66 rm -f "target/latest-sha"
67 ;;
68 freebsd)
69 echo "No freebsd client build (yet)."
70 ;;
71 *)
72 echo "Error: Unknown target '$target'"
73 exit 1
74 ;;
75esac