Skip to content

Commit 2174318

Browse files
authored
CI: publish docs preview site for PRs (#48)
2 parents c556975 + eeded49 commit 2174318

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/mkdocs.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: Publish docs
22
on:
33
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- "docs/**"
9+
- "mkdocs.yml"
10+
- ".github/workflows/mkdocs.yml"
411
push:
512
branches:
613
- main
@@ -11,9 +18,69 @@ on:
1118
- "mkdocs.yml"
1219

1320
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: "docs/requirements.txt"
40+
41+
- name: Build MkDocs website
42+
run: |
43+
pip install -r docs/requirements.txt
44+
mkdocs build
45+
46+
- name: Install Netlify CLI
47+
run: npm install --location=global netlify-cli@17.x.x
48+
49+
- name: Deploy Preview to Netlify
50+
run: |
51+
netlify deploy \
52+
--alias="${GITHUB_REPOSITORY#*/}-${{ github.event.number }}" \
53+
--auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \
54+
--dir="site" \
55+
--site=${{ vars.NETLIFY_PREVIEW_APP_SITE_ID }}
56+
57+
- name: Find existing comment
58+
uses: peter-evans/find-comment@v3
59+
id: find-comment
60+
with:
61+
issue-number: ${{ github.event.number }}
62+
comment-author: "github-actions[bot]"
63+
body-includes: "Preview url: https://"
64+
65+
- name: Add Netlify link PR comment
66+
uses: actions/github-script@v7
67+
if: steps.find-comment.outputs.comment-id == ''
68+
with:
69+
github-token: ${{ secrets.GITHUB_TOKEN }}
70+
script: |
71+
const hostnameSuffix = "compiler-previews.netlify.app"
72+
github.rest.issues.createComment({
73+
issue_number: context.issue.number,
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
body: `Preview url: https://${context.repo.repo}-${{ github.event.number }}--${hostnameSuffix}`,
77+
})
78+
1479
docs:
1580
name: Publish docs
1681
runs-on: ubuntu-latest
82+
# don't publish for pull requests
83+
if: github.event.pull_request == null
1784
permissions:
1885
contents: write
1986
steps:

0 commit comments

Comments
 (0)