PR Preview Cleanup #725
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
# Github action to cleanup a PR preview | |
# Runs on dispatch or weekly schedule and deletes closed PR previews that are older than 7 days | |
# | |
name: PR Preview Cleanup | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 3 * * 1" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout gh-pages | |
uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
- name: Iterate and Check PRs | |
id: pr_check | |
run: | | |
pr_folders=($(cd pr && ls -d */)) | |
closed_pr=() | |
for pr_folder in "${pr_folders[@]}"; do | |
pr_status=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-X GET "https://api.github.com/repos/${{ github.repository }}/pulls/${pr_folder::-1}" \ | |
| jq -r '.state') | |
echo "PR ${pr_folder::-1} is $pr_status" | |
if [ "$pr_status" != "open" ]; then | |
rm -rf "pr/${pr_folder::-1}" | |
closed_pr+=("${pr_folder::-1}") | |
echo "Removed folder pr/${pr_folder::-1} for closed PR ${pr_folder::-1}" | |
fi | |
done | |
echo "${closed_pr[*]}" >> $GITHUB_STATE | |
- name: Commit and push to gh-pages | |
uses: EndBug/[email protected] | |
with: | |
committer_email: [email protected] | |
committer_name: Fortran | |
message: "Sphinx build cleanup pr/${{ steps.pr_check.outputs.closed_pr }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |