clean up artifacts after deployment

This commit is contained in:
Martin Raifer 2023-02-25 16:30:37 +01:00
parent e8e6c787e6
commit 090d5f5555
No known key found for this signature in database
GPG key ID: 3CD561F7B1C461BD

View file

@ -33,7 +33,7 @@ jobs:
artifact => artifact.name === 'pr'
)[0];
if (!artifact) {
throw new Error('No pr artifact found');
throw new Error('No "pr" artifact found');
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
@ -83,3 +83,25 @@ jobs:
} else {
console.log(`Preview URL comment already added to PR #${pullRequestNumber}`);
}
- name: Clean up artifact
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id}}
});
const artifact = artifacts.data.artifacts.filter(
artifact => artifact.name === 'preview'
)[0];
if (!artifact) {
throw new Error('No "preview" artifact found');
}
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});