|
1 | 1 | name: Deploy PR previews |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | types: |
6 | 6 | - opened |
7 | 7 | - synchronize |
8 | 8 | - reopened |
9 | 9 | - closed |
10 | 10 |
|
11 | | -concurrency: preview-${{ github.ref }} |
| 11 | +concurrency: preview-${{ github.head_ref }} |
12 | 12 |
|
13 | 13 | defaults: |
14 | 14 | run: |
15 | 15 | shell: bash |
16 | 16 |
|
17 | 17 | jobs: |
18 | | - deploy-preview: |
| 18 | + build-preview: |
| 19 | + if: github.event_name == 'pull_request_target' && github.event.action != 'closed' |
19 | 20 | runs-on: ubuntu-latest |
20 | 21 | steps: |
21 | 22 | - name: Use Node.js |
22 | | - uses: actions/setup-node@v3 |
| 23 | + uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2 |
23 | 24 | with: |
24 | 25 | node-version: '18' |
25 | 26 | - name: Checkout |
26 | | - uses: actions/checkout@v3 |
| 27 | + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 28 | + with: |
| 29 | + ref: ${{ github.event.pull_request.head.sha }} |
27 | 30 | - name: Build |
28 | 31 | run: | |
29 | 32 | npm install |
30 | 33 | npm run build |
31 | | - - name: Deploy preview |
32 | | - uses: rossjrw/pr-preview-action@v1 |
| 34 | + - name: Upload artifact |
| 35 | + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 |
| 36 | + with: |
| 37 | + name: "site" |
| 38 | + path: ./public |
| 39 | + |
| 40 | + deploy-preview: |
| 41 | + needs: build-preview |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + pull-requests: write |
| 45 | + environment: |
| 46 | + name: pull-request-preview |
| 47 | + url: ${{ steps.deployment.outputs.deployment-url }} |
| 48 | + steps: |
| 49 | + # checkout required for pr-preview-action to succeed, |
| 50 | + # while the content will not be used |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 53 | + - name: Download the preview page |
| 54 | + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 |
| 55 | + with: |
| 56 | + name: "site" |
| 57 | + path: ./public |
| 58 | + - uses: rossjrw/pr-preview-action@183082fd714654433c8e2f6daedbfb4f20f2a94a # v1.4.4 |
| 59 | + id: deployment |
33 | 60 | with: |
34 | 61 | source-dir: ./public |
| 62 | + preview-branch: previews |
| 63 | + umbrella-dir: pr-previews |
| 64 | + deploy-repository: eclipse-langium/langium-previews |
| 65 | + token: ${{ secrets.DEPLOY_PREVIEW_TOKEN }} |
| 66 | + action: auto |
| 67 | + |
| 68 | + # remove the preview page when the PR got closed |
| 69 | + remove-preview: |
| 70 | + if: github.event_name == 'pull_request_target' && github.event.action == 'closed' |
| 71 | + runs-on: ubuntu-latest |
| 72 | + steps: |
| 73 | + # checkout required for pr-preview-action to succeed, |
| 74 | + # while the content will not be used |
| 75 | + - name: Checkout |
| 76 | + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 77 | + - uses: rossjrw/pr-preview-action@183082fd714654433c8e2f6daedbfb4f20f2a94a # v1.4.4 |
| 78 | + id: deployment |
| 79 | + with: |
| 80 | + preview-branch: previews |
| 81 | + umbrella-dir: pr-previews |
| 82 | + deploy-repository: eclipse-langium/langium-previews |
| 83 | + token: ${{ secrets.DEPLOY_PREVIEW_TOKEN }} |
| 84 | + action: auto |
0 commit comments