diff --git a/.github/workflows/pr-close.yaml b/.github/workflows/pr-close.yaml new file mode 100644 index 0000000..0d47c4b --- /dev/null +++ b/.github/workflows/pr-close.yaml @@ -0,0 +1,47 @@ +name: Remove PR previews when PR is closed + +on: + pull_request_target: + types: + - closed + +concurrency: preview-${{ github.ref }} + +permissions: + contents: write + pull-requests: write + +defaults: + run: + shell: bash + +jobs: + remove: + if: github.repository == 'project-chip/matter-handbook' + runs-on: ubuntu-latest + env: + HUGO_VERSION: 0.115.4 + steps: + - name: Remove from S3 + uses: vitorsgomes/s3-rm-action@master + with: + args: --recursive + env: + AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: "us-east-1" + PATH_TO_DELETE: 'pr-${{ github.event.number }}' + - name: Invalidate CloudFront + uses: chetan/invalidate-cloudfront-action@v2 + env: + DISTRIBUTION: ${{ secrets.AWS_CF_DISTRIBUTION }} + PATHS: '/pr-${{ github.event.number }}/*' + AWS_REGION: "us-east-1" + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: Comment PR + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + Preview deployed at ${{ vars.PREVIEW_URL }}/pr-${{ github.event.number }}