Deletes the documentation preview of a closed pull request. The
docs-preview-cleanup.yml workflow runs it when a pull request closes, on the
default branch's copy of the script, so no pull request content runs with the
cleanup role.
It has two actions:
eligibilityreads the pull request withgh api, which needsGH_TOKEN, and appendsshould_cleanup=trueto the file named by--github-outputwhen the pull request is closed. A closed event can be rerun after the pull request reopens, so the workflow reads the state again before it assumes the cleanup role. The script writesshould_cleanup=falsefirst and exits 1 when the number is not a positive integer or the response is not the pull request asked for, with a state other than open or closed.deleterunsaws s3 rmons3://<bucket>/en/elixir/pr-<number>/with--recursive, after the same number check.
$ elixir scripts/docs_preview_cleanup/docs_preview_cleanup.exs \
eligibility \
--repository libtmux/libtmux-elixir \
--pr 12 \
--github-output "$(mktemp)"
Tests
tests/docs_preview_cleanup_test.exs accepts a closed pull request and an open
one, refuses each malformed response and number, checks the preview prefix, and
runs the command line on a non-numeric number to see it exit 1 before it calls
gh or aws. The two calls run in CI when a pull request closes.
$ elixir scripts/docs_preview_cleanup/tests/docs_preview_cleanup_test.exs