|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: "Upload Artifact (with retry)" |
| 19 | +description: > |
| 20 | + Drop-in replacement for actions/upload-artifact that retries the upload three |
| 21 | + times. The artifact client only retries 429/500/502/503/504, so a |
| 22 | + FinalizeArtifact answered "(403) Forbidden: Error from intermediary" fails the |
| 23 | + step even though the content uploaded fine. There is no input to widen that |
| 24 | + list, Actions has no built-in step retry, and third-party retry wrappers are |
| 25 | + not on the Apache allowed-actions list. See .github/workflows/README.md. |
| 26 | +
|
| 27 | + Retries force overwrite, which deletes the newest artifact carrying the name |
| 28 | + before re-uploading. `name` must therefore identify exactly one producer in |
| 29 | + the run: a reusable workflow ci.yml calls more than once has to qualify the |
| 30 | + name with its version inputs. dev/ci/check-ci-config.py enforces that. |
| 31 | +
|
| 32 | +# Inputs mirror actions/upload-artifact@v7 one for one. The boolean defaults |
| 33 | +# have to be real 'true'/'false' strings because core.getBooleanInput() throws |
| 34 | +# on an empty value; the numeric ones default to '' so "unset" round-trips. |
| 35 | +inputs: |
| 36 | + name: |
| 37 | + description: 'Artifact name' |
| 38 | + required: false |
| 39 | + default: 'artifact' |
| 40 | + path: |
| 41 | + description: 'A file, directory or wildcard pattern that describes what to upload' |
| 42 | + required: true |
| 43 | + if-no-files-found: |
| 44 | + description: "Behavior if no files are found: warn, error or ignore" |
| 45 | + required: false |
| 46 | + default: 'warn' |
| 47 | + retention-days: |
| 48 | + description: 'Days before the artifact expires (empty means repository default)' |
| 49 | + required: false |
| 50 | + default: '' |
| 51 | + compression-level: |
| 52 | + description: 'Zlib compression level 0-9 (empty means the action default)' |
| 53 | + required: false |
| 54 | + default: '' |
| 55 | + overwrite: |
| 56 | + description: 'Delete an existing artifact with the same name before uploading' |
| 57 | + required: false |
| 58 | + default: 'false' |
| 59 | + include-hidden-files: |
| 60 | + description: 'Include hidden files in the artifact' |
| 61 | + required: false |
| 62 | + default: 'false' |
| 63 | + archive: |
| 64 | + description: 'Zip the content before uploading' |
| 65 | + required: false |
| 66 | + default: 'true' |
| 67 | + |
| 68 | +# `||` yields the first non-empty operand, so this picks whichever attempt ran. |
| 69 | +outputs: |
| 70 | + artifact-id: |
| 71 | + description: 'ID of the uploaded artifact' |
| 72 | + value: ${{ steps.attempt-1.outputs.artifact-id || steps.attempt-2.outputs.artifact-id || steps.attempt-3.outputs.artifact-id }} |
| 73 | + artifact-url: |
| 74 | + description: 'Download URL of the uploaded artifact' |
| 75 | + value: ${{ steps.attempt-1.outputs.artifact-url || steps.attempt-2.outputs.artifact-url || steps.attempt-3.outputs.artifact-url }} |
| 76 | + artifact-digest: |
| 77 | + description: 'SHA-256 digest of the uploaded artifact' |
| 78 | + value: ${{ steps.attempt-1.outputs.artifact-digest || steps.attempt-2.outputs.artifact-digest || steps.attempt-3.outputs.artifact-digest }} |
| 79 | + |
| 80 | +runs: |
| 81 | + using: "composite" |
| 82 | + steps: |
| 83 | + # continue-on-error keeps a failed attempt from failing the job while still |
| 84 | + # recording outcome == 'failure', which the later attempts gate on. The last |
| 85 | + # attempt omits it so a genuinely broken upload still fails loudly. |
| 86 | + - name: Upload ${{ inputs.name }} (attempt 1 of 3) |
| 87 | + id: attempt-1 |
| 88 | + uses: actions/upload-artifact@v7 |
| 89 | + continue-on-error: true |
| 90 | + with: |
| 91 | + name: ${{ inputs.name }} |
| 92 | + path: ${{ inputs.path }} |
| 93 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 94 | + retention-days: ${{ inputs.retention-days }} |
| 95 | + compression-level: ${{ inputs.compression-level }} |
| 96 | + overwrite: ${{ inputs.overwrite }} |
| 97 | + include-hidden-files: ${{ inputs.include-hidden-files }} |
| 98 | + archive: ${{ inputs.archive }} |
| 99 | + |
| 100 | + - name: Wait before retrying ${{ inputs.name }} |
| 101 | + if: ${{ steps.attempt-1.outcome == 'failure' }} |
| 102 | + shell: bash |
| 103 | + run: | |
| 104 | + echo "::warning::Upload of '${{ inputs.name }}' failed; retrying in 15s (attempt 2 of 3)." |
| 105 | + sleep 15 |
| 106 | +
|
| 107 | + # Retries force overwrite: attempt 1 may have created the server-side record |
| 108 | + # before failing, and CreateArtifact rejects a duplicate name. The delete is |
| 109 | + # best effort inside upload-artifact, so it no-ops when nothing exists, and |
| 110 | + # the per-producer naming rule keeps the record it does find our own. |
| 111 | + - name: Upload ${{ inputs.name }} (attempt 2 of 3) |
| 112 | + id: attempt-2 |
| 113 | + if: ${{ steps.attempt-1.outcome == 'failure' }} |
| 114 | + uses: actions/upload-artifact@v7 |
| 115 | + continue-on-error: true |
| 116 | + with: |
| 117 | + name: ${{ inputs.name }} |
| 118 | + path: ${{ inputs.path }} |
| 119 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 120 | + retention-days: ${{ inputs.retention-days }} |
| 121 | + compression-level: ${{ inputs.compression-level }} |
| 122 | + overwrite: 'true' |
| 123 | + include-hidden-files: ${{ inputs.include-hidden-files }} |
| 124 | + archive: ${{ inputs.archive }} |
| 125 | + |
| 126 | + - name: Wait before final retry of ${{ inputs.name }} |
| 127 | + if: ${{ steps.attempt-1.outcome == 'failure' && steps.attempt-2.outcome == 'failure' }} |
| 128 | + shell: bash |
| 129 | + run: | |
| 130 | + echo "::warning::Upload of '${{ inputs.name }}' failed again; retrying in 45s (attempt 3 of 3)." |
| 131 | + sleep 45 |
| 132 | +
|
| 133 | + - name: Upload ${{ inputs.name }} (attempt 3 of 3) |
| 134 | + id: attempt-3 |
| 135 | + if: ${{ steps.attempt-1.outcome == 'failure' && steps.attempt-2.outcome == 'failure' }} |
| 136 | + uses: actions/upload-artifact@v7 |
| 137 | + with: |
| 138 | + name: ${{ inputs.name }} |
| 139 | + path: ${{ inputs.path }} |
| 140 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 141 | + retention-days: ${{ inputs.retention-days }} |
| 142 | + compression-level: ${{ inputs.compression-level }} |
| 143 | + overwrite: 'true' |
| 144 | + include-hidden-files: ${{ inputs.include-hidden-files }} |
| 145 | + archive: ${{ inputs.archive }} |
0 commit comments