Skip to content

Davide/test workflows #1

Davide/test workflows

Davide/test workflows #1

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:
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: Deploy to Github-pages
- name: Get date
run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
- name: Leave a comment after removal
# if: env.deployment_status == 'success'
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 }}
"