Skip to content

Commit 3caf501

Browse files
zzambersPaul Hohensee
authored and
Paul Hohensee
committed
8336928: GHA: Bundle artifacts removal broken
Backport-of: 98562166e4a4c8921709014423c6cbc993aa0d97
1 parent d8632ed commit 3caf501

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
@@ -333,26 +333,23 @@ jobs:
333333
- test-windows-x64
334334

335335
steps:
336-
# Hack to get hold of the api environment variables that are only defined for actions
337-
- name: 'Get API configuration'
338-
id: api
339-
uses: actions/github-script@v7
340-
with:
341-
script: 'return { url: process.env["ACTIONS_RUNTIME_URL"], token: process.env["ACTIONS_RUNTIME_TOKEN"] }'
342-
343336
- name: 'Remove bundle artifacts'
344337
run: |
345338
# Find and remove all bundle artifacts
346-
ALL_ARTIFACT_URLS="$(curl -s \
347-
-H 'Accept: application/json;api-version=6.0-preview' \
348-
-H 'Authorization: Bearer ${{ fromJson(steps.api.outputs.result).token }}' \
349-
'${{ fromJson(steps.api.outputs.result).url }}_apis/pipelines/workflows/${{ github.run_id }}/artifacts?api-version=6.0-preview')"
350-
BUNDLE_ARTIFACT_URLS="$(echo "$ALL_ARTIFACT_URLS" | jq -r -c '.value | map(select(.name|startswith("bundles-"))) | .[].url')"
351-
for url in $BUNDLE_ARTIFACT_URLS; do
352-
echo "Removing $url"
353-
curl -s \
354-
-H 'Accept: application/json;api-version=6.0-preview' \
355-
-H 'Authorization: Bearer ${{ fromJson(steps.api.outputs.result).token }}' \
356-
-X DELETE "$url" \
339+
# See: https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28
340+
ALL_ARTIFACT_IDS="$(curl -sL \
341+
-H 'Accept: application/vnd.github+json' \
342+
-H 'Authorization: Bearer ${{ github.token }}' \
343+
-H 'X-GitHub-Api-Version: 2022-11-28' \
344+
'${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts')"
345+
BUNDLE_ARTIFACT_IDS="$(echo "$ALL_ARTIFACT_IDS" | jq -r -c '.artifacts | map(select(.name|startswith("bundles-"))) | .[].id')"
346+
for id in $BUNDLE_ARTIFACT_IDS; do
347+
echo "Removing $id"
348+
curl -sL \
349+
-X DELETE \
350+
-H 'Accept: application/vnd.github+json' \
351+
-H 'Authorization: Bearer ${{ github.token }}' \
352+
-H 'X-GitHub-Api-Version: 2022-11-28' \
353+
"${{ github.api_url }}/repos/${{ github.repository }}/actions/artifacts/$id" \
357354
|| echo "Failed to remove bundle"
358355
done

0 commit comments

Comments
 (0)