update workflows #2
Workflow file for this run
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
name: Cleanup PR Previews | |
on: | |
pull_request: | |
types: | |
- closed # Trigger when a PR is closed (merged or not) | |
jobs: | |
cleanup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Ensure full history and all branches are fetched | |
- name: Configure Git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Delete PR preview folder | |
run: | | |
pr_number=${{ github.event.pull_request.number }} | |
branch=gh-pages | |
# Fetch the gh-pages branch | |
git fetch origin $branch | |
git checkout $branch | |
# Remove the pr-<PR_NUMBER> folder | |
if [ -d "pr-$pr_number" ]; then | |
git rm -r --cached "pr-$pr_number" | |
rm -rf "pr-$pr_number" | |
git commit -m "Remove PR preview for PR #$pr_number" | |
git push origin $branch | |
echo "PR preview folder pr-$pr_number deleted from $branch." | |
else | |
echo "PR preview folder pr-$pr_number not found. Skipping." | |
fi |