Cleanup artifacts #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cleanup artifacts | |
on: | |
workflow_call: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
hardening: | |
name: Harden runner | |
uses: ./.github/workflows/hardening.yaml | |
cleanup: | |
permissions: | |
# Required to delete artifact, otherwise you'll get | |
# "Error: Resource not accessible by integration" | |
contents: write | |
name: Run Tests | |
needs: hardening | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete Old Artifacts | |
uses: actions/github-script@v6 | |
id: artifact | |
with: | |
script: | | |
const res = await github.rest.actions.listArtifactsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}) | |
res.data.artifacts | |
.forEach(({ id }) => { | |
github.rest.actions.deleteArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: id, | |
}) | |
}) |