Skip to content

Commit 89fa9a2

Browse files
committed
ci: update preview workflow
1 parent a77349b commit 89fa9a2

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

.github/workflows/publish-docs.yml

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Deploy to GitHub Pages and Deploy PR Preview
1+
name: Publish Docs
22

33
on:
44
push:
@@ -14,14 +14,76 @@ permissions:
1414
contents: write
1515
pull-requests: write
1616

17-
concurrency: ci-${{ github.ref }}
17+
concurrency: preview-${{ github.ref }}
18+
19+
env:
20+
PREVIEW_BRANCH: gh-pages
1821

1922
jobs:
20-
build-deploy-and-preview:
21-
name: Build, Deploy to GitHub Pages and Deploy PR Preview
23+
deploy-preview:
24+
runs-on: ubuntu-latest
25+
if: github.event_name == 'pull_request'
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: 20
31+
32+
- name: Calculate BASE_URL
33+
run: echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
34+
35+
- run: npm ci && npm run build
36+
env:
37+
BASE_URL: ${{ env.BASE_URL }}
38+
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
45+
46+
- uses: marocchino/sticky-pull-request-comment@v2
47+
if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success'
48+
with:
49+
header: pr-preview
50+
message: |
51+
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
52+
:---:
53+
| <p></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
54+
| <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>
55+
56+
- uses: marocchino/sticky-pull-request-comment@v2
57+
if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success'
58+
with:
59+
header: pr-preview
60+
message: |
61+
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
62+
:---:
63+
Preview removed because the pull request was closed.
64+
${{ steps.preview-step.outputs.action-start-time }}
65+
66+
build-production:
67+
runs-on: ubuntu-latest
68+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
69+
steps:
70+
- uses: actions/checkout@v4
71+
- uses: actions/setup-node@v4
72+
with: { node-version: 20 }
73+
- run: npm ci
74+
- run: npm run build
75+
- uses: actions/upload-artifact@v4
76+
with: { name: site, path: build/ }
77+
78+
deploy-production:
2279
runs-on: ubuntu-latest
80+
needs: build-production
81+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
2382
steps:
24-
- name: Build, Deploy to GitHub Pages and Deploy PR Preview
25-
uses: chvmvd/[email protected]
83+
- uses: actions/download-artifact@v4
84+
with: { name: site, path: site }
85+
- uses: JamesIves/github-pages-deploy-action@v4
2686
with:
27-
type: docusaurus
87+
branch: gh-pages
88+
folder: site
89+
clean-exclude: pr-preview

docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
tagline:
55
"Ecosystem science, policy, and management informed by the best available data and models",
66
url: "https://pecanproject.github.io",
7-
baseUrl: process.env.GITHUB_ACTIONS ? `${process.env.BASE_URL}/` : "/",
7+
baseUrl: (process.env.GITHUB_ACTIONS && process.env.BASE_URL) ? `${process.env.BASE_URL}/` : "/",
88
onBrokenLinks: "ignore",
99
onBrokenMarkdownLinks: "warn",
1010
favicon: "img/favicon.ico",

0 commit comments

Comments
 (0)