Skip to content

Commit b0d6f8a

Browse files
committed
fix: adjust approach with gh-pages
1 parent bb73576 commit b0d6f8a

3 files changed

Lines changed: 23 additions & 32 deletions

File tree

.github/workflows/mdbook-pr-preview.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ jobs:
6464
- name: Add Cargo bin to PATH
6565
run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
6666

67+
- name: Set site-url for PR preview subpath
68+
run: |
69+
SITE_URL="/${{ github.event.repository.name }}/${{ env.PREVIEW_DIR }}/"
70+
sed -i "s|^site-url = .*|site-url = \"${SITE_URL}\"|" book.toml
71+
6772
- name: Build with mdBook
6873
run: ${{ env.CARGO_HOME }}/bin/mdbook build
6974

.github/workflows/mdbook.yml

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Workflow for building and deploying a mdBook site to GitHub Pages
2-
#
3-
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
1+
# Workflow for building and deploying a mdBook site to GitHub Pages.
2+
# Publishes to the gh-pages branch so PR previews (pr-<number>/) from
3+
# mdbook-pr-preview.yml are served from the same branch. Set Pages source
4+
# to "Deploy from a branch" → gh-pages, folder / (root).
45
#
6+
# See: https://rust-lang.github.io/mdBook/index.html
57
name: Deploy mdBook site to Pages
68

79
on:
@@ -12,21 +14,17 @@ on:
1214
# Allows you to run this workflow manually from the Actions tab
1315
workflow_dispatch:
1416

15-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
17+
# Push to gh-pages so PR previews (mdbook-pr-preview) are served from the same branch.
18+
# Repository Settings → Pages → Source: Deploy from a branch → gh-pages / (root).
1619
permissions:
17-
contents: read
18-
pages: write
19-
id-token: write
20+
contents: write
2021

21-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
2322
concurrency:
2423
group: "pages"
2524
cancel-in-progress: false
2625

2726
jobs:
28-
# Build job
29-
build:
27+
build-and-deploy:
3028
runs-on: ubuntu-latest
3129
env:
3230
CARGO_HOME: ${{ github.workspace }}/.cargo
@@ -69,31 +67,17 @@ jobs:
6967
REPO_ROOT: ${{ github.workspace }}
7068
- name: Add Cargo bin to PATH
7169
run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
72-
- name: Setup Pages
73-
if: ${{ !env.ACT }}
74-
id: pages
75-
uses: actions/configure-pages@v5
7670
- name: Build with mdBook
7771
run: ${{ env.CARGO_HOME }}/bin/mdbook build
78-
- name: Upload artifact
72+
- name: Deploy to gh-pages (root)
7973
if: ${{ !env.ACT }}
80-
uses: actions/upload-pages-artifact@v3
74+
uses: peaceiris/actions-gh-pages@v4
8175
with:
82-
path: ./book
76+
github_token: ${{ secrets.GITHUB_TOKEN }}
77+
publish_branch: gh-pages
78+
publish_dir: ./book
79+
keep_files: true
8380
- name: Confirm local act build
8481
if: ${{ env.ACT }}
8582
run: |
86-
echo "Local act run: mdBook build completed; skipping Pages upload/deploy steps."
87-
88-
# Deployment job
89-
deploy:
90-
if: ${{ !github.event.act }}
91-
environment:
92-
name: github-pages
93-
url: ${{ steps.deployment.outputs.page_url }}
94-
runs-on: ubuntu-latest
95-
needs: build
96-
steps:
97-
- name: Deploy to GitHub Pages
98-
id: deployment
99-
uses: actions/deploy-pages@v4
83+
echo "Local act run: mdBook build completed; skipping gh-pages deploy."

book.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ giscus.loading = "lazy"
2020
giscus.crossorigin = "anonymous"
2121

2222
[output.html]
23+
# Required for correct asset and 404 paths on GitHub Pages (project site and PR preview subpaths).
24+
site-url = "/managing-innersource-projects/"
2325
additional-js = ["mermaid.min.js", "mermaid-init.js"]

0 commit comments

Comments
 (0)