Test for GitHub pages deployment through actions #3
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: Remove PR preview | |
on: | |
pull_request: | |
types: | |
- closed | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
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: | |
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: Upload pages artifact | |
uses: actions/upload-pages-artifact@v2 | |
with: | |
path: '.' | |
- name: Deploy to GitHub Pages | |
uses: actions/deploy-pages@v2 | |
- 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 }} | |