diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 473b2802..0cc53117 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -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 + });