upload-nightly

 1#!/bin/bash
 2
 3# Based on the template in: https://docs.digitalocean.com/reference/api/spaces-api/
 4set -ux
 5
 6# Step 1: Define the parameters for the Space you want to upload to.
 7SPACE="zed-nightly-host" # Find your endpoint in the control panel, under Settings.
 8REGION="nyc3" # Must be "us-east-1" when creating new Spaces. Otherwise, use the region in your endpoint (e.g. nyc3).
 9
10# Step 2: Define a function that uploads your object via cURL.
11function uploadToSpaces
12{
13  file_to_upload="$1"
14  file_name="$2"
15  space_path="nightly"
16  date=$(date +"%a, %d %b %Y %T %z")
17  acl="x-amz-acl:private"
18  content_type="application/octet-stream"
19  storage_type="x-amz-storage-class:STANDARD"
20  string="PUT\n\n${content_type}\n${date}\n${acl}\n${storage_type}\n/${SPACE}/${space_path}/${file_name}"
21  signature=$(echo -en "${string}" | openssl sha1 -hmac "${DIGITALOCEAN_SPACES_SECRET_KEY}" -binary | base64)
22
23  curl -vv -s -X PUT -T "$file_to_upload" \
24    -H "Host: ${SPACE}.${REGION}.digitaloceanspaces.com" \
25    -H "Date: $date" \
26    -H "Content-Type: $content_type" \
27    -H "$storage_type" \
28    -H "$acl" \
29    -H "Authorization: AWS ${DIGITALOCEAN_SPACES_ACCESS_KEY}:$signature" \
30    "https://${SPACE}.${REGION}.digitaloceanspaces.com/${space_path}/${file_name}"
31}
32
33sha=$(git rev-parse HEAD)
34echo ${sha} > target/latest-sha
35
36uploadToSpaces "target/release/Zed.dmg" "Zed.dmg"
37uploadToSpaces "target/latest-sha" "latest-sha"