From c4eb278f6e0bf2a786e4d966d9a672d3eadbb44f Mon Sep 17 00:00:00 2001 From: xuxin Date: Fri, 8 Aug 2025 17:47:41 +0800 Subject: [PATCH] fix(workflow): Fix delete-old-artifacts failed --- .../build-examples-gh-pages-on-push.yml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-examples-gh-pages-on-push.yml b/.github/workflows/build-examples-gh-pages-on-push.yml index a1a61e1..81c3b96 100644 --- a/.github/workflows/build-examples-gh-pages-on-push.yml +++ b/.github/workflows/build-examples-gh-pages-on-push.yml @@ -37,10 +37,32 @@ jobs: delete-old-artifacts: runs-on: ubuntu-latest steps: - - name: Delete old artifacts - uses: geekyeggo/delete-artifact@v2 + - name: List and Delete artifacts + uses: actions/github-script@v7 with: - name: build-images-* # Delete all artifacts with name starting with build-images- + script: | + const artifacts = await github.rest.actions.listArtifactsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + + console.log('Found artifacts:', artifacts.data.artifacts.map(a => a.name)); + + for (const artifact of artifacts.data.artifacts) { + if (artifact.name.startsWith('build-images-')) { + console.log(`Deleting artifact: ${artifact.name}`); + try { + await github.rest.actions.deleteArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: artifact.id, + }); + console.log(`Successfully deleted: ${artifact.name}`); + } catch (error) { + console.log(`Failed to delete ${artifact.name}:`, error.message); + } + } + } job1: needs: [delete-old-artifacts]