Skip to content
name: Remove PR preview
# on:
# pull_request:
# types:
# - closed
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
env:
PR: ${{ github.event.number }}
TARGET_FOLDER: pr_preview/pr-${{ github.event.number }}
TARGET_BRANCH: gh-pages
jobs:
close-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.ADMIN_TOKEN }}
ref: ${{ env.TARGET_BRANCH }}
- name: Remove pr-preview
shell: bash
run: |
if [ ! -d ${{ env.TARGET_FOLDER }} ]
then
echo "Nothing to remove!"
exit 0
fi
rm -rf ${{ env.TARGET_FOLDER }}
echo "Removed pr preview for pr-${{ env.PR }}."
- name: Commit to gh-pages
shell: bash
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add .
git commit -m "Deleted '${{ env.TARGET_FOLDER }}' folder."
git push origin ${{ env.TARGET_BRANCH }}
- name: Get date
run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
- name: Leave a comment after removal
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
number: ${{ github.event.number }}
message: "\
PR Preview
:---:
🛬 Preview removed because the pull request was closed.
${{ env.DATE }}
"