Skip to content

Commit b3b8e13

Browse files
committed
fix(ci): prune duplicate github-pages artifacts before deploy
upload-pages-artifact@v3 occasionally uploads the same artifact multiple times in a single run on transient network hiccups, which then makes deploy-pages@v4 fail with 'Multiple artifacts named github-pages'. Prune step keeps the newest, deletes the rest.
1 parent 75d9553 commit b3b8e13

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.github/workflows/deploy-website.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,37 @@ jobs:
5050
url: ${{ steps.deployment.outputs.page_url }}
5151
needs: build
5252
runs-on: ubuntu-latest
53+
permissions:
54+
contents: read
55+
pages: write
56+
id-token: write
57+
actions: write
5358
steps:
59+
# Work around actions/upload-pages-artifact@v3 bug where transient
60+
# network hiccups during upload can produce >1 artifact named
61+
# "github-pages" in a single run, which then makes deploy-pages@v4
62+
# fail with "Multiple artifacts named 'github-pages'". Delete all
63+
# but the most recent before deploying.
64+
- name: Prune duplicate github-pages artifacts
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
RUN_ID: ${{ github.run_id }}
68+
REPO: ${{ github.repository }}
69+
run: |
70+
set -euo pipefail
71+
artifacts=$(gh api "/repos/$REPO/actions/runs/$RUN_ID/artifacts" \
72+
--jq '[.artifacts[] | select(.name == "github-pages")] | sort_by(.created_at) | reverse')
73+
count=$(echo "$artifacts" | jq 'length')
74+
echo "Found $count github-pages artifact(s) in this run."
75+
if [ "$count" -le 1 ]; then
76+
exit 0
77+
fi
78+
# Keep index 0 (newest); delete the rest.
79+
echo "$artifacts" | jq -r '.[1:] | .[].id' | while read -r id; do
80+
echo "Deleting duplicate artifact $id"
81+
gh api -X DELETE "/repos/$REPO/actions/artifacts/$id"
82+
done
83+
5484
- name: Deploy to GitHub Pages
5585
id: deployment
5686
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)