Skip to content

Make PR preview cleanup idempotent #84

Description

@ANonABento

Problem

.github/workflows/pr-clean-up.yml assumes the preview folder exists and that deleting it always creates a commit:

rm -r './previews/pr-${{ github.event.pull_request.number }}'
git commit -am "Delete preview for PR #${{ github.event.pull_request.number }}"

If a PR never deployed a preview, the folder was already removed, or the folder path changes, rm -r fails. If there are no tracked changes after deletion, git commit -am fails. Either case can make the cleanup workflow report a failure even though there is nothing left to clean.

Suggested fix

  • Use rm -rf or explicitly check whether the preview directory exists.
  • Use git status --porcelain before committing and skip the commit/push when there are no changes.
  • Consider using pinned SHAs for the unpinned actions/checkout@v3 step while touching the workflow.

Relevant file

  • .github/workflows/pr-clean-up.yml

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions