Skip to content

Commit 123614b

Browse files
zzambersPaul Hohensee
authored and
Paul Hohensee
committed
8336928: GHA: Bundle artifacts removal broken
Backport-of: 98562166e4a4c8921709014423c6cbc993aa0d97
1 parent 9ac591a commit 123614b

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

.github/workflows/main.yml

+15-18
Original file line numberDiff line numberDiff line change
@@ -362,26 +362,23 @@ jobs:
362362
- test-windows-x64
363363

364364
steps:
365-
# Hack to get hold of the api environment variables that are only defined for actions
366-
- name: 'Get API configuration'
367-
id: api
368-
uses: actions/github-script@v7
369-
with:
370-
script: 'return { url: process.env["ACTIONS_RUNTIME_URL"], token: process.env["ACTIONS_RUNTIME_TOKEN"] }'
371-
372365
- name: 'Remove bundle artifacts'
373366
run: |
374367
# Find and remove all bundle artifacts
375-
ALL_ARTIFACT_URLS="$(curl -s \
376-
-H 'Accept: application/json;api-version=6.0-preview' \
377-
-H 'Authorization: Bearer ${{ fromJson(steps.api.outputs.result).token }}' \
378-
'${{ fromJson(steps.api.outputs.result).url }}_apis/pipelines/workflows/${{ github.run_id }}/artifacts?api-version=6.0-preview')"
379-
BUNDLE_ARTIFACT_URLS="$(echo "$ALL_ARTIFACT_URLS" | jq -r -c '.value | map(select(.name|startswith("bundles-"))) | .[].url')"
380-
for url in $BUNDLE_ARTIFACT_URLS; do
381-
echo "Removing $url"
382-
curl -s \
383-
-H 'Accept: application/json;api-version=6.0-preview' \
384-
-H 'Authorization: Bearer ${{ fromJson(steps.api.outputs.result).token }}' \
385-
-X DELETE "$url" \
368+
# See: https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28
369+
ALL_ARTIFACT_IDS="$(curl -sL \
370+
-H 'Accept: application/vnd.github+json' \
371+
-H 'Authorization: Bearer ${{ github.token }}' \
372+
-H 'X-GitHub-Api-Version: 2022-11-28' \
373+
'${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts')"
374+
BUNDLE_ARTIFACT_IDS="$(echo "$ALL_ARTIFACT_IDS" | jq -r -c '.artifacts | map(select(.name|startswith("bundles-"))) | .[].id')"
375+
for id in $BUNDLE_ARTIFACT_IDS; do
376+
echo "Removing $id"
377+
curl -sL \
378+
-X DELETE \
379+
-H 'Accept: application/vnd.github+json' \
380+
-H 'Authorization: Bearer ${{ github.token }}' \
381+
-H 'X-GitHub-Api-Version: 2022-11-28' \
382+
"${{ github.api_url }}/repos/${{ github.repository }}/actions/artifacts/$id" \
386383
|| echo "Failed to remove bundle"
387384
done

0 commit comments

Comments
 (0)