Add GitHub Action for publishing the extension CLI (#9542)

This PR adds a GitHub Action for publishing the extension CLI.

When the `extension-cli` tag is pushed, this Action will run, build the
`zed-extension` binary, and upload it to DigitalOcean for consumption.

This will allow us to consume the pre-built binary in the CI for the
extensions repo.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-03-19 14:19:32 -04:00 committed by GitHub
parent 2ea333fff6
commit 905a24079a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 102 additions and 56 deletions

View file

@ -0,0 +1,41 @@
name: Publish zed-extension CLI
on:
push:
tags:
- extension-cli
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
publish:
name: Publish zed-extension CLI
runs-on:
- ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
clean: false
submodules: "recursive"
- name: Cache dependencies
uses: swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Configure linux
shell: bash -euxo pipefail {0}
run: script/linux
- name: Build extension CLI
run: cargo build --release --package extension_cli
- name: Upload binary
if: ${{ github.ref == 'refs/heads/main' }}
env:
DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
run: script/upload-extension-cli ${{ github.sha }}

View file

@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -euxo pipefail
source script/lib/blob-store.sh
build_flag="--release"
target_dir="release"
@ -30,29 +31,6 @@ Options:
"
}
function uploadDsym
{
SPACE="zed-debug-symbols"
REGION="nyc3"
file_to_upload="$1"
file_name="$2"
date=$(date +"%a, %d %b %Y %T %z")
acl="x-amz-acl:public-read"
content_type="application/octet-stream"
storage_type="x-amz-storage-class:STANDARD"
string="PUT\n\n${content_type}\n${date}\n${acl}\n${storage_type}\n/${SPACE}/${file_name}"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${DIGITALOCEAN_SPACES_SECRET_KEY}" -binary | base64)
curl --fail -vv -s -X PUT -T "$file_to_upload" \
-H "Host: ${SPACE}.${REGION}.digitaloceanspaces.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${DIGITALOCEAN_SPACES_ACCESS_KEY}:$signature" \
"https://${SPACE}.${REGION}.digitaloceanspaces.com/${file_name}"
}
while getopts 'dlfoh' flag
do
case "${flag}" in
@ -152,7 +130,10 @@ function prepare_binaries() {
gzip target/${architecture}/${target_dir}/Zed.dwarf
echo "Uploading dSYMs for $architecture"
uploadDsym target/${architecture}/${target_dir}/Zed.dwarf.gz "$channel/Zed-$version-${architecture}.dwarf.gz"
upload_to_blob_store_public \
"zed-debug-symbols" \
target/${architecture}/${target_dir}/Zed.dwarf.gz \
"$channel/Zed-$version-${architecture}.dwarf.gz"
cp target/${architecture}/${target_dir}/${binary_name} "${app_path}/Contents/MacOS/${zed_crate}"
cp target/${architecture}/${target_dir}/cli "${app_path}/Contents/MacOS/cli"

33
script/lib/blob-store.sh Normal file
View file

@ -0,0 +1,33 @@
function upload_to_blob_store_with_acl
{
bucket_name="$1"
file_to_upload="$2"
blob_store_key="$3"
acl="$4"
date=$(date +"%a, %d %b %Y %T %z")
acl="x-amz-acl:public-read"
content_type="application/octet-stream"
storage_type="x-amz-storage-class:STANDARD"
string="PUT\n\n${content_type}\n${date}\n${acl}\n${storage_type}\n/${bucket_name}/${blob_store_key}"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${DIGITALOCEAN_SPACES_SECRET_KEY}" -binary | base64)
curl --fail -vv -s -X PUT -T "$file_to_upload" \
-H "Host: ${bucket_name}.nyc3.digitaloceanspaces.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${DIGITALOCEAN_SPACES_ACCESS_KEY}:$signature" \
"https://${bucket_name}.nyc3.digitaloceanspaces.com/${blob_store_key}"
}
function upload_to_blob_store_public
{
upload_to_blob_store_with_acl $1 $2 $3 "x-amz-acl:public-read"
}
function upload_to_blob_store
{
upload_to_blob_store_with_acl $1 $2 $3 "x-amz-acl:private"
}

15
script/upload-extension-cli Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
bash -euo pipefail
source script/lib/blob-store.sh
commit=$1
if [ "$#" -ne 1 ] || ! [[ $commit =~ ^[0-9a-f]{40}$ ]]; then
echo "Usage: $0 <git-sha>"
exit 1
fi
bucket_name="zed-extension-cli"
target_triple=$(rustc -vV | sed -n 's|host: ||p')
upload_to_blob_store_public $bucket_name "target/release/zed-extension" "${commit}/${target_triple}/zed-extension"

View file

@ -2,6 +2,7 @@
# Based on the template in: https://docs.digitalocean.com/reference/api/spaces-api/
bash -euo pipefail
source script/lib/blob-store.sh
allowed_targets=("linux-deb" "macos")
is_allowed_target() {
@ -28,47 +29,22 @@ exit 1
fi
echo "Uploading nightly for target: $target"
# Step 1: Define the parameters for the Space you want to upload to.
SPACE="zed-nightly-host" # Find your endpoint in the control panel, under Settings.
REGION="nyc3" # Must be "us-east-1" when creating new Spaces. Otherwise, use the region in your endpoint (e.g. nyc3).
# Step 2: Define a function that uploads your object via cURL.
function uploadToSpaces
{
file_to_upload="$1"
file_name="$2"
space_path="nightly"
date=$(date +"%a, %d %b %Y %T %z")
acl="x-amz-acl:private"
content_type="application/octet-stream"
storage_type="x-amz-storage-class:STANDARD"
string="PUT\n\n${content_type}\n${date}\n${acl}\n${storage_type}\n/${SPACE}/${space_path}/${file_name}"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${DIGITALOCEAN_SPACES_SECRET_KEY}" -binary | base64)
curl --fail -vv -s -X PUT -T "$file_to_upload" \
-H "Host: ${SPACE}.${REGION}.digitaloceanspaces.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${DIGITALOCEAN_SPACES_ACCESS_KEY}:$signature" \
"https://${SPACE}.${REGION}.digitaloceanspaces.com/${space_path}/${file_name}"
}
bucket_name="zed-nightly-host"
sha=$(git rev-parse HEAD)
echo ${sha} > target/latest-sha
case "$target" in
macos)
uploadToSpaces "target/aarch64-apple-darwin/release/Zed.dmg" "Zed-aarch64.dmg"
uploadToSpaces "target/x86_64-apple-darwin/release/Zed.dmg" "Zed-x86_64.dmg"
uploadToSpaces "target/release/Zed.dmg" "Zed.dmg"
uploadToSpaces "target/latest-sha" "latest-sha"
upload_to_blob_store $bucket_name "target/aarch64-apple-darwin/release/Zed.dmg" "nightly/Zed-aarch64.dmg"
upload_to_blob_store $bucket_name "target/x86_64-apple-darwin/release/Zed.dmg" "nightly/Zed-x86_64.dmg"
upload_to_blob_store $bucket_name "target/release/Zed.dmg" "nightly/Zed.dmg"
upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha"
;;
linux-deb)
find target/release -type f -name "*.deb" -print0 | while IFS= read -r -d '' bundle_file; do
uploadToSpaces "$bundle_file" "$(basename "$bundle_file")"
upload_to_blob_store $bucket_name "$bundle_file" "nightly/$(basename "$bundle_file")"
done
uploadToSpaces "target/latest-sha" "latest-sha-linux-deb"
upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha-linux-deb"
;;
*)
echo "Error: Unknown target '$target'"