Skip to content

Commit 2e9152d

Browse files
zzambersPaul Hohensee
authored and
Paul Hohensee
committed
8336928: GHA: Bundle artifacts removal broken
Backport-of: 98562166e4a4c8921709014423c6cbc993aa0d97
1 parent 4aa7950 commit 2e9152d

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
@@ -344,26 +344,23 @@ jobs:
344344
- test-windows-x64
345345

346346
steps:
347-
# Hack to get hold of the api environment variables that are only defined for actions
348-
- name: 'Get API configuration'
349-
id: api
350-
uses: actions/github-script@v7
351-
with:
352-
script: 'return { url: process.env["ACTIONS_RUNTIME_URL"], token: process.env["ACTIONS_RUNTIME_TOKEN"] }'
353-
354347
- name: 'Remove bundle artifacts'
355348
run: |
356349
# Find and remove all bundle artifacts
357-
ALL_ARTIFACT_URLS="$(curl -s \
358-
-H 'Accept: application/json;api-version=6.0-preview' \
359-
-H 'Authorization: Bearer ${{ fromJson(steps.api.outputs.result).token }}' \
360-
'${{ fromJson(steps.api.outputs.result).url }}_apis/pipelines/workflows/${{ github.run_id }}/artifacts?api-version=6.0-preview')"
361-
BUNDLE_ARTIFACT_URLS="$(echo "$ALL_ARTIFACT_URLS" | jq -r -c '.value | map(select(.name|startswith("bundles-"))) | .[].url')"
362-
for url in $BUNDLE_ARTIFACT_URLS; do
363-
echo "Removing $url"
364-
curl -s \
365-
-H 'Accept: application/json;api-version=6.0-preview' \
366-
-H 'Authorization: Bearer ${{ fromJson(steps.api.outputs.result).token }}' \
367-
-X DELETE "$url" \
350+
# See: https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28
351+
ALL_ARTIFACT_IDS="$(curl -sL \
352+
-H 'Accept: application/vnd.github+json' \
353+
-H 'Authorization: Bearer ${{ github.token }}' \
354+
-H 'X-GitHub-Api-Version: 2022-11-28' \
355+
'${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts')"
356+
BUNDLE_ARTIFACT_IDS="$(echo "$ALL_ARTIFACT_IDS" | jq -r -c '.artifacts | map(select(.name|startswith("bundles-"))) | .[].id')"
357+
for id in $BUNDLE_ARTIFACT_IDS; do
358+
echo "Removing $id"
359+
curl -sL \
360+
-X DELETE \
361+
-H 'Accept: application/vnd.github+json' \
362+
-H 'Authorization: Bearer ${{ github.token }}' \
363+
-H 'X-GitHub-Api-Version: 2022-11-28' \
364+
"${{ github.api_url }}/repos/${{ github.repository }}/actions/artifacts/$id" \
368365
|| echo "Failed to remove bundle"
369366
done

0 commit comments

Comments
 (0)