|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -exuo pipefail |
| 3 | + |
| 4 | +BINARY_NAME="stl" |
| 5 | +DIST_DIR="dist" |
| 6 | +FILENAME="dist.zip" |
| 7 | + |
| 8 | +mapfile -d '' files < <( |
| 9 | + find "$DIST_DIR" -regextype posix-extended -type f \ |
| 10 | + -regex ".*/[^/]*(amd64|arm64)[^/]*/${BINARY_NAME}(\\.exe)?$" -print0 |
| 11 | +) |
| 12 | + |
| 13 | +if [[ ${#files[@]} -eq 0 ]]; then |
| 14 | + echo -e "\033[31mNo binaries found for packaging.\033[0m" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +rm -f "${DIST_DIR}/${FILENAME}" |
| 19 | + |
| 20 | +while IFS= read -r -d '' dir; do |
| 21 | + printf "Remove the quarantine attribute before running the executable:\n\nxattr -d com.apple.quarantine %s\n" \ |
| 22 | + "$BINARY_NAME" >"${dir}/README.txt" |
| 23 | +done < <(find "$DIST_DIR" -type d -name '*macos*' -print0) |
| 24 | + |
| 25 | +relative_files=() |
| 26 | +for file in "${files[@]}"; do |
| 27 | + relative_files+=("${file#"${DIST_DIR}"/}") |
| 28 | +done |
| 29 | + |
| 30 | +(cd "$DIST_DIR" && zip -r "$FILENAME" "${relative_files[@]}") |
| 31 | + |
| 32 | +RESPONSE=$(curl -X POST "$URL?filename=$FILENAME" \ |
| 33 | + -H "Authorization: Bearer $AUTH" \ |
| 34 | + -H "Content-Type: application/json") |
| 35 | + |
| 36 | +SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url') |
| 37 | + |
| 38 | +if [[ "$SIGNED_URL" == "null" ]]; then |
| 39 | + echo -e "\033[31mFailed to get signed URL.\033[0m" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +UPLOAD_RESPONSE=$(curl -v -X PUT \ |
| 44 | + -H "Content-Type: application/zip" \ |
| 45 | + --data-binary "@${DIST_DIR}/${FILENAME}" "$SIGNED_URL" 2>&1) |
| 46 | + |
| 47 | +if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then |
| 48 | + echo -e "\033[32mUploaded build to Stainless storage.\033[0m" |
| 49 | + echo -e "\033[32mInstallation: Download and unzip: 'https://pkg.stainless.com/s/stainless-v0-cli/$SHA/$FILENAME'. On macOS, run `xattr -d com.apple.quarantine {executable name}.`\033[0m" |
| 50 | +else |
| 51 | + echo -e "\033[31mFailed to upload artifact.\033[0m" |
| 52 | + exit 1 |
| 53 | +fi |
0 commit comments