|
| 1 | +name: "Upload Artifacts" |
| 2 | +description: "Upload a small, arbitrary number of artifacts." |
| 3 | + |
| 4 | +inputs: |
| 5 | + artifacts: |
| 6 | + description: "JSCN array objects produced via ci/util/artifacts/upload/print_matrix.sh. Each object must include 'name', 'path', 'retention_days', and 'compression_level'." |
| 7 | + required: true |
| 8 | + |
| 9 | +runs: |
| 10 | + using: "composite" |
| 11 | + steps: |
| 12 | + - name: Parse artifact array |
| 13 | + id: parse |
| 14 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 15 | + run: | |
| 16 | + # Save artifacts json for parsing: |
| 17 | + jq -r '.' <<< '${{ inputs.artifacts }}' > artifacts.json |
| 18 | +
|
| 19 | + echo "::group::List of artifacts to upload" |
| 20 | + cat artifacts.json |
| 21 | + echo "::endgroup::" |
| 22 | +
|
| 23 | + max_artifacts=10 |
| 24 | +
|
| 25 | + count=$(jq '. | length' artifacts.json) |
| 26 | + if [ "$count" -gt "$max_artifacts" ]; then |
| 27 | + echo "Error: Too many artifacts to upload. Maximum is $max_artifacts, got $count." |
| 28 | + echo "Update the action to support more artifacts if needed." |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +
|
| 32 | + for i in $(seq 0 $((count - 1))); do |
| 33 | + name=$(jq -r ".[$i].name" artifacts.json) |
| 34 | + path=$(jq -r ".[$i].path" artifacts.json) |
| 35 | + retention_days=$(jq -r ".[$i].retention_days" artifacts.json) |
| 36 | + compression_level=$(jq -r ".[$i].compression_level" artifacts.json) |
| 37 | +
|
| 38 | + echo "enabled$i=true" >> "${GITHUB_OUTPUT}" |
| 39 | + echo "name$i=$name" >> "${GITHUB_OUTPUT}" |
| 40 | + echo "path$i=$path" >> "${GITHUB_OUTPUT}" |
| 41 | + echo "retention_days$i=$retention_days" >> "${GITHUB_OUTPUT}" |
| 42 | + echo "compression_level$i=$compression_level" >> "${GITHUB_OUTPUT}" |
| 43 | + done |
| 44 | +
|
| 45 | + for i in $(seq $((count)) $((max_artifacts - 1))); do |
| 46 | + echo "enabled$i=false" >> "${GITHUB_OUTPUT}" |
| 47 | + echo "name$i=" >> "${GITHUB_OUTPUT}" |
| 48 | + echo "path$i=" >> "${GITHUB_OUTPUT}" |
| 49 | + echo "retention_days$i=" >> "${GITHUB_OUTPUT}" |
| 50 | + echo "compression_level$i=" >> "${GITHUB_OUTPUT}" |
| 51 | + done |
| 52 | +
|
| 53 | + - name: Upload artifact 0 |
| 54 | + if: ${{ steps.parse.outputs.enabled0 == 'true' }} |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: ${{ steps.parse.outputs.name0 }} |
| 58 | + path: ${{ steps.parse.outputs.path0 }} |
| 59 | + retention-days: ${{ steps.parse.outputs.retention_days0 }} |
| 60 | + compression-level: ${{ steps.parse.outputs.compression_level0 }} |
| 61 | + - name: Upload artifact 1 |
| 62 | + if: ${{ steps.parse.outputs.enabled1 == 'true' }} |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: ${{ steps.parse.outputs.name1 }} |
| 66 | + path: ${{ steps.parse.outputs.path1 }} |
| 67 | + retention-days: ${{ steps.parse.outputs.retention_days1 }} |
| 68 | + compression-level: ${{ steps.parse.outputs.compression_level1 }} |
| 69 | + - name: Upload artifact 2 |
| 70 | + if: ${{ steps.parse.outputs.enabled2 == 'true' }} |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: ${{ steps.parse.outputs.name2 }} |
| 74 | + path: ${{ steps.parse.outputs.path2 }} |
| 75 | + retention-days: ${{ steps.parse.outputs.retention_days2 }} |
| 76 | + compression-level: ${{ steps.parse.outputs.compression_level2 }} |
| 77 | + - name: Upload artifact 3 |
| 78 | + if: ${{ steps.parse.outputs.enabled3 == 'true' }} |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: ${{ steps.parse.outputs.name3 }} |
| 82 | + path: ${{ steps.parse.outputs.path3 }} |
| 83 | + retention-days: ${{ steps.parse.outputs.retention_days3 }} |
| 84 | + compression-level: ${{ steps.parse.outputs.compression_level3 }} |
| 85 | + - name: Upload artifact 4 |
| 86 | + if: ${{ steps.parse.outputs.enabled4 == 'true' }} |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: ${{ steps.parse.outputs.name4 }} |
| 90 | + path: ${{ steps.parse.outputs.path4 }} |
| 91 | + retention-days: ${{ steps.parse.outputs.retention_days4 }} |
| 92 | + compression-level: ${{ steps.parse.outputs.compression_level4 }} |
| 93 | + - name: Upload artifact 5 |
| 94 | + if: ${{ steps.parse.outputs.enabled5 == 'true' }} |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: ${{ steps.parse.outputs.name5 }} |
| 98 | + path: ${{ steps.parse.outputs.path5 }} |
| 99 | + retention-days: ${{ steps.parse.outputs.retention_days5 }} |
| 100 | + compression-level: ${{ steps.parse.outputs.compression_level5 }} |
| 101 | + - name: Upload artifact 6 |
| 102 | + if: ${{ steps.parse.outputs.enabled6 == 'true' }} |
| 103 | + uses: actions/upload-artifact@v4 |
| 104 | + with: |
| 105 | + name: ${{ steps.parse.outputs.name6 }} |
| 106 | + path: ${{ steps.parse.outputs.path6 }} |
| 107 | + retention-days: ${{ steps.parse.outputs.retention_days6 }} |
| 108 | + compression-level: ${{ steps.parse.outputs.compression_level6 }} |
| 109 | + - name: Upload artifact 7 |
| 110 | + if: ${{ steps.parse.outputs.enabled7 == 'true' }} |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: ${{ steps.parse.outputs.name7 }} |
| 114 | + path: ${{ steps.parse.outputs.path7 }} |
| 115 | + retention-days: ${{ steps.parse.outputs.retention_days7 }} |
| 116 | + compression-level: ${{ steps.parse.outputs.compression_level7 }} |
| 117 | + - name: Upload artifact 8 |
| 118 | + if: ${{ steps.parse.outputs.enabled8 == 'true' }} |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: ${{ steps.parse.outputs.name8 }} |
| 122 | + path: ${{ steps.parse.outputs.path8 }} |
| 123 | + retention-days: ${{ steps.parse.outputs.retention_days8 }} |
| 124 | + compression-level: ${{ steps.parse.outputs.compression_level8 }} |
| 125 | + - name: Upload artifact 9 |
| 126 | + if: ${{ steps.parse.outputs.enabled9 == 'true' }} |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: ${{ steps.parse.outputs.name9 }} |
| 130 | + path: ${{ steps.parse.outputs.path9 }} |
| 131 | + retention-days: ${{ steps.parse.outputs.retention_days9 }} |
| 132 | + compression-level: ${{ steps.parse.outputs.compression_level9 }} |
0 commit comments