Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove every file when cleaning up PR preview #17

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ runs:
pr: ${{ github.event.number }}
actionref: ${{ github.action_ref }}
actionrepo: ${{ github.action_repository }}
worktree: ../pr-preview-action-temp-cleanup-folder
run: |
echo "action=$action" >> $GITHUB_ENV
echo "targetdir=$umbrella/pr-$pr" >> $GITHUB_ENV
Expand All @@ -64,6 +65,8 @@ runs:

echo "actionref=$actionref" >> $GITHUB_ENV
echo "actionrepo=$actionrepo" >> $GITHUB_ENV

echo "worktree=$worktree" >> $GITHUB_ENV
shell: bash

- name: Determine action version
Expand Down Expand Up @@ -108,18 +111,29 @@ runs:
at ${{ env.datetime }}
"

- name: Setup temp worktree
if: env.action == 'remove'
run: |
git fetch --no-recurse-submodules --depth=1 origin ${{ inputs.preview-branch }}
git worktree add $worktree ${{ inputs.preview-branch }}
shell: bash

- name: Remove preview directory
if: env.action == 'remove'
uses: JamesIves/github-pages-deploy-action@v4
uses: EndBug/add-and-commit@v9
id: remove
with:
branch: ${{ inputs.preview-branch }}
folder: ${{ env.emptydir }}
target-folder: ${{ env.targetdir }}
commit-message: Remove preview for PR ${{ env.pr }} 🛬
force: false
cwd: ${{ env.worktree }}
remove: ${{ env.targetdir }} -r
message: Remove preview for PR ${{ env.pr }} 🛬

- name: Remove temp worktree
if: env.action == 'remove'
run: git worktree remove $worktree
shell: bash

- name: Leave a comment after removal
if: env.action == 'remove' && env.deployment_status == 'success'
if: env.action == 'remove'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
Expand Down