-
Notifications
You must be signed in to change notification settings - Fork 0
287 lines (236 loc) · 7.62 KB
/
ci.yml
File metadata and controls
287 lines (236 loc) · 7.62 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
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
release:
types: [ published ]
permissions:
contents: read
pull-requests: write
checks: write
jobs:
test:
name: Test & Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run TypeScript check
run: npm run typecheck
- name: Run linting
run: npm run lint
- name: Run tests with coverage
run: npm run test:ci
- name: Upload coverage reports
uses: codecov/codecov-action@v5
if: success()
with:
fail_ci_if_error: false
build:
name: Build & Verify Plugin
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build plugin
run: npm run build
- name: Verify build output
run: |
echo "🔍 Verifying build artifacts..."
# Check required files exist
if [ ! -f "dist/plugin.json" ]; then
echo "❌ plugin.json missing from build"
exit 1
fi
if [ ! -f "dist/module.js" ]; then
echo "❌ module.js missing from build"
exit 1
fi
# Check plugin.json is valid JSON
if ! jq empty dist/plugin.json; then
echo "❌ plugin.json is not valid JSON"
exit 1
fi
# Check plugin ID matches package.json
PLUGIN_ID=$(jq -r '.id' dist/plugin.json)
PACKAGE_NAME=$(jq -r '.name' package.json)
if [ "$PLUGIN_ID" != "$PACKAGE_NAME" ]; then
echo "❌ Plugin ID ($PLUGIN_ID) doesn't match package name ($PACKAGE_NAME)"
exit 1
fi
# Check module.js is not empty
if [ ! -s "dist/module.js" ]; then
echo "❌ module.js is empty"
exit 1
fi
echo "✅ All build artifacts verified successfully"
- name: Test plugin loading (simulation)
run: |
echo "🧪 Testing plugin structure..."
# Simulate plugin loading by checking for exports
if ! grep -q "exports" dist/module.js; then
echo "⚠️ Warning: No exports found in module.js"
fi
# Check for common Grafana panel patterns
if ! grep -q "PanelPlugin" dist/module.js; then
echo "❌ PanelPlugin not found in module.js"
exit 1
fi
echo "✅ Plugin structure tests passed"
- name: Check bundle size
run: |
echo "📦 Checking bundle size..."
BUNDLE_SIZE=$(stat -c%s dist/module.js)
MAX_SIZE=2097152 # 2MB limit
echo "Bundle size: $BUNDLE_SIZE bytes"
if [ $BUNDLE_SIZE -gt $MAX_SIZE ]; then
echo "⚠️ Warning: Bundle size ($BUNDLE_SIZE bytes) exceeds recommended limit (2MB)"
else
echo "✅ Bundle size is within limits"
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: plugin-build-${{ github.sha }}
path: dist/
retention-days: 30
security:
name: Security & Dependency Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run npm audit
run: |
echo "🔒 Running security audit..."
# Run audit and capture output
if npm audit --audit-level=high; then
echo "✅ No high-severity vulnerabilities found"
else
echo "⚠️ High-severity vulnerabilities detected"
echo "Running npm audit fix..."
# Try to auto-fix
if npm audit fix --dry-run; then
echo "📝 Auto-fixable vulnerabilities found. Run 'npm audit fix' to resolve."
fi
# Don't fail CI for audit issues, just warn
echo "⚠️ Please review security vulnerabilities"
fi
- name: Check for known vulnerabilities with Snyk
uses: snyk/actions/node@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: Dependency Review
uses: actions/dependency-review-action@v4
if: github.event_name == 'pull_request'
with:
fail-on-severity: high
package:
name: Create Release Package
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release'
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build plugin
run: npm run build
- name: Get version from package.json
id: version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Create plugin archive
run: |
cd dist
zip -r ../uptime-kuma-status-panel-${{ steps.version.outputs.version }}.zip .
cd ..
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./uptime-kuma-status-panel-${{ steps.version.outputs.version }}.zip
asset_name: uptime-kuma-status-panel-${{ steps.version.outputs.version }}.zip
asset_content_type: application/zip
# Disabled plugin signing
# sign:
# name: Sign Plugin
# runs-on: ubuntu-latest
# needs: build
# if: github.event_name == 'release' && github.repository_owner != 'grafana'
#
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
#
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: '20'
# cache: 'npm'
#
# - name: Install dependencies
# run: npm ci
#
# - name: Build plugin
# run: npm run build
#
# - name: Sign plugin
# run: npm run sign
# env:
# GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
# if: env.GRAFANA_API_KEY != ''
#
# - name: Get version from package.json
# id: version
# run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
#
# - name: Create signed plugin archive
# run: |
# cd dist
# zip -r ../uptime-kuma-status-panel-${{ steps.version.outputs.version }}-signed.zip .
# cd ..
#
# - name: Upload signed release asset
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ github.event.release.upload_url }}
# asset_path: ./uptime-kuma-status-panel-${{ steps.version.outputs.version }}-signed.zip
# asset_name: uptime-kuma-status-panel-${{ steps.version.outputs.version }}-signed.zip
# asset_content_type: application/zip