| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| |
| |
|
|
| if [[ $# -ne 1 ]]; then |
| echo "Usage: $0 <cli-version> (e.g., cli/v1.0.0)" |
| exit 1 |
| fi |
| CLI_TAG="$1" |
| |
| if [[ ! "$CLI_TAG" =~ ^cli/v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then |
| echo "β Invalid tag format: $CLI_TAG" |
| echo " Expected format: cli/vX.Y.Z or cli/vX.Y.Z-prerelease (e.g., cli/v1.0.0, cli/v1.0.0-rc.1)" |
| exit 1 |
| fi |
| if [[ ! -d "./dist" ]]; then |
| echo "β ./dist not found. Build artifacts must be present before upload." |
| exit 1 |
| fi |
| : "${R2_ENDPOINT:?R2_ENDPOINT env var is required}" |
| : "${R2_BUCKET:?R2_BUCKET env var is required}" |
|
|
| |
| VERSION_ONLY=${CLI_TAG#cli/v} |
| CLI_VERSION="v${VERSION_ONLY}" |
| printf '%s' "$CLI_VERSION" > "./dist/version.txt" |
| R2_ENDPOINT="$(echo "$R2_ENDPOINT" | tr -d '[:space:]')" |
|
|
| echo "π€ Uploading CLI binaries for version: $CLI_VERSION" |
|
|
| |
| upload_with_retry() { |
| local source_path="$1" |
| local dest_path="$2" |
| local max_retries=3 |
|
|
| for attempt in $(seq 1 $max_retries); do |
| echo "π Attempt $attempt/$max_retries: Uploading to $dest_path" |
|
|
| if aws s3 sync "$source_path" "$dest_path" \ |
| --endpoint-url "$R2_ENDPOINT" \ |
| --profile "${R2_AWS_PROFILE:-R2}" \ |
| --no-progress \ |
| --delete; then |
| echo "β
Upload successful to $dest_path" |
| return 0 |
| else |
| echo "β οΈ Attempt $attempt failed" |
| if [ $attempt -lt $max_retries ]; then |
| delay=$((2 ** attempt)) |
| echo "π Waiting ${delay}s before retry..." |
| sleep $delay |
| fi |
| fi |
| done |
|
|
| echo "β All $max_retries attempts failed for $dest_path" |
| return 1 |
| } |
|
|
| |
| if ! upload_with_retry "./dist/" "s3://$R2_BUCKET/bifrost-cli/$CLI_VERSION/"; then |
| exit 1 |
| fi |
|
|
| |
| if [[ "$CLI_VERSION" == *-* ]]; then |
| echo "π Detected prerelease version: $CLI_VERSION" |
| echo "βοΈ Skipping upload to latest/ for prerelease" |
| else |
| echo "π Detected stable release: $CLI_VERSION" |
|
|
| |
| sleep "${INTER_UPLOAD_SLEEP_SECONDS:-2}" |
|
|
| |
| echo "π€ Uploading to latest/" |
| if ! upload_with_retry "./dist/" "s3://$R2_BUCKET/bifrost-cli/latest/"; then |
| exit 1 |
| fi |
| fi |
|
|
| echo "π All CLI binaries uploaded successfully to R2" |
|
|