diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml index 28d5ae0..59ec00e 100644 --- a/.github/actions/build-docs/action.yml +++ b/.github/actions/build-docs/action.yml @@ -5,21 +5,28 @@ inputs: subdir: description: Subdirectory to deploy to (e.g., dev, 1.0.0, pr/3) required: true + site-dir: + description: Output directory for the built site + default: /tmp/built-site outputs: site-dir: description: Path to the built site - value: /tmp/built-site + value: ${{ inputs.site-dir }} runs: using: composite steps: - shell: bash run: | - # Use github.action_path so the script always comes from the action's - # source (trusted main branch), not the checked-out working directory - # (which may contain untrusted PR code). + # Update the site url. uv run --group docs python "${{ github.action_path }}/override_site_url.py" "${{ inputs.subdir }}" + + # Build the docs. uv run --group docs zensical build --clean - mv site /tmp/built-site - git checkout -- zensical.toml + + # Move the docs to the output directory. + mv site "${{ inputs.site-dir }}" + + # Leave the working directory clean for the next action. + git checkout -- . diff --git a/.github/workflows/docs-pr-preview.yml b/.github/workflows/docs-pr-preview.yml index 187960e..b0357eb 100644 --- a/.github/workflows/docs-pr-preview.yml +++ b/.github/workflows/docs-pr-preview.yml @@ -7,6 +7,9 @@ on: pull_request_target: types: [opened, synchronize, reopened] +env: + SITE_DIR: /tmp/built-site + concurrency: group: docs-deploy cancel-in-progress: false @@ -34,11 +37,12 @@ jobs: id: build with: subdir: pr/${{ github.event.number }} + site-dir: ${{ env.SITE_DIR }} - uses: actions/upload-artifact@v4 with: name: docs-preview - path: /tmp/built-site + path: ${{ env.SITE_DIR }} retention-days: 1 deploy: @@ -55,14 +59,14 @@ jobs: - uses: actions/download-artifact@v4 with: name: docs-preview - path: /tmp/built-site + path: ${{ env.SITE_DIR }} # Reference the action from @main so deploy logic always comes from the # trusted main branch. - uses: TaiSakuma/improved-octo-fortnight/.github/actions/deploy-to-gh-pages@main id: deploy with: - site-dir: /tmp/built-site + site-dir: ${{ env.SITE_DIR }} target: pr/${{ github.event.number }} commit-message: "Deploy PR #${{ github.event.number }} preview"