Skip to content

Commit 3df8e62

Browse files
committed
build and preview docs on PR
1 parent 4826030 commit 3df8e62

1 file changed

Lines changed: 92 additions & 8 deletions

File tree

.github/workflows/build_docs.yml

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
8+
paths:
9+
- 'quaddtype/**'
710
workflow_dispatch: # Make sure this job can be triggered manually
811

12+
# Allow only one concurrent deployment per PR/branch
13+
concurrency:
14+
group: pages-${{ github.ref }}
15+
cancel-in-progress: true
16+
917
jobs:
1018
build:
1119
runs-on: ubuntu-latest
12-
permissions:
13-
contents: read
14-
pages: write
15-
id-token: write
1620
steps:
1721
- uses: actions/checkout@v6
18-
- uses: actions/configure-pages@v5
1922
- uses: actions/setup-python@v6
2023
with:
2124
python-version: '3.13'
@@ -33,11 +36,92 @@ jobs:
3336
cd quaddtype/
3437
python -m pip install ."[docs]"
3538
cd docs/
36-
sphinx-build -b html . _build/html/quaddtype
37-
- name: Upload artifact
38-
uses: actions/upload-pages-artifact@v4
39+
sphinx-build -b html . _build/html
40+
- name: Upload docs artifact
41+
uses: actions/upload-artifact@v4
3942
with:
43+
name: docs-html
4044
path: './quaddtype/docs/_build/html'
45+
46+
# Deploy main docs to GitHub Pages (only on push to main)
47+
deploy-main:
48+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
49+
needs: build
50+
runs-on: ubuntu-latest
51+
permissions:
52+
contents: read
53+
pages: write
54+
id-token: write
55+
environment:
56+
name: github-pages
57+
url: ${{ steps.deployment.outputs.page_url }}
58+
steps:
59+
- uses: actions/configure-pages@v5
60+
- name: Download docs artifact
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: docs-html
64+
path: './docs-html'
65+
- name: Upload pages artifact
66+
uses: actions/upload-pages-artifact@v4
67+
with:
68+
path: './docs-html'
4169
- name: Deploy to GitHub Pages
4270
id: deployment
4371
uses: actions/deploy-pages@v4
72+
73+
# Deploy PR preview (only on pull requests)
74+
deploy-preview:
75+
if: github.event_name == 'pull_request'
76+
needs: build
77+
runs-on: ubuntu-latest
78+
permissions:
79+
contents: write
80+
pull-requests: write
81+
steps:
82+
- uses: actions/checkout@v6
83+
- name: Download docs artifact
84+
uses: actions/download-artifact@v4
85+
with:
86+
name: docs-html
87+
path: './docs-html'
88+
- name: Deploy PR Preview
89+
uses: rossjrw/pr-preview-action@v1
90+
with:
91+
source-dir: './docs-html'
92+
preview-branch: gh-pages
93+
umbrella-dir: pr-preview
94+
action: auto
95+
- name: Comment PR with preview URL
96+
uses: actions/github-script@v7
97+
with:
98+
script: |
99+
const previewUrl = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/`;
100+
const body = `📚 **Documentation Preview**\n\nPreview URL: ${previewUrl}\n\n_This preview will be automatically updated when you push new commits._`;
101+
102+
// Check if we already commented
103+
const { data: comments } = await github.rest.issues.listComments({
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
issue_number: context.issue.number,
107+
});
108+
109+
const botComment = comments.find(comment =>
110+
comment.user.type === 'Bot' && comment.body.includes('Documentation Preview')
111+
);
112+
113+
if (botComment) {
114+
await github.rest.issues.updateComment({
115+
owner: context.repo.owner,
116+
repo: context.repo.repo,
117+
comment_id: botComment.id,
118+
body: body
119+
});
120+
} else {
121+
await github.rest.issues.createComment({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
issue_number: context.issue.number,
125+
body: body
126+
});
127+
}

0 commit comments

Comments
 (0)