-
Notifications
You must be signed in to change notification settings - Fork 325
441 lines (372 loc) · 16.1 KB
/
sync-plugins.yml
File metadata and controls
441 lines (372 loc) · 16.1 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
name: Sync Plugin Documentation
on:
issues:
types: [opened]
workflow_dispatch:
inputs:
plugins:
description: 'Plugin names to sync (comma-separated, or "all")'
required: true
default: 'all'
source_commit:
description: 'influxdb3_plugins commit SHA or branch'
required: false
default: 'main'
permissions:
contents: write
pull-requests: write
issues: write
jobs:
sync-plugins:
runs-on: ubuntu-latest
# Only run on issues with sync-plugin-docs label or manual dispatch
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'issues' && contains(github.event.issue.labels.*.name, 'sync-plugin-docs'))
steps:
- name: Parse issue inputs
id: parse-inputs
if: github.event_name == 'issues'
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const body = issue.body || '';
// Extract plugins and source_commit from issue body
const pluginsMatch = body.match(/### Plugin Names\s*\n\s*(.+)/);
const commitMatch = body.match(/### Source Commit\/Branch\s*\n\s*(.+)/);
const plugins = pluginsMatch ? pluginsMatch[1].trim() : 'all';
const sourceCommit = commitMatch ? commitMatch[1].trim() : 'main';
core.setOutput('plugins', plugins);
core.setOutput('source_commit', sourceCommit);
core.setOutput('issue_number', issue.number);
- name: Set workflow inputs
id: inputs
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "plugins=${{ github.event.inputs.plugins }}" >> $GITHUB_OUTPUT
echo "source_commit=${{ github.event.inputs.source_commit }}" >> $GITHUB_OUTPUT
echo "issue_number=" >> $GITHUB_OUTPUT
else
echo "plugins=${{ steps.parse-inputs.outputs.plugins }}" >> $GITHUB_OUTPUT
echo "source_commit=${{ steps.parse-inputs.outputs.source_commit }}" >> $GITHUB_OUTPUT
echo "issue_number=${{ steps.parse-inputs.outputs.issue_number }}" >> $GITHUB_OUTPUT
fi
- name: Update issue status
if: steps.inputs.outputs.issue_number != ''
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.inputs.outputs.issue_number }},
body: '🔄 Plugin sync started...\n\nPlugins: `${{ steps.inputs.outputs.plugins }}`\nSource: `${{ steps.inputs.outputs.source_commit }}`'
});
- name: Checkout docs-v2
uses: actions/checkout@v4
with:
path: docs-v2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout influxdb3_plugins (sparse)
uses: actions/checkout@v4
with:
repository: influxdata/influxdb3_plugins
token: ${{ secrets.PLUGINS_CONTENT_READ_TOKEN }}
path: .ext/influxdb3_plugins
sparse-checkout: |
influxdata/
scripts/
ref: ${{ steps.inputs.outputs.source_commit }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: docs-v2/yarn.lock
- name: Install dependencies
run: |
cd docs-v2
CYPRESS_INSTALL_BINARY=0 yarn install
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Validate plugin READMEs
id: validate
run: |
cd .ext/influxdb3_plugins
# Determine which plugins to validate
if [[ "${{ steps.inputs.outputs.plugins }}" == "all" ]]; then
PLUGINS=""
else
PLUGINS="${{ steps.inputs.outputs.plugins }}"
fi
# Run validation with --errors-only flag (warnings are OK, only errors fail)
if [[ -n "$PLUGINS" ]]; then
echo "Validating specific plugins: $PLUGINS"
python scripts/validate_readme.py --plugins "$PLUGINS" --errors-only 2>&1 | tee validation.log
else
echo "Validating all plugins"
python scripts/validate_readme.py --errors-only 2>&1 | tee validation.log
fi
# Check if validation passed
if [[ ${PIPESTATUS[0]} -eq 0 ]]; then
echo "validation_passed=true" >> $GITHUB_OUTPUT
else
echo "validation_passed=false" >> $GITHUB_OUTPUT
fi
- name: Report validation failure
if: steps.validate.outputs.validation_passed == 'false'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let validationLog = '';
try {
validationLog = fs.readFileSync('influxdb3_plugins/validation.log', 'utf8');
} catch (e) {
validationLog = 'Could not read validation log';
}
const issueNumber = '${{ steps.inputs.outputs.issue_number }}';
if (issueNumber) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issueNumber),
body: `❌ **Validation Failed**
Plugin READMEs do not meet template requirements. Please fix the following issues in influxdb3_plugins:
\`\`\`
${validationLog}
\`\`\`
See [README_TEMPLATE.md](https://github.com/influxdata/influxdb3_plugins/blob/main/README_TEMPLATE.md) for requirements.`
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issueNumber),
state: 'closed',
labels: ['sync-plugin-docs', 'validation-failed']
});
}
core.setFailed('Plugin validation failed');
- name: Debug - Check file structure
if: steps.validate.outputs.validation_passed == 'true'
run: |
echo "======================================"
echo "DEBUG: Checking file structure"
echo "======================================"
echo ""
echo "1. Current working directory:"
pwd
echo ""
echo "2. List workspace root:"
ls -la
echo ""
echo "3. Check if .ext exists:"
if [ -d ".ext" ]; then
echo "✅ .ext directory exists"
ls -la .ext/
else
echo "❌ .ext directory NOT found"
fi
echo ""
echo "4. Check if .ext/influxdb3_plugins exists:"
if [ -d ".ext/influxdb3_plugins" ]; then
echo "✅ .ext/influxdb3_plugins exists"
ls -la .ext/influxdb3_plugins/
else
echo "❌ .ext/influxdb3_plugins NOT found"
fi
echo ""
echo "5. Check if influxdata directory exists:"
if [ -d ".ext/influxdb3_plugins/influxdata" ]; then
echo "✅ influxdata directory exists"
ls -la .ext/influxdb3_plugins/influxdata/
else
echo "❌ influxdata directory NOT found"
fi
echo ""
echo "6. Check if basic_transformation exists:"
if [ -d ".ext/influxdb3_plugins/influxdata/basic_transformation" ]; then
echo "✅ basic_transformation directory exists"
ls -la .ext/influxdb3_plugins/influxdata/basic_transformation/
else
echo "❌ basic_transformation directory NOT found"
fi
echo ""
echo "7. Now checking from script directory:"
cd docs-v2/helper-scripts/influxdb3-plugins
echo "Current directory:"
pwd
echo ""
echo "8. Trying to access with ../../../.ext/influxdb3_plugins:"
if [ -d "../../../.ext/influxdb3_plugins" ]; then
echo "✅ Can access via ../../../.ext/influxdb3_plugins"
ls -la ../../../.ext/influxdb3_plugins/
else
echo "❌ Cannot access via ../../../.ext/influxdb3_plugins"
fi
echo ""
echo "9. Checking all possible paths from script dir:"
echo "Checking ../.ext/influxdb3_plugins:"
ls -la ../.ext/influxdb3_plugins/ 2>&1 || echo "❌ Not found"
echo ""
echo "Checking ../../.ext/influxdb3_plugins:"
ls -la ../../.ext/influxdb3_plugins/ 2>&1 || echo "❌ Not found"
echo ""
echo "Checking ../../../.ext/influxdb3_plugins:"
ls -la ../../../.ext/influxdb3_plugins/ 2>&1 || echo "❌ Not found"
echo ""
echo "======================================"
echo "DEBUG: Complete"
echo "======================================"
- name: Transform plugin documentation
if: steps.validate.outputs.validation_passed == 'true'
run: |
cd docs-v2/helper-scripts/influxdb3-plugins
# Set path to plugins repo (relative from script directory)
export INFLUXDB3_PLUGINS_PATH="../../../.ext/influxdb3_plugins"
# Run the transformation
if [[ "${{ steps.inputs.outputs.plugins }}" == "all" ]]; then
node port_to_docs.js # ← CHANGE: Script is in current dir now
else
# Transform specific plugins
IFS=',' read -ra PLUGIN_ARRAY <<< "${{ steps.inputs.outputs.plugins }}"
for plugin in "${PLUGIN_ARRAY[@]}"; do
plugin=$(echo "$plugin" | xargs) # trim whitespace
echo "Transforming plugin: $plugin"
node port_to_docs.js --plugin "$plugin"
done
fi
- name: Build Hugo site
run: |
cd docs-v2
npx hugo --quiet --minify
- name: Setup Playwright
run: |
cd docs-v2
npm install playwright
npx playwright install chromium
- name: Generate screenshots
if: false # Disable screenshots for MVP
id: screenshots
run: |
cd docs-v2
# Start Hugo server in background
npx hugo server --bind 0.0.0.0 --port 1313 --quiet &
HUGO_PID=$!
# Wait for server to start
sleep 10
# Create screenshots directory
mkdir -p plugin-screenshots
# Generate screenshots for changed plugin pages
node -e "
const { chromium } = require('playwright');
const fs = require('fs');
const path = require('path');
async function captureScreenshots() {
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
// Find changed plugin files
const glob = require('glob');
const pluginFiles = glob.sync('content/shared/influxdb3-plugins/plugins-library/**/*.md');
for (const file of pluginFiles) {
const pluginName = path.basename(file, '.md');
const url = \`http://localhost:1313/influxdb3/core/reference/plugins/\${pluginName}/\`;
try {
console.log(\`Capturing screenshot for \${pluginName}\`);
await page.goto(url, { waitUntil: 'networkidle' });
await page.screenshot({
path: \`plugin-screenshots/\${pluginName}.png\`,
fullPage: true
});
} catch (error) {
console.log(\`Could not capture \${pluginName}: \${error.message}\`);
}
}
await browser.close();
}
captureScreenshots().catch(console.error);
"
# Stop Hugo server
kill $HUGO_PID
# List generated screenshots
ls -la plugin-screenshots/ || echo "No screenshots generated"
echo "screenshots_generated=$(ls plugin-screenshots/ 2>/dev/null | wc -l)" >> $GITHUB_OUTPUT
- name: Create Pull Request
if: steps.validate.outputs.validation_passed == 'true'
id: create-pr
uses: peter-evans/create-pull-request@v5
with:
path: docs-v2
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: |
sync: update plugin documentation from influxdb3_plugins@${{ steps.inputs.outputs.source_commit }}
Plugins: ${{ steps.inputs.outputs.plugins }}
branch: sync-plugins-${{ github.run_number }}
title: "Sync plugin documentation: ${{ steps.inputs.outputs.plugins }}"
body: |
## Plugin Documentation Sync
**Source**: influxdb3_plugins@${{ steps.inputs.outputs.source_commit }}
**Plugins**: ${{ steps.inputs.outputs.plugins }}
**Triggered by**: ${{ github.event_name == 'issues' && format('Issue #{0}', steps.inputs.outputs.issue_number) || 'Manual workflow dispatch' }}
### Changes Made
- ✅ Validated source READMEs against template requirements
- 🔄 Transformed content for docs-v2 compatibility
- 🖼️ Generated ${{ steps.screenshots.outputs.screenshots_generated }} plugin page screenshots
### Transformations Applied
- Removed emoji metadata (already in plugin JSON metadata)
- Converted relative links to GitHub URLs
- Added Hugo product shortcodes (`{{% product-name %}}`)
- Added standard logging section
- Updated support sections with docs-v2 format
### Screenshots
Plugin page previews are available in the `plugin-screenshots/` directory (if any were generated).
### Review Checklist
- [ ] All plugin pages render correctly
- [ ] GitHub links resolve properly
- [ ] Product shortcodes display correctly
- [ ] Code examples are properly formatted
- [ ] Support sections link correctly
---
*This PR was automatically generated by the plugin sync workflow.*
- name: Update issue with success
if: steps.validate.outputs.validation_passed == 'true' && steps.inputs.outputs.issue_number != ''
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.inputs.outputs.issue_number }},
body: `✅ **Plugin sync completed successfully!**
**Pull Request**: #${{ steps.create-pr.outputs.pull-request-number }}
**Plugins synced**: ${{ steps.inputs.outputs.plugins }}
**Source commit**: ${{ steps.inputs.outputs.source_commit }}
**Screenshots generated**: ${{ steps.screenshots.outputs.screenshots_generated }}
The PR is ready for review and includes all necessary transformations and validations.`
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.inputs.outputs.issue_number }},
state: 'closed',
labels: ['sync-plugin-docs', 'completed']
});
- name: Report failure
if: failure() && steps.inputs.outputs.issue_number != ''
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.inputs.outputs.issue_number }},
body: `❌ **Plugin sync failed**
Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
You may need to:
- Check that the source commit exists
- Verify plugin names are correct
- Ensure all validation requirements are met`
});