44 push :
55 branches : [master]
66 pull_request :
7- types :
8- - opened
9- - reopened
10- - synchronize
11- - closed
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
1218
1319permissions :
1420 contents : write
15-
16- concurrency : preview-${{ github.ref }}
17-
18- env :
19- PREVIEW_BRANCH : gh-pages
21+ pull-requests : write
2022
2123jobs :
22- deploy-preview :
24+ build :
2325 runs-on : ubuntu-latest
24- if : github.event_name == 'pull_request'
2526 steps :
26- - uses : actions/checkout@v4
27- - uses : actions/setup-node@v4
27+ - name : Checkout
28+ uses : actions/checkout@v4
29+
30+ - name : Setup Node.js
31+ uses : actions/setup-node@v4
2832 with :
2933 node-version : 20
3034
31- - name : Calculate BASE_URL
32- run : echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
35+ - name : Install dependencies
36+ run : npm ci
3337
34- - run : npm ci && npm run build
35- env :
36- BASE_URL : ${{ env.BASE_URL }}
38+ - name : Build
39+ run : npm run build
3740
38- - uses : rossjrw/pr-preview-action@v1
39- id : preview-step
41+ - name : Upload build artifact
42+ uses : actions/upload-artifact@v4
4043 with :
41- source-dir : ./build/
42- preview-branch : ${{ env.PREVIEW_BRANCH }}
43- comment : false
44+ name : site
45+ path : build/
4446
45- - uses : marocchino/sticky-pull-request-comment@v2
46- if : steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success'
47+ deploy-pr-preview :
48+ if : ${{ github.event_name == 'workflow_dispatch' }}
49+ runs-on : ubuntu-latest
50+ steps :
51+ - name : Checkout
52+ uses : actions/checkout@v4
53+
54+ - name : Download build artifact
55+ uses : actions/download-artifact@v4
4756 with :
48- header : pr-preview
49- message : |
50- [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
51- :---:
52- | <p></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
53- | <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>
57+ name : site
58+ path : site
59+ run-id : ${{ inputs.run_id }}
60+ github-token : ${{ secrets.GITHUB_TOKEN }}
5461
55- - uses : marocchino/sticky-pull-request-comment@v2
56- if : steps.preview-step.outputs.deployment- action == 'remove' && env.deployment_status == 'success'
62+ - name : Deploy PR Preview
63+ uses : JamesIves/github-pages-deploy- action@v4
5764 with :
58- header : pr-preview
65+ branch : gh-pages-pr-previews
66+ folder : site
67+ target-folder : pr-${{ inputs.pr_number }}
68+
69+ - name : Comment Preview URL
70+ uses : marocchino/sticky-pull-request-comment@v2
71+ with :
72+ recreate : true
73+ number : ${{ inputs.pr_number }}
5974 message : |
60- [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
61- :---:
62- Preview removed because the pull request was closed.
63- ${{ steps.preview-step.outputs.action-start-time }}
75+ 🚀 **Preview Ready!**
76+ Your docs preview for this PR is available here:
6477
65- build-production :
66- runs-on : ubuntu-latest
67- if : github.event_name == 'push' && github.ref == 'refs/heads/master'
68- steps :
69- - uses : actions/checkout@v4
70- - uses : actions/setup-node@v4
71- with : { node-version: 20 }
72- - run : npm ci
73- - run : npm run build
74- - uses : actions/upload-artifact@v4
75- with : { name: site, path: build/ }
78+ **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ inputs.pr_number }}/**
7679
7780 deploy-production :
81+ if : ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
7882 runs-on : ubuntu-latest
79- needs : build-production
80- if : github.event_name == 'push' && github.ref == 'refs/heads/master'
83+ needs : build
8184 steps :
82- - uses : actions/download-artifact@v4
83- with : { name: site, path: site }
84- - uses : JamesIves/github-pages-deploy-action@v4
85+ - name : Checkout
86+ uses : actions/checkout@v4
87+
88+ - name : Download build artifact
89+ uses : actions/download-artifact@v4
90+ with :
91+ name : site
92+ path : site
93+
94+ - name : Deploy to GitHub Pages
95+ uses : JamesIves/github-pages-deploy-action@v4
8596 with :
8697 branch : gh-pages
87- folder : site
88- clean-exclude : pr-preview
98+ folder : site
0 commit comments