Skip to content

Clean gh-pages branch #193

Clean gh-pages branch

Clean gh-pages branch #193

name: Clean gh-pages branch
on:
schedule:
- cron: '0 0 * * *' # Every day at midnight
workflow_dispatch:
jobs:
clean-gh-pages:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v6
with:
ref: gh-pages
- name: Install gh CLI
run: |
sudo apt-get install gh -y
# TODO: remove this step once we have full migrated to the dev server
- name: Remove dirs in _vitest, _playwright, etc. for PRs that are no longer open
env:
REPO_PR_URL: ${{ github.event.repository.html_url }}/pull
GH_TOKEN: ${{ github.token }}
run: |
open_prs=$(gh pr list --state open --json number --jq '.[].number')
echo Open PRs: $open_prs
for dir in _nodemodules _vitest _playwright _coverage _pullrequests; do
echo Checking $dir
for pr in $dir/*; do
number=$(basename "$pr" | sed 's/^pr-//')
if ! echo "$open_prs" | grep -q "$number"; then
echo "Removing $pr, $number does not match any open PR: $REPO_PR_URL/$number"
rm -rf "$pr"
else
echo "Keeping $pr as $number is still open: $REPO_PR_URL/$number"
fi
done
done
- name: Collapse branch history and push
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "github-actions@github.com"
git checkout --orphan flattened
git add -A
git commit -m "Clean up gh-pages branch"
git branch -M gh-pages
git push -f origin gh-pages