Skip to content

Commit 08dd692

Browse files
feat(ci): run mdbook on pull requests
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 7f7681a commit 08dd692

File tree

2 files changed

+104
-60
lines changed

2 files changed

+104
-60
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: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,34 @@
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"]
11-
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
4+
pull_request:
265

276
env:
287
MDBOOK_VERSION: 0.4.21
298
MDBOOK_ALERTS_VERSION: 0.6.7
309
MDBOOK_LINKCHECK_VERSION: 0.7.7
31-
PUBLISH_DOMAIN: component-model.bytecodealliance.org
32-
ARTIFACT_PATH: ./component-model/book/html
3310

3411
jobs:
3512
build:
3613
runs-on: ubuntu-latest
3714
steps:
3815
- uses: actions/checkout@v3
39-
- name: Install mdBook
40-
run: |
41-
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
42-
rustup update
43-
cargo install --version ${{ env.MDBOOK_VERSION }} mdbook
44-
cargo install --version ${{ env.MDBOOK_ALERTS_VERSION }} mdbook-alerts
45-
cargo install --version ${{ env.MDBOOK_LINKCHECK_VERSION }} mdbook-linkcheck
4616

47-
- name: Build with mdBook
48-
run: mdbook build component-model
17+
- uses: taiki-e/cache-cargo-install-action@v2
18+
with:
19+
tool: mdbook@${{ env.MDBOOK_VERSION }}
4920

50-
- name: Setup Python
51-
uses: actions/setup-python@v5
21+
- uses: taiki-e/cache-cargo-install-action@v2
5222
with:
53-
python-version: '3.13'
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+
29+
- name: Build with mdBook
30+
run: mdbook build component-model
5431

55-
# Ensure the build generated properly
5632
- name: Ensure build outputs are present
5733
shell: bash
5834
run: |
@@ -61,31 +37,14 @@ jobs:
6137
exit 1;
6238
fi
6339
40+
- name: Setup Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: '3.13'
44+
6445
- name: Generate sitemap
6546
shell: bash
6647
run: |
6748
cd ${{ env.ARTIFACT_PATH }}
6849
python3 ../../../scripts/generate_sitemap.py --domain "component-model.bytecodealliance.org" --higher-priority "design" --output-path sitemap.xml
6950
cd ../../../
70-
71-
- name: Setup Pages
72-
id: pages
73-
uses: actions/configure-pages@v3
74-
75-
- name: Upload artifact
76-
uses: actions/upload-pages-artifact@v3
77-
with:
78-
path: ${{ env.ARTIFACT_PATH }}
79-
80-
# Deployment job
81-
deploy:
82-
if: ${{ github.repository_owner == 'bytecodealliance' }}
83-
environment:
84-
name: github-pages
85-
url: ${{ steps.deployment.outputs.page_url }}
86-
runs-on: ubuntu-latest
87-
needs: build
88-
steps:
89-
- name: Deploy to GitHub Pages
90-
id: deployment
91-
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)