-
Notifications
You must be signed in to change notification settings - Fork 15
160 lines (134 loc) · 5.63 KB
/
Copy pathdocumentation.yml
File metadata and controls
160 lines (134 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Documentation Build and Preview
on:
push:
branches: [ main, develop ]
paths:
- 'skainet-lang/**'
- 'tools/docgen/**'
- 'docs/**'
- '.github/workflows/documentation.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'skainet-lang/**'
- 'tools/docgen/**'
- 'docs/**'
- '.github/workflows/documentation.yml'
# Set default permission for all jobs to none. Only preview-documentation posts
# the PR comment, so pull-requests:write lives there rather than build-wide.
permissions: {}
jobs:
build-documentation:
runs-on: ubuntu-latest
timeout-minutes: 40
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up JDK 25
uses: actions/setup-java@dd06d9cba3e5552c54d9f8ea23572deb30010f7c # v6.0.0
with:
java-version: '25'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
- name: Generate operator documentation
run: ./gradlew generateDocs --stacktrace
- name: Upload generated documentation
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: operator-documentation
path: |
docs/modules/operators/_generated_/**
skainet-lang/skainet-lang-core/build/generated/ksp/metadata/commonMain/resources/operators.json
retention-days: 30
- name: Upload documentation preview (PR only)
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: documentation-preview-${{ github.event.number }}
path: |
docs/**
tools/docgen/build/docs/asciidoc/**
retention-days: 7
# Job for documentation preview generation on PRs
preview-documentation:
if: github.event_name == 'pull_request'
needs: build-documentation
runs-on: ubuntu-latest
# Posts the preview comment via actions/github-script. PR comments are issue
# comments, so pull-requests:write is what listComments/createComment need.
permissions:
contents: read
pull-requests: write
steps:
- name: Download documentation artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: documentation-preview-${{ github.event.number }}
path: ./docs-preview
- name: Setup Node.js for preview server
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '18'
- name: Install serve package
run: npm install -g serve
- name: Start preview server
run: |
cd docs-preview
serve -s . -l 3000 &
sleep 5
echo "Preview server started at http://localhost:3000"
- name: Create PR comment with preview link
# Fork PRs get a read-only GITHUB_TOKEN, so commenting is impossible
# regardless of the workflow's `permissions:` block. Only attempt on
# same-repo PRs, and never let a failed comment fail the whole run.
if: github.event.pull_request.head.repo.full_name == github.repository
continue-on-error: true
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📖 Documentation Preview')
);
const commentBody = `📖 **Documentation Preview**
The documentation has been built successfully for this PR.
**Generated Files:**
- Operator documentation: \`docs/modules/operators/_generated_/\`
- JSON schema output: \`operators.json\`
**Artifacts:**
- Download the \`documentation-preview-${{ github.event.number }}\` artifact to view the complete documentation locally.
_This comment will be updated automatically when the PR is updated._`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}