Skip to content

Commit 10c31df

Browse files
feat(ci): run mdbook on pull requests
Signed-off-by: Victor Adossi <[email protected]>
1 parent 5062fd9 commit 10c31df

File tree

2 files changed

+118
-58
lines changed

2 files changed

+118
-58
lines changed

.github/workflows/deploy.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Deploy mdBook site to Pages
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: false
17+
18+
env:
19+
MDBOOK_VERSION: 0.4.21
20+
MDBOOK_ALERTS_VERSION: 0.6.7
21+
MDBOOK_LINKCHECK_VERSION: 0.7.7
22+
PUBLISH_DOMAIN: component-model.bytecodealliance.org
23+
ARTIFACT_PATH: ./component-model/book/html
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- uses: taiki-e/cache-cargo-install-action@v2
32+
with:
33+
tool: mdbook@${{ env.MDBOOK_VERSION }}
34+
35+
- uses: taiki-e/cache-cargo-install-action@v2
36+
with:
37+
tool: mdbook-alerts@${{ env.MDBOOK_ALERTS_VERSION }}
38+
39+
- uses: taiki-e/cache-cargo-install-action@v2
40+
with:
41+
tool: mdbook-linkcheck@${{ env.MDBOOK_LINKCHECK_VERSION }}
42+
43+
- name: Build with mdBook
44+
run: mdbook build component-model
45+
46+
- name: Setup Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: '3.13'
50+
51+
- name: Ensure build outputs are present
52+
shell: bash
53+
run: |
54+
if [[ ! -f "${{ env.ARTIFACT_PATH }}/index.html" ]]; then
55+
echo "[error] index.html @ [${{ env.ARTIFACT_PATH }}] is missing. Build or path misconfigured";
56+
exit 1;
57+
fi
58+
59+
- name: Generate sitemap
60+
shell: bash
61+
run: |
62+
cd ${{ env.ARTIFACT_PATH }}
63+
python3 ../../../scripts/generate_sitemap.py --domain "component-model.bytecodealliance.org" --higher-priority "design" --output-path sitemap.xml
64+
cd ../../../
65+
66+
- name: Setup Pages
67+
id: pages
68+
uses: actions/configure-pages@v3
69+
70+
- name: Upload artifact
71+
uses: actions/upload-pages-artifact@v3
72+
with:
73+
path: ${{ env.ARTIFACT_PATH }}
74+
75+
deploy:
76+
if: ${{ github.repository_owner == 'bytecodealliance' }}
77+
environment:
78+
name: github-pages
79+
url: ${{ steps.deployment.outputs.page_url }}
80+
runs-on: ubuntu-latest
81+
needs: build
82+
steps:
83+
- name: Deploy to GitHub Pages
84+
id: deployment
85+
uses: actions/deploy-pages@v4

.github/workflows/mdbook.yml

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,50 @@
1-
# Sample 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
4-
#
5-
name: Deploy mdBook site to Pages
1+
name: mdbook
62

73
on:
8-
# Runs on pushes targeting the default branch
9-
push:
10-
branches: ["main"]
4+
pull_request:
115

12-
# Allows you to run this workflow manually from the Actions tab
13-
workflow_dispatch:
14-
15-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
16-
permissions:
17-
contents: read
18-
pages: write
19-
id-token: write
20-
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.
23-
concurrency:
24-
group: "pages"
25-
cancel-in-progress: false
6+
env:
7+
MDBOOK_VERSION: 0.4.21
8+
MDBOOK_ALERTS_VERSION: 0.6.7
9+
MDBOOK_LINKCHECK_VERSION: 0.7.7
2610

2711
jobs:
28-
# Build job
2912
build:
3013
runs-on: ubuntu-latest
31-
env:
32-
MDBOOK_VERSION: 0.4.21
33-
MDBOOK_ALERTS_VERSION: 0.6.7
34-
MDBOOK_LINKCHECK_VERSION: 0.7.7
35-
PUBLISH_DOMAIN: component-model.bytecodealliance.org
3614
steps:
3715
- uses: actions/checkout@v3
38-
- name: Install mdBook
39-
run: |
40-
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
41-
rustup update
42-
cargo install --version ${MDBOOK_VERSION} mdbook
43-
cargo install --version ${MDBOOK_ALERTS_VERSION} mdbook-alerts
44-
cargo install --version ${MDBOOK_LINKCHECK_VERSION} mdbook-linkcheck
45-
- name: Setup Pages
46-
id: pages
47-
uses: actions/configure-pages@v3
16+
17+
- uses: taiki-e/cache-cargo-install-action@v2
18+
with:
19+
tool: mdbook@${{ env.MDBOOK_VERSION }}
20+
21+
- uses: taiki-e/cache-cargo-install-action@v2
22+
with:
23+
tool: mdbook-alerts@${{ env.MDBOOK_ALERTS_VERSION }}
24+
25+
- uses: taiki-e/cache-cargo-install-action@v2
26+
with:
27+
tool: mdbook-linkcheck@${{ env.MDBOOK_LINKCHECK_VERSION }}
28+
4829
- name: Build with mdBook
4930
run: mdbook build component-model
31+
32+
- name: Ensure build outputs are present
33+
shell: bash
34+
run: |
35+
if [[ ! -f "${{ env.ARTIFACT_PATH }}/index.html" ]]; then
36+
echo "[error] index.html @ [${{ env.ARTIFACT_PATH }}] is missing. Build or path misconfigured";
37+
exit 1;
38+
fi
39+
5040
- name: Setup Python
5141
uses: actions/setup-python@v5
5242
with:
5343
python-version: '3.13'
44+
5445
- name: Generate sitemap
46+
shell: bash
5547
run: |
56-
cd component-model
57-
python3 ../scripts/generate_sitemap.py --domain "component-model.bytecodealliance.org" --higher-priority "design" --output-path book/sitemap.xml
58-
cd ..
59-
- name: Upload artifact
60-
uses: actions/upload-pages-artifact@v3
61-
with:
62-
path: ./component-model/book
63-
64-
# Deployment job
65-
deploy:
66-
if: ${{ github.repository_owner == 'bytecodealliance' }}
67-
environment:
68-
name: github-pages
69-
url: ${{ steps.deployment.outputs.page_url }}
70-
runs-on: ubuntu-latest
71-
needs: build
72-
steps:
73-
- name: Deploy to GitHub Pages
74-
id: deployment
75-
uses: actions/deploy-pages@v4
48+
cd ${{ env.ARTIFACT_PATH }}
49+
python3 ../../../scripts/generate_sitemap.py --domain "component-model.bytecodealliance.org" --higher-priority "design" --output-path sitemap.xml
50+
cd ../../../

0 commit comments

Comments
 (0)