Skip to content

Commit

Permalink
Added workflow for PR previews
Browse files Browse the repository at this point in the history
  • Loading branch information
spoenemann committed Dec 21, 2023
1 parent ec5bbd9 commit b803ced
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Deploy PR previews

on:
pull_request_target:
types:
- opened
- synchronize
- reopened
- closed

concurrency: preview-${{ github.head_ref }}

defaults:
run:
shell: bash

jobs:
build-preview:
if: github.event_name == 'pull_request_target' && github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Use Node.js
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2
with:
node-version: '18'
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Build
run: |
npm install
npm run build
- name: Upload artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: 'site'
path: ./public

deploy-preview:
needs: build-preview
runs-on: ubuntu-latest
permissions:
pull-requests: write
environment:
name: pull-request-preview
url: ${{ steps.deployment.outputs.deployment-url }}
steps:
# checkout required for pr-preview-action to succeed,
# while the content will not be used
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Download the preview page
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: 'site'
path: ./public
- uses: rossjrw/pr-preview-action@4668d7cb417ce7067b0b59bc152b1ae1513010de # v1.4.6
id: deployment
with:
source-dir: ./public
preview-branch: previews
umbrella-dir: pr-previews
deploy-repository: eclipse-sprotty/sprotty-previews
token: ${{ secrets.DEPLOY_PREVIEW_TOKEN }}
action: auto

# remove the preview page when the PR got closed
remove-preview:
if: github.event_name == 'pull_request_target' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
# checkout required for pr-preview-action to succeed,
# while the content will not be used
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: rossjrw/pr-preview-action@4668d7cb417ce7067b0b59bc152b1ae1513010de # v1.4.6
id: deployment
with:
preview-branch: previews
umbrella-dir: pr-previews
deploy-repository: eclipse-sprotty/sprotty-previews
token: ${{ secrets.DEPLOY_PREVIEW_TOKEN }}
action: auto

0 comments on commit b803ced

Please sign in to comment.