Skip to content

Commit 8dbe91f

Browse files
committed
feat(ci): docs preview and deploy workflow
1 parent e9cbd78 commit 8dbe91f

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

.github/workflows/mkdocs.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Publish docs
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- "docs/**"
9+
- "mkdocs.yml"
10+
- ".github/workflows/mkdocs.yml"
11+
push:
12+
branches:
13+
- main
14+
paths:
15+
- ".github/workflows/mkdocs.yml"
16+
- "docs/**"
17+
- ".markdownlint.yaml"
18+
- "mkdocs.yml"
19+
20+
jobs:
21+
docs-preview:
22+
name: Publish docs preview
23+
runs-on: ubuntu-latest
24+
# only pull requests should generate a preview
25+
if: github.event.pull_request
26+
permissions:
27+
pull-requests: write
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
ref: "refs/pull/${{ github.event.number }}/merge"
33+
34+
- name: Setup Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version-file: .github/workflows/.python-version
38+
cache: pip
39+
cache-dependency-path: |
40+
"**/pyproject.toml"
41+
"docs/requirements.txt"
42+
43+
- name: Build MkDocs website
44+
run: |
45+
pip install .[dev] -r docs/requirements.txt
46+
mkdocs build
47+
48+
- name: Install Netlify CLI
49+
run: npm install --location=global netlify-cli@17.x.x
50+
51+
- name: Deploy Preview to Netlify
52+
run: |
53+
netlify deploy \
54+
--alias="${GITHUB_REPOSITORY#*/}-${{ github.event.number }}" \
55+
--auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \
56+
--dir="site" \
57+
--site=${{ vars.NETLIFY_PREVIEW_APP_SITE_ID }}
58+
59+
- name: Find existing comment
60+
uses: peter-evans/find-comment@v3
61+
id: find-comment
62+
with:
63+
issue-number: ${{ github.event.number }}
64+
comment-author: "github-actions[bot]"
65+
body-includes: "Preview url: https://"
66+
67+
- name: Add Netlify link PR comment
68+
uses: actions/github-script@v7
69+
if: steps.find-comment.outputs.comment-id == ''
70+
with:
71+
github-token: ${{ secrets.GITHUB_TOKEN }}
72+
script: |
73+
const hostnameSuffix = "compiler-previews.netlify.app"
74+
github.rest.issues.createComment({
75+
issue_number: context.issue.number,
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
body: `Preview url: https://${context.repo.repo}-${{ github.event.number }}--${hostnameSuffix}`,
79+
})
80+
81+
docs:
82+
name: Publish docs
83+
runs-on: ubuntu-latest
84+
# don't publish for pull requests
85+
if: github.event.pull_request == null
86+
permissions:
87+
contents: write
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v4
91+
92+
- uses: actions/setup-python@v5
93+
with:
94+
python-version-file: .github/workflows/.python-version
95+
cache: pip
96+
cache-dependency-path: |
97+
"**/pyproject.toml"
98+
"docs/requirements.txt"
99+
100+
- name: Install MkDocs requirements
101+
run: |
102+
pip install .[dev] -r docs/requirements.txt
103+
104+
- name: Deploy MkDocs website
105+
run: |
106+
mkdocs gh-deploy --force

0 commit comments

Comments
 (0)