-
Notifications
You must be signed in to change notification settings - Fork 275
295 lines (254 loc) · 9.84 KB
/
Copy pathpost-deployment.yml
File metadata and controls
295 lines (254 loc) · 9.84 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# Actions done after Mintlify deployment following a push done on `main`.
# This will trigger new commits on `main`, so a new deployment of Mintlify.
name: Post Deployment
on:
workflow_dispatch:
schedule:
- cron: '0 23 * * *' # Every day at 11:00 PM UTC
push:
branches:
- 'main'
concurrency:
group: post-deployment
cancel-in-progress: false
jobs:
build-code-samples:
name: Build code samples
runs-on: ubuntu-latest
outputs:
run_openapi_automation: ${{ steps.openapi_automation.outputs.run }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.GH_TOKEN }}
- name: Get OpenAPI automation flag from docs.json
id: openapi_automation
run: |
value=$(jq -r '.. | select(type == "object" and has("internal-meili-fetch-automation")) | .["internal-meili-fetch-automation"] | select(. != null) | tostring' docs.json 2>/dev/null | head -1)
echo "run=${value:-false}" >> "$GITHUB_OUTPUT"
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Generate code sample snippets
run: npm run generate-code-sample-snippets-file
- name: Check for changes
id: changes
run: |
if git diff --quiet snippets/; then
echo "has_changes=false" >> "$GITHUB_ENV"
else
echo "has_changes=true" >> "$GITHUB_ENV"
fi
- name: Commit changes
run: |
if [[ $has_changes == "true" ]]; then
echo "There are changes in the Git working directory."
git config user.name "meili-bot"
git config user.email "robot@meilisearch.com"
git add snippets/
git commit -m "[AUTOMATION POST DEPLOYMENT] Update code samples"
git push origin main
else
echo "No changes in the Git working directory."
fi
# We need to wait for build-code-samples to commit first so we can push a separate commit
# (avoid stacking both changes in one run and keep history clear).
# Only runs when docs.json has "internal-meili-fetch-automation": true.
# In case of issues with the latest release OpenAPI file: fetch the desired OpenAPI file
# manually, then set "internal-meili-fetch-automation" to false to prevent this automation from running.
fetch-openapi-file:
name: Fetch OpenAPI file from Meilisearch release
runs-on: ubuntu-latest
needs: build-code-samples
if: needs.build-code-samples.outputs.run_openapi_automation == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Fetch latest meilisearch-openapi.json from Meilisearch release
run: npm run fetch-meilisearch-openapi-file
- name: Check for changes
id: openapi_changes
run: |
if git diff --quiet assets/open-api/meilisearch-openapi.json; then
echo "has_changes=false" >> "$GITHUB_ENV"
else
echo "has_changes=true" >> "$GITHUB_ENV"
fi
- name: Commit changes
run: |
if [[ $has_changes == "true" ]]; then
echo "There are changes in the OpenAPI file."
git config user.name "meili-bot"
git config user.email "robot@meilisearch.com"
git add assets/open-api/meilisearch-openapi.json
git commit -m "[AUTOMATION POST DEPLOYMENT] Update meilisearch-openapi.json from latest Meilisearch release"
git push origin main
else
echo "No changes in the OpenAPI file."
fi
# Runs after fetch-openapi-file: generate Mintlify OpenAPI file, validate with mint openapi-check, commit if valid.
generate-and-check-mintlify-openapi:
name: Generate and check Mintlify OpenAPI file
runs-on: ubuntu-latest
needs: [build-code-samples, fetch-openapi-file]
if: needs.build-code-samples.outputs.run_openapi_automation == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Generate Mintlify OpenAPI file
run: npm run generate-mintlify-openapi-file
- name: Validate OpenAPI with Mintlify CLI
run: npx mint openapi-check assets/open-api/meilisearch-openapi-mintlify.json
- name: Check for changes
id: mintlify_changes
run: |
if git diff --quiet assets/open-api/meilisearch-openapi-mintlify.json; then
echo "has_changes=false" >> "$GITHUB_ENV"
else
echo "has_changes=true" >> "$GITHUB_ENV"
fi
- name: Commit changes
run: |
if [[ $has_changes == "true" ]]; then
echo "There are changes in the Mintlify OpenAPI file."
git config user.name "meili-bot"
git config user.email "robot@meilisearch.com"
git add assets/open-api/meilisearch-openapi-mintlify.json
git commit -m "[AUTOMATION POST DEPLOYMENT] Update meilisearch-openapi-mintlify.json"
git push origin main
else
echo "No changes in the Mintlify OpenAPI file."
fi
# After the Mintlify OpenAPI file is updated, check if any new routes are missing
# from docs.json. If so, open a GitHub issue (unless one is already open).
check-undocumented-routes:
name: Open issue for undocumented API routes
runs-on: ubuntu-latest
needs: [build-code-samples, generate-and-check-mintlify-openapi]
if: needs.build-code-samples.outputs.run_openapi_automation == 'true'
permissions:
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Check for undocumented routes
id: coverage
run: |
set +e
output=$(npm run check-openapi-routes-coverage 2>&1)
status=$?
set -e
echo "$output"
missing=$(echo "$output" | grep '^\s*-' | sed 's/^\s*- //' || true)
if [ -n "$missing" ]; then
echo "has_missing=true" >> "$GITHUB_OUTPUT"
{
echo "missing_routes<<EOF"
echo "$missing"
echo "EOF"
} >> "$GITHUB_OUTPUT"
else
if [ "$status" -ne 0 ]; then
exit "$status"
fi
echo "has_missing=false" >> "$GITHUB_OUTPUT"
fi
- name: Check for existing open issue
if: steps.coverage.outputs.has_missing == 'true'
id: existing
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
count=$(gh issue list --search "New API routes need documentation in:title" --state open --json number --jq 'length')
echo "open_issues=$count" >> "$GITHUB_OUTPUT"
- name: Create issue for undocumented routes
if: steps.coverage.outputs.has_missing == 'true' && steps.existing.outputs.open_issues == '0'
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
MISSING_ROUTES: ${{ steps.coverage.outputs.missing_routes }}
run: |
# Build the route list as markdown
route_list=""
while IFS= read -r route; do
route_list="${route_list}- \`${route}\`
"
done <<< "$MISSING_ROUTES"
gh issue create \
--title "New API routes need documentation" \
--body "The OpenAPI spec was updated and the following routes are not yet documented in \`docs.json\`:
${route_list}
**Next steps:**
1. Add the missing route(s) to \`docs.json\` under the appropriate API reference group
2. Run \`npm run check-openapi-routes-coverage\` to verify
_This issue was created automatically by the post-deployment workflow._"
# Runs alongside the OpenAPI automation. A new Meilisearch release triggers both
# the OpenAPI update and the changelog update at the same time.
# Only runs when docs.json has "internal-meili-fetch-automation": true.
update-changelog:
name: Update changelog if new release exists
runs-on: ubuntu-latest
needs: [build-code-samples]
if: needs.build-code-samples.outputs.run_openapi_automation == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Generate changelog
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: npm run generate-changelog
- name: Commit changes
run: |
if git diff --quiet changelog/; then
echo "No changelog changes detected."
else
git config user.name "meili-bot"
git config user.email "robot@meilisearch.com"
git add changelog/
git commit -m "[AUTOMATION POST DEPLOYMENT] Update changelog with latest Meilisearch release"
git push origin main
fi