github.com/anthropics/anthropic-sdk-go@v1.70.1/scripts/utils/upload-artifact.sh (about)

     1  #!/usr/bin/env bash
     2  set -exuo pipefail
     3  
     4  DIST_DIR="dist"
     5  FILENAME="source.zip"
     6  
     7  mapfile -d '' files < <(
     8    find . -type f \
     9      \( -name '*.go' -o -name 'go.mod' -o -name 'go.sum' \) \
    10      ! -path "./${DIST_DIR}/*" \
    11      -print0
    12  )
    13  
    14  if [[ ${#files[@]} -eq 0 ]]; then
    15    echo -e "\033[31mNo Go source files found for packaging.\033[0m"
    16    exit 1
    17  fi
    18  
    19  mkdir -p "$DIST_DIR"
    20  rm -f "${DIST_DIR}/${FILENAME}"
    21  
    22  relative_files=()
    23  for file in "${files[@]}"; do
    24    relative_files+=("${file#./}")
    25  done
    26  
    27  zip "${DIST_DIR}/${FILENAME}" "${relative_files[@]}"
    28  
    29  RESPONSE=$(curl -X POST "$URL?filename=$FILENAME" \
    30    -H "Authorization: Bearer $AUTH" \
    31    -H "Content-Type: application/json")
    32  
    33  SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url')
    34  
    35  if [[ "$SIGNED_URL" == "null" ]]; then
    36    echo -e "\033[31mFailed to get signed URL.\033[0m"
    37    exit 1
    38  fi
    39  
    40  UPLOAD_RESPONSE=$(curl -v -X PUT \
    41    -H "Content-Type: application/zip" \
    42    --data-binary "@${DIST_DIR}/${FILENAME}" "$SIGNED_URL" 2>&1)
    43  
    44  if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then
    45    echo -e "\033[32mUploaded build to Stainless storage.\033[0m"
    46    echo -e "\033[32mInstallation: Download and unzip: 'https://pkg.stainless.com/s/anthropic-go/$SHA'. Run 'go mod edit -replace github.com/anthropics/anthropic-sdk-go=/path/to/unzipped_directory'.\033[0m"
    47  else
    48    echo -e "\033[31mFailed to upload artifact.\033[0m"
    49    exit 1
    50  fi