Skip to content

Commit 84d2446

Browse files
committed
feat: switch to rossjrw/pr-preview-action
1 parent 43786f9 commit 84d2446

File tree

1 file changed

+57
-48
lines changed

1 file changed

+57
-48
lines changed

.github/workflows/publish-docs.yml

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ on:
44
push:
55
branches: [master]
66
pull_request:
7-
branches: [master]
8-
workflow_dispatch:
9-
inputs:
10-
pr_number:
11-
description: 'PR number to deploy preview for'
12-
required: true
13-
type: number
14-
run_id:
15-
description: 'Run ID of the build workflow (from the PR checks)'
16-
required: true
17-
type: string
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
- closed
1812

1913
permissions:
2014
contents: write
2115
pull-requests: write
2216

17+
concurrency: preview-${{ github.ref }}
18+
19+
env:
20+
PREVIEW_BRANCH: gh-pages-pr-previews
21+
2322
jobs:
24-
build:
23+
deploy-preview:
2524
runs-on: ubuntu-latest
25+
if: ${{ github.event_name == 'pull_request' }}
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
@@ -32,59 +32,68 @@ jobs:
3232
with:
3333
node-version: 20
3434

35-
- name: Install dependencies
36-
run: npm ci
35+
- name: Install and Build
36+
run: npm ci && npm run build
3737

38-
- name: Build
39-
run: npm run build
38+
- name: Deploy Preview
39+
uses: rossjrw/pr-preview-action@v1
40+
id: preview-step
41+
with:
42+
source-dir: build/
43+
preview-branch: ${{ env.PREVIEW_BRANCH }}
44+
comment: false
4045

41-
- name: Upload build artifact
42-
uses: actions/upload-artifact@v4
46+
- name: Comment Preview URL (Success)
47+
uses: marocchino/sticky-pull-request-comment@v2
48+
if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success'
4349
with:
44-
name: site
45-
path: build/
50+
header: pr-preview
51+
message: |
52+
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
53+
:---:
54+
| <p></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
55+
| <h6>Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}. <br> Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete. <br><br> </h6>
56+
57+
- name: Comment Preview Removed
58+
uses: marocchino/sticky-pull-request-comment@v2
59+
if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success'
60+
with:
61+
header: pr-preview
62+
message: |
63+
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
64+
:---:
65+
Preview removed because the pull request was closed.
66+
${{ steps.preview-step.outputs.action-start-time }}
4667
47-
deploy-pr-preview:
48-
if: ${{ github.event_name == 'workflow_dispatch' }}
68+
build-production:
4969
runs-on: ubuntu-latest
70+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
5071
steps:
5172
- name: Checkout
5273
uses: actions/checkout@v4
5374

54-
- name: Download build artifact
55-
uses: actions/download-artifact@v4
75+
- name: Setup Node.js
76+
uses: actions/setup-node@v4
5677
with:
57-
name: site
58-
path: site
59-
run-id: ${{ inputs.run_id }}
60-
github-token: ${{ secrets.GITHUB_TOKEN }}
78+
node-version: 20
6179

62-
- name: Deploy PR Preview
63-
uses: JamesIves/github-pages-deploy-action@v4
64-
with:
65-
branch: gh-pages-pr-previews
66-
folder: site
67-
target-folder: pr-${{ inputs.pr_number }}
80+
- name: Install dependencies
81+
run: npm ci
6882

69-
- name: Comment Preview URL
70-
uses: marocchino/sticky-pull-request-comment@v2
71-
with:
72-
recreate: true
73-
number: ${{ inputs.pr_number }}
74-
message: |
75-
🚀 **Preview Ready!**
76-
Your docs preview for this PR is available here:
83+
- name: Build
84+
run: npm run build
7785

78-
**https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ inputs.pr_number }}/**
86+
- name: Upload build artifact
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: site
90+
path: build/
7991

8092
deploy-production:
81-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
8293
runs-on: ubuntu-latest
83-
needs: build
94+
needs: build-production
95+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
8496
steps:
85-
- name: Checkout
86-
uses: actions/checkout@v4
87-
8897
- name: Download build artifact
8998
uses: actions/download-artifact@v4
9099
with:

0 commit comments

Comments
 (0)