@@ -2,22 +2,79 @@ name: Build the documentation
22
33on :
44 pull_request :
5+ types : [opened, synchronize, reopened, closed]
56 branches : [main]
67 workflow_dispatch :
78
9+ permissions :
10+ contents : write
11+ pull-requests : write
12+
813jobs :
914 build :
10- name : Build
15+ name : Build and Deploy Documentation Preview
1116 runs-on : ubuntu-latest
1217 steps :
1318 - uses : actions/checkout@v4
19+
1420 - uses : actions/setup-python@v4
1521 with :
1622 python-version : " 3.10"
1723
24+ - name : Install dependencies
25+ if : github.event.action != 'closed'
26+ run : pip install -r requirements-doc.txt
27+
1828 - name : Build the documentation
29+ if : github.event.action != 'closed'
1930 env :
2031 GOOGLE_ANALYTICS_KEY : ${{ secrets.GOOGLE_ANALYTICS_KEY }}
21- run : |
22- pip install -r requirements-doc.txt
23- mkdocs build
32+ run : mkdocs build
33+
34+ - name : Deploy to PR preview
35+ if : github.event_name == 'pull_request'
36+ uses : rossjrw/pr-preview-action@v1
37+ with :
38+ source-dir : site/
39+ preview-branch : gh-pages
40+ umbrella-dir : pr-preview
41+ comment : false
42+
43+ - name : Comment PR with preview link
44+ if : github.event_name == 'pull_request' && github.event.action != 'closed'
45+ uses : actions/github-script@v7
46+ with :
47+ script : |
48+ const prNumber = context.issue.number;
49+ const previewUrl = `https://dottxt-ai.github.io/outlines/pr-preview/pr-${prNumber}/`;
50+
51+ // Find existing preview comment
52+ const comments = await github.rest.issues.listComments({
53+ issue_number: prNumber,
54+ owner: context.repo.owner,
55+ repo: context.repo.repo,
56+ });
57+
58+ const botComment = comments.data.find(comment =>
59+ comment.user.type === 'Bot' &&
60+ comment.body.includes('Documentation preview')
61+ );
62+
63+ const commentBody = `📚 **Documentation preview**: ${previewUrl}\n\n*Preview updates automatically with each commit.*`;
64+
65+ // Update existing comment or create new one
66+ if (botComment) {
67+ await github.rest.issues.updateComment({
68+ comment_id: botComment.id,
69+ owner: context.repo.owner,
70+ repo: context.repo.repo,
71+ body: commentBody
72+ });
73+ } else {
74+ await github.rest.issues.createComment({
75+ issue_number: prNumber,
76+ owner: context.repo.owner,
77+ repo: context.repo.repo,
78+ body: commentBody
79+ });
80+ }
0 commit comments