fix(workflow): Fix delete-old-artifacts failed

This commit is contained in:
xuxin
2025-08-08 17:47:41 +08:00
parent 21f18d4bd9
commit c4eb278f6e
@@ -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]