Skip to content

Commit

Permalink
feat: add workflow to remove preview files when pr closed
Browse files Browse the repository at this point in the history
  • Loading branch information
f-hollow committed Dec 9, 2024
1 parent 3ffa3c3 commit 68cda03
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/pr-remove-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Remove preview for PR

on:
pull_request:
types:
- closed

jobs:
remove-preview:
name: Remove preview for PR
runs-on: ubuntu-latest

steps:
# Remove the PR-specific folder from S3
- name: Remove PR-specific subdirectory from S3
run: |
echo "Cleaning up preview folder for PR #${{ github.event.pull_request.number }}"
aws s3 rm "s3://${{ secrets.PREVIEW_AWS_BUCKET_NAME }}/pr${{ github.event.pull_request.number }}" --recursive
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Invalidate CloudFront cache for PR
uses: chetan/invalidate-cloudfront-action@v2
env:
PATHS: "/pr-${{ github.event.pull_request.number }}/*"
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

0 comments on commit 68cda03

Please sign in to comment.