Skip to content

Commit 6d9a8c1

Browse files
refactor(ci): use reusable action
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 08dd692 commit 6d9a8c1

File tree

3 files changed

+104
-82
lines changed

3 files changed

+104
-82
lines changed

.github/actions/mdbook.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: mdbook
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
publish-pages-artifact:
7+
type: boolean
8+
required: false
9+
default: false
10+
description: |
11+
Whether to publish a pages artifact
12+
13+
publish-domain:
14+
type: string
15+
required: false
16+
default: "component-model.bytecodealliance.org"
17+
description: |
18+
Path to which to store the artifac
19+
20+
mdbook-version:
21+
type: string
22+
required: false
23+
default: "0.4.21"
24+
description: |
25+
Version of mdbook to use (ex. '0.4.21')
26+
27+
mdbook-alerts-version:
28+
type: string
29+
required: false
30+
default: "0.6.7"
31+
description: |
32+
Version of mdbook-alerts to use (ex. '0.6.7')
33+
34+
mdbook-alerts-version:
35+
type: string
36+
required: false
37+
default: "0.7.7"
38+
description: |
39+
Version of mdbook-linkcheck to use (ex. '0.7.7')
40+
41+
env:
42+
ARTIFACT_PATH: ./component-model/book/html
43+
44+
jobs:
45+
build:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
50+
- uses: taiki-e/cache-cargo-install-action@v2
51+
with:
52+
tool: mdbook@${{ inputs.mdbook-version }}
53+
54+
- uses: taiki-e/cache-cargo-install-action@v2
55+
with:
56+
tool: mdbook-alerts@${{ inputs.mdbook-alerts-version }}
57+
58+
- uses: taiki-e/cache-cargo-install-action@v2
59+
with:
60+
tool: mdbook-linkcheck@${{ inputs.mdbook-linkcheck-version }}
61+
62+
- name: Build with mdBook
63+
run: mdbook build component-model
64+
65+
- name: Setup Python
66+
uses: actions/setup-python@v5
67+
with:
68+
python-version: '3.13'
69+
70+
- name: Ensure build outputs are present
71+
shell: bash
72+
run: |
73+
if [[ ! -f "${{ env.ARTIFACT_PATH }}/index.html" ]]; then
74+
echo "[error] index.html @ [${{ env.ARTIFACT_PATH }}] is missing. Build or path misconfigured";
75+
exit 1;
76+
fi
77+
78+
- name: Generate sitemap
79+
shell: bash
80+
run: |
81+
cd ${{ env.ARTIFACT_PATH }}
82+
python3 ../../../scripts/generate_sitemap.py \
83+
--domain "${{ inputs.publish-domain }}" \
84+
--higher-priority "design" \
85+
--output-path sitemap.xml
86+
cd ../../../
87+
88+
- name: Setup Pages
89+
if: ${{ inputs.publish-pages-artifact }}
90+
id: pages
91+
uses: actions/configure-pages@v3
92+
93+
- name: Upload artifact
94+
if: ${{ inputs.publish-pages-artifact }}
95+
uses: actions/upload-pages-artifact@v3
96+
with:
97+
path: ${{ env.ARTIFACT_PATH }}

.github/workflows/deploy.yml

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,58 +27,18 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- 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
30+
31+
- uses: ../actions/mdbook.yml
4832
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 }}
33+
publish-pages: true
7434

7535
deploy:
7636
if: ${{ github.repository_owner == 'bytecodealliance' }}
37+
needs:
38+
- build
7739
environment:
7840
name: github-pages
7941
url: ${{ steps.deployment.outputs.page_url }}
80-
runs-on: ubuntu-latest
81-
needs: build
8242
steps:
8343
- name: Deploy to GitHub Pages
8444
id: deployment

.github/workflows/mdbook.yml

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,13 @@ name: mdbook
33
on:
44
pull_request:
55

6-
env:
7-
MDBOOK_VERSION: 0.4.21
8-
MDBOOK_ALERTS_VERSION: 0.6.7
9-
MDBOOK_LINKCHECK_VERSION: 0.7.7
10-
116
jobs:
127
build:
138
runs-on: ubuntu-latest
149
steps:
1510
- uses: actions/checkout@v3
1611

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-
29-
- name: Build with mdBook
30-
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-
40-
- name: Setup Python
41-
uses: actions/setup-python@v5
12+
- uses: ../actions/mdbook.yml
4213
with:
43-
python-version: '3.13'
14+
publish-pages: true
4415

45-
- name: Generate sitemap
46-
shell: bash
47-
run: |
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)