diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 65b819b2..b052f1f4 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -1,7 +1,7 @@ name: PR Preview to GitHub Pages on: - pull_request: + pull_request_target: types: [opened, synchronize, reopened] branches: - main @@ -9,11 +9,15 @@ on: jobs: deploy-preview: runs-on: ubuntu-latest - if: github.event.pull_request.head.repo.full_name == github.repository + permissions: + contents: write + pull-requests: write steps: - name: Checkout PR branch uses: actions/checkout@v4 with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 1 - name: Set up Node.js @@ -24,9 +28,7 @@ jobs: - name: Copy files to preview folder run: | mkdir -p preview/pr-${{ github.event.pull_request.number }} - cp -r * preview/pr-${{ github.event.pull_request.number }}/ - rm -rf preview/pr-${{ github.event.pull_request.number }}/.git - rm -rf preview/pr-${{ github.event.pull_request.number }}/.github + rsync -av --exclude 'preview' --exclude '.git' --exclude '.github' ./ preview/pr-${{ github.event.pull_request.number }}/ - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v4 @@ -43,4 +45,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} header: preview-url message: | - 🚀 PR Preview: https://opensource-society.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.pull_request.number }}/index.html \ No newline at end of file + 🚀 PR Preview: PR Preview: https://opensource-society.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.pull_request.number }}/index.html