| 1 |
name: 'Merge Artifacts' |
| 2 |
description: 'Merge Artifacts' |
| 3 |
inputs: |
| 4 |
target_name: |
| 5 |
description: 'The name of the result artifact' |
| 6 |
required: true |
| 7 |
source_paths: |
| 8 |
description: 'The path to the files that will be uplaoded' |
| 9 |
required: true |
| 10 |
source_name_pattern: |
| 11 |
description: "Artifact's pattern to be merged" |
| 12 |
required: true |
| 13 |
github_token: |
| 14 |
description: 'The Github Token to use' |
| 15 |
required: true |
| 16 |
|
| 17 |
runs: |
| 18 |
using: 'composite' |
| 19 |
steps: |
| 20 |
- name: Download Artifacts |
| 21 |
uses: actions/download-artifact@f44cd7b40bfd40b6aa1cc1b9b5b7bf03d3c67110 |
| 22 |
with: |
| 23 |
pattern: ${{ inputs.source_name_pattern }}* |
| 24 |
path: ${{ inputs.target_name }} |
| 25 |
merge-multiple: true |
| 26 |
|
| 27 |
- name: Upload the Regrouped Artifact |
| 28 |
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b |
| 29 |
with: |
| 30 |
name: ${{ inputs.target_name }} |
| 31 |
path: | |
| 32 |
${{ inputs.source_paths }} |
| 33 |
retention-days: 1 |
| 34 |
|
| 35 |
- name: Delete Artifacts |
| 36 |
run: | |
| 37 |
artifact_pattern="${{ inputs.source_name_pattern }}" |
| 38 |
TOKEN="${{ inputs.github_token }}" |
| 39 |
artifact_exists=true |
| 40 |
while [ "$artifact_exists" = true ]; do |
| 41 |
artifact_exists=false |
| 42 |
artifacts_response=$(curl -L \ |
| 43 |
-H "Accept: application/vnd.github+json" \ |
| 44 |
-H "Authorization: Bearer $TOKEN" \ |
| 45 |
-H "X-GitHub-Api-Version: 2022-11-28" \ |
| 46 |
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100") |
| 47 |
artifacts=$(echo $artifacts_response | jq -c '.artifacts[]') |
| 48 |
echo "Those are the artifacts : $artifacts" |
| 49 |
while read row; do |
| 50 |
artifact_name=$(echo "$row" | jq -r '.name') |
| 51 |
if [[ "$artifact_name" =~ ^.*"$artifact_pattern".* ]]; then |
| 52 |
artifact_exists=true |
| 53 |
echo "Deleting : $artifact_name" |
| 54 |
artifact_id=$(echo "$row" | jq -r '.id') |
| 55 |
curl -L \ |
| 56 |
-X DELETE \ |
| 57 |
-H "Accept: application/vnd.github+json" \ |
| 58 |
-H "Authorization: Bearer $TOKEN" \ |
| 59 |
-H "X-GitHub-Api-Version: 2022-11-28" \ |
| 60 |
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${artifact_id}" |
| 61 |
fi |
| 62 |
done <<< "$artifacts" |
| 63 |
done |
| 64 |
echo "End of Deleting" |
| 65 |
shell: bash |