gh-pages-cleanup #106
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: gh-pages-cleanup | |
on: delete | |
jobs: | |
cleanup: | |
name: Cleanup gh-pages | |
runs-on: ubuntu-latest | |
if: github.event.ref_type == 'branch' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
lfs: true | |
ref: gh-pages | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. | |
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. | |
- name: Get branch name | |
id: branch-name | |
uses: tj-actions/branch-names@v8 | |
- name: Remove deleted branch from gh-pages | |
if: steps.branch-name.outputs.is_default == 'true' | |
run: | | |
git config user.name "Github Actions" | |
git config user.email github-actions@github.com | |
BASE_REF=$(printf "%q" "${{ github.event.ref }}") | |
BASE_REF=${BASE_REF/refs\/heads\/} | |
if test -d "$BASE_REF"; then | |
echo "Deleting folder: $BASE_REF" | |
git rm -rf "$BASE_REF" | |
git commit -m "Remove deleted branch" | |
else | |
echo "Folder $BASE_REF does not exist" | |
fi | |
- name: Push changes | |
uses: ad-m/github-push-action@v0.8.0 | |
with: | |
# PAT required to trigger gh_pages_readme.yml workflow | |
github_token: ${{ secrets.PAT }} | |
branch: gh-pages |