Skip to content

Commit 4f61812

Browse files
Ci/docs preview workflow (#1)
* ci: consolidate docs deployment workflows and add PR previews Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix: source dir path for deployment Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix: pr from forks deployment issue Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix workflow Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix repo name Signed-off-by: Aritra Dey <adey01027@gmail.com> * add workflow_dispatch for running pr previews Signed-off-by: Aritra Dey <adey01027@gmail.com> * feat: switch to rossjrw/pr-preview-action * fix: preview branch Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix: base url Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix redirect url Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix Signed-off-by: Aritra Dey <adey01027@gmail.com> * fix deploy url Signed-off-by: Aritra Dey <adey01027@gmail.com> * remove base url changes Signed-off-by: Aritra Dey <adey01027@gmail.com> * check for fork Signed-off-by: Aritra Dey <adey01027@gmail.com> * trying another action Signed-off-by: Aritra Dey <adey01027@gmail.com> * ci: update preview workflow * remove write for pr Signed-off-by: Aritra Dey <adey01027@gmail.com> * add a two step process Signed-off-by: Aritra Dey <adey01027@gmail.com> * make run_id automatic for pr preview Signed-off-by: Aritra Dey <adey01027@gmail.com> --------- Signed-off-by: Aritra Dey <adey01027@gmail.com>
1 parent b9e3d02 commit 4f61812

4 files changed

Lines changed: 110 additions & 38 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/publish-docs.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Publish Docs
2+
3+
on:
4+
push:
5+
branches: [master]
6+
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+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Build
35+
run: npm run build
36+
37+
- name: Upload build artifact
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: site
41+
path: build/
42+
43+
deploy-pr-preview:
44+
if: ${{ github.event_name == 'workflow_dispatch' }}
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
50+
- name: Find latest run ID
51+
id: find-run
52+
env:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
run: |
55+
BRANCH=$(gh pr view ${{ inputs.pr_number }} --json headRefName --jq .headRefName)
56+
echo "Found branch: $BRANCH"
57+
RUN_ID=$(gh run list --workflow "Publish Docs" --branch "$BRANCH" --event pull_request --status success --limit 1 --json databaseId --jq '.[0].databaseId')
58+
echo "Found run ID: $RUN_ID"
59+
if [ -z "$RUN_ID" ]; then
60+
echo "::error::No successful 'Publish Docs' run found for PR #${{ inputs.pr_number }} (branch: $BRANCH)"
61+
exit 1
62+
fi
63+
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
64+
65+
- name: Download build artifact
66+
uses: actions/download-artifact@v4
67+
with:
68+
name: site
69+
path: site
70+
run-id: ${{ steps.find-run.outputs.run_id }}
71+
github-token: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Deploy PR Preview
74+
uses: JamesIves/github-pages-deploy-action@v4
75+
with:
76+
branch: gh-pages-pr-previews
77+
folder: site
78+
target-folder: pr-${{ inputs.pr_number }}
79+
80+
- name: Comment Preview URL
81+
uses: marocchino/sticky-pull-request-comment@v2
82+
with:
83+
recreate: true
84+
number: ${{ inputs.pr_number }}
85+
message: |
86+
🚀 **Preview Ready!**
87+
Your docs preview for this PR is available here:
88+
89+
**https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ inputs.pr_number }}/**
90+
91+
deploy-production:
92+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
93+
runs-on: ubuntu-latest
94+
needs: build
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v4
98+
99+
- name: Download build artifact
100+
uses: actions/download-artifact@v4
101+
with:
102+
name: site
103+
path: site
104+
105+
- name: Deploy to GitHub Pages
106+
uses: JamesIves/github-pages-deploy-action@v4
107+
with:
108+
branch: gh-pages
109+
folder: site

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: "/",
7+
baseUrl: process.env.BASE_URL || "/",
88
onBrokenLinks: "ignore",
99
onBrokenMarkdownLinks: "warn",
1010
favicon: "img/favicon.ico",

0 commit comments

Comments
 (0)