name: 'Upload Cache to GitHub Releases' description: 'Upload cache archive(s) to GitHub Releases with retry logic' inputs: cache_key: description: 'Unique key for the cache' required: true type: string cache_bucket: description: 'The tag name for the release' required: true default: 'general-cache' github_token: description: 'GitHub Token' required: true compression_level: description: 'Compression level (0-9)' required: false type: number default: 6 debug: description: 'Enable Logs' required: false type: boolean default: false runs: using: 'composite' steps: - name: Upload Cache Asset(s) shell: bash env: GH_TOKEN: ${{ inputs.github_token }} TARGET_REPO: "${{ github.repository }}" run: | set -euo pipefail TAG_NAME="${{ inputs.cache_bucket }}" BASE_FILENAME="cache-${{ inputs.cache_key }}" if [ "${{ inputs.compression_level }}" -eq 0 ]; then FILENAME="$BASE_FILENAME.tar" else FILENAME="$BASE_FILENAME.tzst" fi upload_with_retry() { local file=$1 local max_attempts=3 local timeout_duration="10m" for ((i=1; i<=max_attempts; i++)); do echo " Attempt $i for $file..." if [ "${{ inputs.debug }}" = "true" ]; then if timeout "$timeout_duration" gh release upload "$TAG_NAME" "$file" --clobber --repo "$TARGET_REPO"; then echo " Successfully uploaded $file" return 0 fi else if timeout "$timeout_duration" gh release upload "$TAG_NAME" "$file" --clobber --repo "$TARGET_REPO" > /dev/null 2>&1; then echo " Successfully uploaded $file" return 0 fi fi echo " ⚠ Attempt $i failed. Retrying..." if [ "$i" -lt "$max_attempts" ]; then sleep 5 fi done echo "::error::Failed to upload $file after multiple attempts." return 1 } # Upload single file or split parts if [ -f "$FILENAME" ]; then if ! upload_with_retry "$FILENAME"; then exit 1 fi rm -f "$FILENAME" else # Upload split parts for part in "${FILENAME}".part*; do if [ ! -f "$part" ]; then continue fi if ! upload_with_retry "$part"; then exit 1 fi rm -f "$part" done rm -rf "$FILENAME" fi # Final cleanup rm -f "${BASE_FILENAME}"* || true echo "✅ Cache upload complete"