Skip to content

Commit d61f174

Browse files
committed
chore: add mdBook deploy and PR preview support
1 parent b2e9072 commit d61f174

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
name: Deploy mdBook to GitHub Pages (Branch Deployment)
1+
name: Deploy mdBook to GitHub Pages (With PR Preview)
22

33
on:
44
push:
55
branches:
6-
- main # Deploy the main site when pushing to 'main'
7-
# - preview-test # You can add this if you want to deploy from 'preview-test' as well
6+
- main
7+
- gh-pages
8+
pull_request:
9+
branches:
10+
- main
811

912
permissions:
10-
contents: write # This is crucial: the workflow needs write access to push to the gh-pages branch
13+
contents: write
14+
pages: write
15+
id-token: write
1116

1217
jobs:
13-
deploy-book:
18+
build:
1419
runs-on: ubuntu-latest
1520
steps:
1621
- name: Checkout repo
@@ -26,13 +31,21 @@ jobs:
2631
fi
2732
2833
- name: Build mdBook
29-
run: mdbook build docs # This builds your book into 'docs/book'
34+
run: mdbook build docs
3035

31-
- name: Deploy to GitHub Pages
32-
uses: peaceiris/actions-gh-pages@v4 # Use this action for direct branch deployment
36+
- name: Upload artifact
37+
uses: actions/upload-pages-artifact@v3
3338
with:
34-
github_token: ${{ secrets.GITHUB_TOKEN }}
35-
publish_dir: ./docs/book # The directory containing your built book files
36-
publish_branch: gh-pages # The branch where your GitHub Pages content will live
37-
# The default 'gh-pages' branch is commonly used for this.
38-
# It will be created if it doesn't exist.
39+
path: ./docs/book
40+
41+
deploy:
42+
needs: build
43+
runs-on: ubuntu-latest
44+
if: github.event_name != 'pull_request' || github.event.action == 'opened' || github.event.action == 'synchronize'
45+
environment:
46+
name: github-pages
47+
url: ${{ steps.deployment.outputs.page_url }}
48+
steps:
49+
- name: Deploy to GitHub Pages
50+
id: deployment
51+
uses: actions/deploy-pages@v4

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ ci-runner-github: ci-job-format ci-job-clippy
1818
@cargo check
1919
@echo "Running tests..."
2020
@cargo test
21+
22+
.PHONY: ci-mdbook-job
23+
ci-job-mdbook:
24+
@echo "Installing mdBook if necessary and building docs..."
25+
@cargo install mdbook --version "^0.4" --force
26+
@mdbook build docs
27+

0 commit comments

Comments
 (0)