1+ name : Documentation Build and Preview
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ paths :
7+ - ' skainet-lang/**'
8+ - ' tools/docgen/**'
9+ - ' docs/**'
10+ - ' .github/workflows/documentation.yml'
11+ pull_request :
12+ branches : [ main, develop ]
13+ paths :
14+ - ' skainet-lang/**'
15+ - ' tools/docgen/**'
16+ - ' docs/**'
17+ - ' .github/workflows/documentation.yml'
18+
19+ jobs :
20+ build-documentation :
21+ runs-on : ubuntu-latest
22+ timeout-minutes : 30
23+
24+ steps :
25+ - name : Checkout code
26+ uses : actions/checkout@v4
27+
28+ - name : Set up JDK 17
29+ uses : actions/setup-java@v4
30+ with :
31+ java-version : ' 17'
32+ distribution : ' temurin'
33+
34+ - name : Cache Gradle packages
35+ uses : actions/cache@v4
36+ with :
37+ path : |
38+ ~/.gradle/caches
39+ ~/.gradle/wrapper
40+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
41+ restore-keys : |
42+ ${{ runner.os }}-gradle-
43+
44+ - name : Grant execute permission for gradlew
45+ run : chmod +x gradlew
46+
47+ - name : Copy CI gradle.properties
48+ run : mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
49+
50+ - name : Generate operator documentation
51+ run : ./gradlew generateDocs --stacktrace
52+
53+ - name : Upload generated documentation
54+ uses : actions/upload-artifact@v4
55+ with :
56+ name : operator-documentation
57+ path : |
58+ docs/modules/operators/_generated_/**
59+ skainet-lang/skainet-lang-core/build/generated/ksp/metadata/commonMain/resources/operators.json
60+ retention-days : 30
61+
62+ - name : Upload documentation preview (PR only)
63+ if : github.event_name == 'pull_request'
64+ uses : actions/upload-artifact@v4
65+ with :
66+ name : documentation-preview-${{ github.event.number }}
67+ path : |
68+ docs/**
69+ tools/docgen/build/docs/asciidoc/**
70+ retention-days : 7
71+
72+ # Job for documentation preview generation on PRs
73+ preview-documentation :
74+ if : github.event_name == 'pull_request'
75+ needs : build-documentation
76+ runs-on : ubuntu-latest
77+
78+ steps :
79+ - name : Download documentation artifacts
80+ uses : actions/download-artifact@v4
81+ with :
82+ name : documentation-preview-${{ github.event.number }}
83+ path : ./docs-preview
84+
85+ - name : Setup Node.js for preview server
86+ uses : actions/setup-node@v4
87+ with :
88+ node-version : ' 18'
89+
90+ - name : Install serve package
91+ run : npm install -g serve
92+
93+ - name : Start preview server
94+ run : |
95+ cd docs-preview
96+ serve -s . -l 3000 &
97+ sleep 5
98+ echo "Preview server started at http://localhost:3000"
99+
100+ - name : Create PR comment with preview link
101+ uses : actions/github-script@v7
102+ with :
103+ script : |
104+ const { data: comments } = await github.rest.issues.listComments({
105+ owner: context.repo.owner,
106+ repo: context.repo.repo,
107+ issue_number: context.issue.number,
108+ });
109+
110+ const botComment = comments.find(comment =>
111+ comment.user.type === 'Bot' &&
112+ comment.body.includes('📖 Documentation Preview')
113+ );
114+
115+ const commentBody = `📖 **Documentation Preview**
116+
117+ The documentation has been built successfully for this PR.
118+
119+ **Generated Files:**
120+ - Operator documentation: \`docs/modules/operators/_generated_/\`
121+ - JSON schema output: \`operators.json\`
122+
123+ **Artifacts:**
124+ - Download the \`documentation-preview-${{ github.event.number }}\` artifact to view the complete documentation locally.
125+
126+ _This comment will be updated automatically when the PR is updated._`;
127+
128+ if (botComment) {
129+ await github.rest.issues.updateComment({
130+ owner: context.repo.owner,
131+ repo: context.repo.repo,
132+ comment_id: botComment.id,
133+ body: commentBody
134+ });
135+ } else {
136+ await github.rest.issues.createComment({
137+ owner: context.repo.owner,
138+ repo: context.repo.repo,
139+ issue_number: context.issue.number,
140+ body: commentBody
141+ });
142+ }
0 commit comments