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