From d7bc4ef233f7aa4d364975962b8d862bf51fcc04 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Sat, 22 Nov 2025 21:27:32 +0530 Subject: [PATCH 01/19] ci: consolidate docs deployment workflows and add PR previews Signed-off-by: Aritra Dey --- .github/workflows/build.yml | 16 ---------- .github/workflows/deploy.yml | 21 ------------ .github/workflows/publish-docs.yml | 51 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/publish-docs.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 0eae7326..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: build -on: - pull_request: - branches: [master] -jobs: - build: - runs-on: ubuntu-latest - name: Build Test - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 - - - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built. - run: | - npm install - npm run build \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 65e4ed40..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: deploy -on: - push: - branches: [master] -jobs: - build-and-deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 - - - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built. - run: | - npm install - npm run build - - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@4.1.4 - with: - branch: gh-pages # The branch the action should deploy to. - folder: build # The folder the action should deploy. diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml new file mode 100644 index 00000000..c2414692 --- /dev/null +++ b/.github/workflows/publish-docs.yml @@ -0,0 +1,51 @@ +name: Publish Docs + +on: + push: + branches: [master] + pull_request: + branches: [master] + types: [opened, synchronize, reopened, closed] + +permissions: + contents: write + pull-requests: write + statuses: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install and Build 🔧 + run: | + npm ci + npm run build + + - name: Deploy Preview deploy-preview 🚀 + if: github.event_name == 'pull_request' + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./docusaurus/ + preview-branch: gh-pages-pr-previews + umbrella-dir: pr-preview + action: auto + + - name: Deploy to GitHub Pages 🚀 + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: build From 332e13750c7e2a5d851533d34d4209a5ec594b75 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Sat, 22 Nov 2025 22:09:33 +0530 Subject: [PATCH 02/19] fix: source dir path for deployment Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index c2414692..c7c22234 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -38,7 +38,7 @@ jobs: if: github.event_name == 'pull_request' uses: rossjrw/pr-preview-action@v1 with: - source-dir: ./docusaurus/ + source-dir: ./build/ preview-branch: gh-pages-pr-previews umbrella-dir: pr-preview action: auto From 9b6dd7ac51072e9dc74a38dab9176ea5315e95e7 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Tue, 25 Nov 2025 14:52:48 +0530 Subject: [PATCH 03/19] fix: pr from forks deployment issue Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 84 +++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index c7c22234..021f95aa 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -5,47 +5,81 @@ on: branches: [master] pull_request: branches: [master] - types: [opened, synchronize, reopened, closed] permissions: contents: write pull-requests: write - statuses: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: true jobs: - build-and-deploy: + build: runs-on: ubuntu-latest + steps: - - name: Checkout 🛎️ + - name: Checkout uses: actions/checkout@v4 - - name: Setup Node.js + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: 20 + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: site + path: build/ + + deploy-pr-preview: + # Runs ONLY for PRs + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + needs: build - - name: Install and Build 🔧 - run: | - npm ci - npm run build + steps: + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: site + path: site - - name: Deploy Preview deploy-preview 🚀 - if: github.event_name == 'pull_request' - uses: rossjrw/pr-preview-action@v1 + - name: Deploy PR Preview + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages-pr-previews + folder: site + target-folder: pr-${{ github.event.pull_request.number }} + + - name: Comment Preview URL + uses: marocchino/sticky-pull-request-comment@v2 + with: + recreate: true + message: | + 🚀 **Preview Ready!** + Your docs preview for this PR is available here: + + **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/** + + deploy-production: + # Runs ONLY on push to master + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + runs-on: ubuntu-latest + needs: build + + steps: + - name: Download build artifact + uses: actions/download-artifact@v4 with: - source-dir: ./build/ - preview-branch: gh-pages-pr-previews - umbrella-dir: pr-preview - action: auto + name: site + path: site - - name: Deploy to GitHub Pages 🚀 - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + - name: Deploy to GitHub Pages uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages - folder: build + folder: site From e44a206e187856cb7feb5c10e86f6aa4bc27e168 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Tue, 25 Nov 2025 15:20:00 +0530 Subject: [PATCH 04/19] fix workflow Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 021f95aa..afdfb347 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -63,8 +63,8 @@ jobs: 🚀 **Preview Ready!** Your docs preview for this PR is available here: - **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/** - + **https://pecanproject.github.io/pr-${{ github.event.pull_request.number }}/** + deploy-production: # Runs ONLY on push to master if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} From a1ad3a4f4b4b884fd6496faecf14262f33e6b129 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Tue, 25 Nov 2025 15:23:51 +0530 Subject: [PATCH 05/19] fix repo name Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index afdfb347..ec4ed3a2 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -54,6 +54,7 @@ jobs: branch: gh-pages-pr-previews folder: site target-folder: pr-${{ github.event.pull_request.number }} + workspace: /home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }} - name: Comment Preview URL uses: marocchino/sticky-pull-request-comment@v2 @@ -64,7 +65,7 @@ jobs: Your docs preview for this PR is available here: **https://pecanproject.github.io/pr-${{ github.event.pull_request.number }}/** - + deploy-production: # Runs ONLY on push to master if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} From 43786f9a72e51349082ed91300416a9fdf3f868d Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Tue, 25 Nov 2025 15:28:29 +0530 Subject: [PATCH 06/19] add workflow_dispatch for running pr previews Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index ec4ed3a2..2794503e 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -5,6 +5,16 @@ on: branches: [master] pull_request: branches: [master] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to deploy preview for' + required: true + type: number + run_id: + description: 'Run ID of the build workflow (from the PR checks)' + required: true + type: string permissions: contents: write @@ -13,7 +23,6 @@ permissions: jobs: build: runs-on: ubuntu-latest - steps: - name: Checkout uses: actions/checkout@v4 @@ -36,43 +45,46 @@ jobs: path: build/ deploy-pr-preview: - # Runs ONLY for PRs - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest - needs: build - steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Download build artifact uses: actions/download-artifact@v4 with: name: site path: site + run-id: ${{ inputs.run_id }} + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Deploy PR Preview uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages-pr-previews folder: site - target-folder: pr-${{ github.event.pull_request.number }} - workspace: /home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }} + target-folder: pr-${{ inputs.pr_number }} - name: Comment Preview URL uses: marocchino/sticky-pull-request-comment@v2 with: recreate: true + number: ${{ inputs.pr_number }} message: | 🚀 **Preview Ready!** Your docs preview for this PR is available here: - **https://pecanproject.github.io/pr-${{ github.event.pull_request.number }}/** + **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ inputs.pr_number }}/** deploy-production: - # Runs ONLY on push to master if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest needs: build - steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Download build artifact uses: actions/download-artifact@v4 with: From 84d2446e98ae5858b587f1530be49a3f0f2a5196 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:00:37 +0530 Subject: [PATCH 07/19] feat: switch to rossjrw/pr-preview-action --- .github/workflows/publish-docs.yml | 105 ++++++++++++++++------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 2794503e..e0f29657 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -4,25 +4,25 @@ on: push: branches: [master] pull_request: - branches: [master] - workflow_dispatch: - inputs: - pr_number: - description: 'PR number to deploy preview for' - required: true - type: number - run_id: - description: 'Run ID of the build workflow (from the PR checks)' - required: true - type: string + types: + - opened + - reopened + - synchronize + - closed permissions: contents: write pull-requests: write +concurrency: preview-${{ github.ref }} + +env: + PREVIEW_BRANCH: gh-pages-pr-previews + jobs: - build: + deploy-preview: runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} steps: - name: Checkout uses: actions/checkout@v4 @@ -32,59 +32,68 @@ jobs: with: node-version: 20 - - name: Install dependencies - run: npm ci + - name: Install and Build + run: npm ci && npm run build - - name: Build - run: npm run build + - name: Deploy Preview + uses: rossjrw/pr-preview-action@v1 + id: preview-step + with: + source-dir: build/ + preview-branch: ${{ env.PREVIEW_BRANCH }} + comment: false - - name: Upload build artifact - uses: actions/upload-artifact@v4 + - name: Comment Preview URL (Success) + uses: marocchino/sticky-pull-request-comment@v2 + if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success' with: - name: site - path: build/ + header: pr-preview + message: | + [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} + :---: + |

:rocket: View preview at
${{ steps.preview-step.outputs.preview-url }}

+ |
Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}.
Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete.

+ + - name: Comment Preview Removed + uses: marocchino/sticky-pull-request-comment@v2 + if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success' + with: + header: pr-preview + message: | + [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} + :---: + Preview removed because the pull request was closed. + ${{ steps.preview-step.outputs.action-start-time }} - deploy-pr-preview: - if: ${{ github.event_name == 'workflow_dispatch' }} + build-production: runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Download build artifact - uses: actions/download-artifact@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 with: - name: site - path: site - run-id: ${{ inputs.run_id }} - github-token: ${{ secrets.GITHUB_TOKEN }} + node-version: 20 - - name: Deploy PR Preview - uses: JamesIves/github-pages-deploy-action@v4 - with: - branch: gh-pages-pr-previews - folder: site - target-folder: pr-${{ inputs.pr_number }} + - name: Install dependencies + run: npm ci - - name: Comment Preview URL - uses: marocchino/sticky-pull-request-comment@v2 - with: - recreate: true - number: ${{ inputs.pr_number }} - message: | - 🚀 **Preview Ready!** - Your docs preview for this PR is available here: + - name: Build + run: npm run build - **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ inputs.pr_number }}/** + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: site + path: build/ deploy-production: - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest - needs: build + needs: build-production + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Download build artifact uses: actions/download-artifact@v4 with: From 63f33bd5ec2c0714c04d430bca1d24f4db4fb030 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:11:15 +0530 Subject: [PATCH 08/19] fix: preview branch Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index e0f29657..99758ff0 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -17,7 +17,7 @@ permissions: concurrency: preview-${{ github.ref }} env: - PREVIEW_BRANCH: gh-pages-pr-previews + PREVIEW_BRANCH: gh-pages jobs: deploy-preview: @@ -105,3 +105,4 @@ jobs: with: branch: gh-pages folder: site + clean-exclude: pr-preview From 1e812af3b7d1c340da47a92871c02775527c08a9 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:18:24 +0530 Subject: [PATCH 09/19] fix: base url Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 10 ++++++++++ docusaurus.config.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 99758ff0..5f55bf5b 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -32,8 +32,18 @@ jobs: with: node-version: 20 + - name: Calculate BASE_URL + run: | + if [[ "${{ github.event.repository.name }}" == "${{ github.repository_owner }}.github.io" ]]; then + echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + else + echo "BASE_URL=/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + fi + - name: Install and Build run: npm ci && npm run build + env: + BASE_URL: ${{ env.BASE_URL }} - name: Deploy Preview uses: rossjrw/pr-preview-action@v1 diff --git a/docusaurus.config.js b/docusaurus.config.js index 573cdd4c..8859e445 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -4,7 +4,7 @@ module.exports = { tagline: "Ecosystem science, policy, and management informed by the best available data and models", url: "https://pecanproject.github.io", - baseUrl: "/", + baseUrl: process.env.BASE_URL || "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", From 170997ca699e60873bec8574380be45bc0ff0aa9 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:33:30 +0530 Subject: [PATCH 10/19] fix redirect url Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 15 ++++++++++++--- docusaurus.config.js | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 5f55bf5b..83a836fb 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -32,18 +32,27 @@ jobs: with: node-version: 20 - - name: Calculate BASE_URL + - name: Calculate URLs run: | - if [[ "${{ github.event.repository.name }}" == "${{ github.repository_owner }}.github.io" ]]; then + REPO="${{ github.event.repository.name }}" + OWNER="${{ github.repository_owner }}" + + if [[ "$REPO" == "$OWNER.github.io" ]]; then + # User/org GitHub Pages repo echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + echo "URL=https://$OWNER.github.io" >> $GITHUB_ENV else - echo "BASE_URL=/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + # Normal project repo (fork or upstream) + echo "BASE_URL=/$REPO/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + echo "URL=https://$OWNER.github.io/$REPO" >> $GITHUB_ENV fi + - name: Install and Build run: npm ci && npm run build env: BASE_URL: ${{ env.BASE_URL }} + URL: ${{ env.URL }} - name: Deploy Preview uses: rossjrw/pr-preview-action@v1 diff --git a/docusaurus.config.js b/docusaurus.config.js index 8859e445..b8a17871 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -3,13 +3,13 @@ module.exports = { title: "PEcAn Project", tagline: "Ecosystem science, policy, and management informed by the best available data and models", - url: "https://pecanproject.github.io", + url: process.env.URL || "https://pecanproject.github.io", baseUrl: process.env.BASE_URL || "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", - organizationName: "PecanProject", // Usually your GitHub org/user name. - projectName: "PecanProject.github.io", // Usually your repo name. + organizationName: process.env.GITHUB_OWNER || "PecanProject", // Usually your GitHub org/user name. + projectName: process.env.GITHUB_REPOSITORY || "PecanProject.github.io", // Usually your repo name. themeConfig: { navbar: { title: "PEcAn", From 1a31f1a950bd83de79e5132e16fe775ea2bd2ce2 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:36:47 +0530 Subject: [PATCH 11/19] fix Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 83a836fb..f0bbb404 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -44,7 +44,7 @@ jobs: else # Normal project repo (fork or upstream) echo "BASE_URL=/$REPO/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV - echo "URL=https://$OWNER.github.io/$REPO" >> $GITHUB_ENV + echo "URL=https://$OWNER.github.io" >> $GITHUB_ENV fi From 12f9eec7d6c76a698d140d2572ef3d47ede27624 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:45:52 +0530 Subject: [PATCH 12/19] fix deploy url Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index f0bbb404..c7361fae 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -38,16 +38,15 @@ jobs: OWNER="${{ github.repository_owner }}" if [[ "$REPO" == "$OWNER.github.io" ]]; then - # User/org GitHub Pages repo echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV echo "URL=https://$OWNER.github.io" >> $GITHUB_ENV else - # Normal project repo (fork or upstream) echo "BASE_URL=/$REPO/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV - echo "URL=https://$OWNER.github.io" >> $GITHUB_ENV + echo "URL=https://$OWNER.github.io/$REPO" >> $GITHUB_ENV fi + - name: Install and Build run: npm ci && npm run build env: From 4bf21cbb1962f2fd6b1f9d9b8741c1f6d9459278 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 14:50:07 +0530 Subject: [PATCH 13/19] remove base url changes Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 21 ++------------------- docusaurus.config.js | 8 ++++---- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index c7361fae..8cc00161 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -31,27 +31,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20 - - - name: Calculate URLs - run: | - REPO="${{ github.event.repository.name }}" - OWNER="${{ github.repository_owner }}" - - if [[ "$REPO" == "$OWNER.github.io" ]]; then - echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV - echo "URL=https://$OWNER.github.io" >> $GITHUB_ENV - else - echo "BASE_URL=/$REPO/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV - echo "URL=https://$OWNER.github.io/$REPO" >> $GITHUB_ENV - fi - - - + - name: Install and Build run: npm ci && npm run build - env: - BASE_URL: ${{ env.BASE_URL }} - URL: ${{ env.URL }} + - name: Deploy Preview uses: rossjrw/pr-preview-action@v1 diff --git a/docusaurus.config.js b/docusaurus.config.js index b8a17871..573cdd4c 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -3,13 +3,13 @@ module.exports = { title: "PEcAn Project", tagline: "Ecosystem science, policy, and management informed by the best available data and models", - url: process.env.URL || "https://pecanproject.github.io", - baseUrl: process.env.BASE_URL || "/", + url: "https://pecanproject.github.io", + baseUrl: "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", - organizationName: process.env.GITHUB_OWNER || "PecanProject", // Usually your GitHub org/user name. - projectName: process.env.GITHUB_REPOSITORY || "PecanProject.github.io", // Usually your repo name. + organizationName: "PecanProject", // Usually your GitHub org/user name. + projectName: "PecanProject.github.io", // Usually your repo name. themeConfig: { navbar: { title: "PEcAn", From 34b8156f255fcb17bab747b5730ac0af473f9f66 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 15:11:13 +0530 Subject: [PATCH 14/19] check for fork Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 13 +++++++++++++ docusaurus.config.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 8cc00161..280ced55 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -31,9 +31,22 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20 + + - name: Calculate BASE_URL + run: | + REPO="${{ github.event.repository.name }}" + OWNER="${{ github.repository_owner }}" + if [[ "$REPO" == "$OWNER.github.io" ]]; then + echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + else + echo "BASE_URL=/$REPO/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV + fi + - name: Install and Build run: npm ci && npm run build + env: + BASE_URL: ${{ env.BASE_URL }} - name: Deploy Preview diff --git a/docusaurus.config.js b/docusaurus.config.js index 573cdd4c..8859e445 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -4,7 +4,7 @@ module.exports = { tagline: "Ecosystem science, policy, and management informed by the best available data and models", url: "https://pecanproject.github.io", - baseUrl: "/", + baseUrl: process.env.BASE_URL || "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", From a77349b9282c4731c61b544f0c92cf2d90d0b3ff Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 15:25:58 +0530 Subject: [PATCH 15/19] trying another action Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 109 ++--------------------------- docusaurus.config.js | 2 +- 2 files changed, 8 insertions(+), 103 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 280ced55..7be332b0 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -1,4 +1,4 @@ -name: Publish Docs +name: Build, Deploy to GitHub Pages and Deploy PR Preview on: push: @@ -14,109 +14,14 @@ permissions: contents: write pull-requests: write -concurrency: preview-${{ github.ref }} - -env: - PREVIEW_BRANCH: gh-pages +concurrency: ci-${{ github.ref }} jobs: - deploy-preview: - runs-on: ubuntu-latest - if: ${{ github.event_name == 'pull_request' }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 20 - - - name: Calculate BASE_URL - run: | - REPO="${{ github.event.repository.name }}" - OWNER="${{ github.repository_owner }}" - - if [[ "$REPO" == "$OWNER.github.io" ]]; then - echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV - else - echo "BASE_URL=/$REPO/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV - fi - - - name: Install and Build - run: npm ci && npm run build - env: - BASE_URL: ${{ env.BASE_URL }} - - - - name: Deploy Preview - uses: rossjrw/pr-preview-action@v1 - id: preview-step - with: - source-dir: build/ - preview-branch: ${{ env.PREVIEW_BRANCH }} - comment: false - - - name: Comment Preview URL (Success) - uses: marocchino/sticky-pull-request-comment@v2 - if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success' - with: - header: pr-preview - message: | - [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} - :---: - |

:rocket: View preview at
${{ steps.preview-step.outputs.preview-url }}

- |
Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}.
Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete.

- - - name: Comment Preview Removed - uses: marocchino/sticky-pull-request-comment@v2 - if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success' - with: - header: pr-preview - message: | - [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} - :---: - Preview removed because the pull request was closed. - ${{ steps.preview-step.outputs.action-start-time }} - - build-production: + build-deploy-and-preview: + name: Build, Deploy to GitHub Pages and Deploy PR Preview runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 20 - - - name: Install dependencies - run: npm ci - - - name: Build - run: npm run build - - - name: Upload build artifact - uses: actions/upload-artifact@v4 - with: - name: site - path: build/ - - deploy-production: - runs-on: ubuntu-latest - needs: build-production - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} - steps: - - name: Download build artifact - uses: actions/download-artifact@v4 - with: - name: site - path: site - - - name: Deploy to GitHub Pages - uses: JamesIves/github-pages-deploy-action@v4 + - name: Build, Deploy to GitHub Pages and Deploy PR Preview + uses: chvmvd/build-deploy-and-preview-action@v1.2.0 with: - branch: gh-pages - folder: site - clean-exclude: pr-preview + type: docusaurus \ No newline at end of file diff --git a/docusaurus.config.js b/docusaurus.config.js index 8859e445..a21e207c 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -4,7 +4,7 @@ module.exports = { tagline: "Ecosystem science, policy, and management informed by the best available data and models", url: "https://pecanproject.github.io", - baseUrl: process.env.BASE_URL || "/", + baseUrl: process.env.GITHUB_ACTIONS ? `${process.env.BASE_URL}/` : "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", From 89fa9a2bcba9e93c0d8a175b4e06737c61058202 Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 16:01:47 +0530 Subject: [PATCH 16/19] ci: update preview workflow --- .github/workflows/publish-docs.yml | 76 +++++++++++++++++++++++++++--- docusaurus.config.js | 2 +- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 7be332b0..b702ecdc 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -1,4 +1,4 @@ -name: Build, Deploy to GitHub Pages and Deploy PR Preview +name: Publish Docs on: push: @@ -14,14 +14,76 @@ permissions: contents: write pull-requests: write -concurrency: ci-${{ github.ref }} +concurrency: preview-${{ github.ref }} + +env: + PREVIEW_BRANCH: gh-pages jobs: - build-deploy-and-preview: - name: Build, Deploy to GitHub Pages and Deploy PR Preview + deploy-preview: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Calculate BASE_URL + run: echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV + + - run: npm ci && npm run build + env: + BASE_URL: ${{ env.BASE_URL }} + + - uses: rossjrw/pr-preview-action@v1 + id: preview-step + with: + source-dir: ./build/ + preview-branch: ${{ env.PREVIEW_BRANCH }} + comment: false + + - uses: marocchino/sticky-pull-request-comment@v2 + if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success' + with: + header: pr-preview + message: | + [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} + :---: + |

:rocket: View preview at
${{ steps.preview-step.outputs.preview-url }}

+ |
Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}.
Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete.

+ + - uses: marocchino/sticky-pull-request-comment@v2 + if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success' + with: + header: pr-preview + message: | + [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} + :---: + Preview removed because the pull request was closed. + ${{ steps.preview-step.outputs.action-start-time }} + + build-production: + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: { node-version: 20 } + - run: npm ci + - run: npm run build + - uses: actions/upload-artifact@v4 + with: { name: site, path: build/ } + + deploy-production: runs-on: ubuntu-latest + needs: build-production + if: github.event_name == 'push' && github.ref == 'refs/heads/master' steps: - - name: Build, Deploy to GitHub Pages and Deploy PR Preview - uses: chvmvd/build-deploy-and-preview-action@v1.2.0 + - uses: actions/download-artifact@v4 + with: { name: site, path: site } + - uses: JamesIves/github-pages-deploy-action@v4 with: - type: docusaurus \ No newline at end of file + branch: gh-pages + folder: site + clean-exclude: pr-preview \ No newline at end of file diff --git a/docusaurus.config.js b/docusaurus.config.js index a21e207c..0a380738 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -4,7 +4,7 @@ module.exports = { tagline: "Ecosystem science, policy, and management informed by the best available data and models", url: "https://pecanproject.github.io", - baseUrl: process.env.GITHUB_ACTIONS ? `${process.env.BASE_URL}/` : "/", + baseUrl: (process.env.GITHUB_ACTIONS && process.env.BASE_URL) ? `${process.env.BASE_URL}/` : "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", From 492ce4e085ae80b7a112f724914dc6a1f8c91b8e Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 16:13:28 +0530 Subject: [PATCH 17/19] remove write for pr Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index b702ecdc..b88946ab 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -12,7 +12,6 @@ on: permissions: contents: write - pull-requests: write concurrency: preview-${{ github.ref }} From 4562db8a3a4abcae262b7fe1d67244714b40e21f Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Mon, 1 Dec 2025 16:22:58 +0530 Subject: [PATCH 18/19] add a two step process Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 124 ++++++++++++++++------------- docusaurus.config.js | 2 +- 2 files changed, 68 insertions(+), 58 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index b88946ab..53a67a02 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -4,85 +4,95 @@ on: push: branches: [master] pull_request: - types: - - opened - - reopened - - synchronize - - closed + branches: [master] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to deploy preview for' + required: true + type: number + run_id: + description: 'Run ID of the build workflow (from the PR checks)' + required: true + type: string permissions: contents: write - -concurrency: preview-${{ github.ref }} - -env: - PREVIEW_BRANCH: gh-pages + pull-requests: write jobs: - deploy-preview: + build: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 with: node-version: 20 - - name: Calculate BASE_URL - run: echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV + - name: Install dependencies + run: npm ci - - run: npm ci && npm run build - env: - BASE_URL: ${{ env.BASE_URL }} + - name: Build + run: npm run build - - uses: rossjrw/pr-preview-action@v1 - id: preview-step + - name: Upload build artifact + uses: actions/upload-artifact@v4 with: - source-dir: ./build/ - preview-branch: ${{ env.PREVIEW_BRANCH }} - comment: false + name: site + path: build/ - - uses: marocchino/sticky-pull-request-comment@v2 - if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success' + deploy-pr-preview: + if: ${{ github.event_name == 'workflow_dispatch' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download build artifact + uses: actions/download-artifact@v4 with: - header: pr-preview - message: | - [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} - :---: - |

:rocket: View preview at
${{ steps.preview-step.outputs.preview-url }}

- |
Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}.
Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete.

+ name: site + path: site + run-id: ${{ inputs.run_id }} + github-token: ${{ secrets.GITHUB_TOKEN }} - - uses: marocchino/sticky-pull-request-comment@v2 - if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success' + - name: Deploy PR Preview + uses: JamesIves/github-pages-deploy-action@v4 with: - header: pr-preview + branch: gh-pages-pr-previews + folder: site + target-folder: pr-${{ inputs.pr_number }} + + - name: Comment Preview URL + uses: marocchino/sticky-pull-request-comment@v2 + with: + recreate: true + number: ${{ inputs.pr_number }} message: | - [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }} - :---: - Preview removed because the pull request was closed. - ${{ steps.preview-step.outputs.action-start-time }} + 🚀 **Preview Ready!** + Your docs preview for this PR is available here: - build-production: - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: { node-version: 20 } - - run: npm ci - - run: npm run build - - uses: actions/upload-artifact@v4 - with: { name: site, path: build/ } + **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ inputs.pr_number }}/** deploy-production: + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest - needs: build-production - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + needs: build steps: - - uses: actions/download-artifact@v4 - with: { name: site, path: site } - - uses: JamesIves/github-pages-deploy-action@v4 + - name: Checkout + uses: actions/checkout@v4 + + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: site + path: site + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages - folder: site - clean-exclude: pr-preview \ No newline at end of file + folder: site \ No newline at end of file diff --git a/docusaurus.config.js b/docusaurus.config.js index 0a380738..8859e445 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -4,7 +4,7 @@ module.exports = { tagline: "Ecosystem science, policy, and management informed by the best available data and models", url: "https://pecanproject.github.io", - baseUrl: (process.env.GITHUB_ACTIONS && process.env.BASE_URL) ? `${process.env.BASE_URL}/` : "/", + baseUrl: process.env.BASE_URL || "/", onBrokenLinks: "ignore", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", From e24d4c1d093cfa2ccefbb52137372217be765e2f Mon Sep 17 00:00:00 2001 From: Aritra Dey Date: Sun, 7 Dec 2025 23:09:37 +0530 Subject: [PATCH 19/19] make run_id automatic for pr preview Signed-off-by: Aritra Dey --- .github/workflows/publish-docs.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 53a67a02..fc6ca022 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -11,10 +11,6 @@ on: description: 'PR number to deploy preview for' required: true type: number - run_id: - description: 'Run ID of the build workflow (from the PR checks)' - required: true - type: string permissions: contents: write @@ -51,12 +47,27 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Find latest run ID + id: find-run + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + BRANCH=$(gh pr view ${{ inputs.pr_number }} --json headRefName --jq .headRefName) + echo "Found branch: $BRANCH" + RUN_ID=$(gh run list --workflow "Publish Docs" --branch "$BRANCH" --event pull_request --status success --limit 1 --json databaseId --jq '.[0].databaseId') + echo "Found run ID: $RUN_ID" + if [ -z "$RUN_ID" ]; then + echo "::error::No successful 'Publish Docs' run found for PR #${{ inputs.pr_number }} (branch: $BRANCH)" + exit 1 + fi + echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT + - name: Download build artifact uses: actions/download-artifact@v4 with: name: site path: site - run-id: ${{ inputs.run_id }} + run-id: ${{ steps.find-run.outputs.run_id }} github-token: ${{ secrets.GITHUB_TOKEN }} - name: Deploy PR Preview