|
| 1 | +# ------------------------------------------------------------------------------------ |
| 2 | +# Upload Artifact with Resilience (Composite Action) (GoFortress) |
| 3 | +# |
| 4 | +# Purpose: Provide resilient artifact uploads with step-level retry logic to handle |
| 5 | +# transient GitHub infrastructure failures (including non-retryable 403 errors from |
| 6 | +# CDN/proxy intermediaries during artifact finalization). |
| 7 | +# |
| 8 | +# This action handles: |
| 9 | +# - Step-level retry (3 attempts) to recover from non-retryable errors (e.g., 403) |
| 10 | +# - Escalating delays (10s, 30s) between retries for transient infrastructure issues |
| 11 | +# - overwrite: true on all attempts to handle partially-finalized artifacts |
| 12 | +# - ACTIONS_UPLOAD_RETRY_COUNT=3 for defense-in-depth against 5xx errors |
| 13 | +# - Configurable continue-on-error for critical vs non-critical artifacts |
| 14 | +# |
| 15 | +# Maintainer: @mrz1836 |
| 16 | +# |
| 17 | +# ------------------------------------------------------------------------------------ |
| 18 | + |
| 19 | +name: "Upload Artifact with Resilience" |
| 20 | +description: "Uploads GitHub Actions artifacts with step-level retry logic for transient infrastructure failures" |
| 21 | + |
| 22 | +inputs: |
| 23 | + artifact-name: |
| 24 | + description: "Name of the artifact (will be displayed in GitHub UI)" |
| 25 | + required: true |
| 26 | + artifact-path: |
| 27 | + description: "Path to the artifact file(s) to upload" |
| 28 | + required: true |
| 29 | + retention-days: |
| 30 | + description: "Number of days to retain the artifact (1-90 days)" |
| 31 | + required: false |
| 32 | + default: "7" |
| 33 | + if-no-files-found: |
| 34 | + description: "Behavior when no files match the path (warn, error, ignore)" |
| 35 | + required: false |
| 36 | + default: "ignore" |
| 37 | + compression-level: |
| 38 | + description: "Compression level for the artifact (0-9, 6 is default)" |
| 39 | + required: false |
| 40 | + default: "6" |
| 41 | + continue-on-error: |
| 42 | + description: "Continue workflow if all upload attempts fail (true for non-critical artifacts)" |
| 43 | + required: false |
| 44 | + default: "true" |
| 45 | + |
| 46 | +runs: |
| 47 | + using: "composite" |
| 48 | + steps: |
| 49 | + # ------------------------------------------------------------------ |
| 50 | + # Attempt 1 |
| 51 | + # ------------------------------------------------------------------ |
| 52 | + - name: "📤 Upload ${{ inputs.artifact-name }} (attempt 1)" |
| 53 | + id: attempt1 |
| 54 | + continue-on-error: true |
| 55 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 56 | + with: |
| 57 | + name: ${{ inputs.artifact-name }} |
| 58 | + path: ${{ inputs.artifact-path }} |
| 59 | + retention-days: ${{ inputs.retention-days }} |
| 60 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 61 | + compression-level: ${{ inputs.compression-level }} |
| 62 | + overwrite: true |
| 63 | + env: |
| 64 | + ACTIONS_UPLOAD_RETRY_COUNT: 3 |
| 65 | + |
| 66 | + # ------------------------------------------------------------------ |
| 67 | + # Delay before retry |
| 68 | + # ------------------------------------------------------------------ |
| 69 | + - name: "⏳ Wait before retry (${{ inputs.artifact-name }})" |
| 70 | + if: steps.attempt1.outcome == 'failure' |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + echo "::warning::Upload attempt 1 for '${{ inputs.artifact-name }}' failed, retrying in 10s..." |
| 74 | + sleep 10 |
| 75 | +
|
| 76 | + # ------------------------------------------------------------------ |
| 77 | + # Attempt 2 |
| 78 | + # ------------------------------------------------------------------ |
| 79 | + - name: "📤 Upload ${{ inputs.artifact-name }} (attempt 2)" |
| 80 | + id: attempt2 |
| 81 | + if: steps.attempt1.outcome == 'failure' |
| 82 | + continue-on-error: true |
| 83 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 84 | + with: |
| 85 | + name: ${{ inputs.artifact-name }} |
| 86 | + path: ${{ inputs.artifact-path }} |
| 87 | + retention-days: ${{ inputs.retention-days }} |
| 88 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 89 | + compression-level: ${{ inputs.compression-level }} |
| 90 | + overwrite: true |
| 91 | + env: |
| 92 | + ACTIONS_UPLOAD_RETRY_COUNT: 3 |
| 93 | + |
| 94 | + # ------------------------------------------------------------------ |
| 95 | + # Delay before final retry |
| 96 | + # ------------------------------------------------------------------ |
| 97 | + - name: "⏳ Wait before final retry (${{ inputs.artifact-name }})" |
| 98 | + if: steps.attempt1.outcome == 'failure' && steps.attempt2.outcome == 'failure' |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + echo "::warning::Upload attempt 2 for '${{ inputs.artifact-name }}' failed, retrying in 30s..." |
| 102 | + sleep 30 |
| 103 | +
|
| 104 | + # ------------------------------------------------------------------ |
| 105 | + # Attempt 3 (final -- continue-on-error depends on criticality input) |
| 106 | + # ------------------------------------------------------------------ |
| 107 | + - name: "📤 Upload ${{ inputs.artifact-name }} (attempt 3 - final)" |
| 108 | + id: attempt3 |
| 109 | + if: steps.attempt1.outcome == 'failure' && steps.attempt2.outcome == 'failure' |
| 110 | + continue-on-error: ${{ inputs.continue-on-error == 'true' }} |
| 111 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 112 | + with: |
| 113 | + name: ${{ inputs.artifact-name }} |
| 114 | + path: ${{ inputs.artifact-path }} |
| 115 | + retention-days: ${{ inputs.retention-days }} |
| 116 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 117 | + compression-level: ${{ inputs.compression-level }} |
| 118 | + overwrite: true |
| 119 | + env: |
| 120 | + ACTIONS_UPLOAD_RETRY_COUNT: 3 |
0 commit comments