Skip to content

Commit

Permalink
ci: add pull request previews
Browse files Browse the repository at this point in the history
Addresses SRGSSR/pillarbox-web#196 by introducing pull request previews using
`rossjrw/pr-preview-action`. This new workflow enables us to review both visual and functional
changes before merging.

The preview functionality work in the following manner:

1. **Triggering a Preview**: Whenever a pull request is either opened, re-opened, or updated, the
   project undergoes a build process. The contents of the `dist` directory are copied
   under `pr-preview/pr-${github.ref}` located in the `gh-pages` branch.

2. **Cleaning Up**: Once a pull request is closed, the corresponding preview folder (specific to the
   closed pull request) is deleted.

Additional workflow updates include:

- The `JamesIves/github-pages-deploy-action` has been updated from version 3 to version 4. This
  update introduces the following configurations to this action:
  - `force: false`: This disables force push to the deployment branch.
  - `clean-exclude: pr-preview/`: This prevents the deletion of PR previews when the main branch is
    deployed.
  • Loading branch information
jboix committed Feb 20, 2024
1 parent 145626f commit 0b4f56f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/github-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
always-auth: true
registry-url: https://npm.pkg.github.com/
scope: '@srgssr'
Expand All @@ -35,8 +35,10 @@ jobs:
npm run build
- name: Deploy GitHub Page 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
uses: JamesIves/github-pages-deploy-action@releases/v4
with:
branch: gh-pages
folder: dist
force: false
clean-exclude: pr-preview/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: dist
48 changes: 48 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy PR previews

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

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

jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 20
always-auth: true
registry-url: https://npm.pkg.github.com/
scope: '@srgssr'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
if: github.event.action != 'closed'
env:
CI: true
run: |
npm pkg delete scripts.prepare
npm ci
- name: Run build
if: github.event.action != 'closed'
run: |
npm run build
- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: dist
preview-branch: gh-pages
umbrella-dir: pr-preview
4 changes: 2 additions & 2 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
always-auth: true
registry-url: https://npm.pkg.github.com/
scope: '@srgssr'
Expand Down

0 comments on commit 0b4f56f

Please sign in to comment.