-
Notifications
You must be signed in to change notification settings - Fork 0
440 lines (386 loc) · 17.4 KB
/
main.yml
File metadata and controls
440 lines (386 loc) · 17.4 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
name: Main CI/CD Pipeline
on:
push:
branches:
- main
workflow_dispatch:
jobs:
setup:
name: "Step 0: Setup"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Installing Dependencies"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📥 Running npm ci..."
npm ci
echo "✅ Dependencies installed successfully"
test:
name: "Step 1: Run Tests"
runs-on: ubuntu-latest
needs: setup
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: npm ci
- name: "Run Tests"
working-directory: ./scripts
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧪 Step 1/10: Running Test Suite"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Executing all test cases..."
npm test
echo "✅ Tests completed successfully"
coverage:
name: "Step 2: Check Coverage"
runs-on: ubuntu-latest
needs: test
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: npm ci
- name: "Check Test Coverage"
working-directory: ./scripts
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 Step 2/10: Checking Test Coverage"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔍 Checking if new functions have test coverage..."
git fetch origin main:main || true
BASE_SHA=$(git merge-base HEAD~1 HEAD 2>/dev/null || echo "HEAD~1")
echo "📌 Comparing against commit: $BASE_SHA"
npm run test:check-diff || npm run test:check
echo "✅ Coverage check completed"
version-check:
name: "Step 3-4: Version & Tag Check"
runs-on: ubuntu-latest
needs: coverage
permissions:
contents: write
outputs:
version: ${{ steps.final_version.outputs.version }}
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: npm ci
- name: "Get Current Version"
id: current_version
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Step 3/10: Detecting Version"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔍 Reading version from package.json..."
VERSION=$(node -p "require('./scripts/package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "✅ Current version: $VERSION"
- name: "Check if Tag Exists and Increment Version"
id: version_increment
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🏷️ Step 4/10: Checking Git Tag & Incrementing Version"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
TAG="v${CURRENT_VERSION}"
echo "🔍 Checking if tag $TAG already exists..."
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null 2>&1; then
echo "⚠️ Tag $TAG already exists, incrementing version..."
# Extract base version (remove -BETA, -ALPHA, etc.)
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-.*//')
SUFFIX=$(echo "$CURRENT_VERSION" | sed 's/.*-//' || echo "")
# Parse version parts
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
# Increment patch version
PATCH=$((PATCH + 1))
# If patch reaches 10, increment minor and reset patch
if [ $PATCH -ge 10 ]; then
PATCH=0
MINOR=$((MINOR + 1))
fi
# If minor reaches 10, increment major and reset minor
if [ $MINOR -ge 10 ]; then
MINOR=0
MAJOR=$((MAJOR + 1))
fi
# Reconstruct version with BETA suffix
if [ -n "$SUFFIX" ]; then
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-${SUFFIX}"
else
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-BETA"
fi
echo "📈 Incrementing version: $CURRENT_VERSION -> $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "needs_increment=true" >> $GITHUB_OUTPUT
else
echo "✅ Tag $TAG does not exist, using current version"
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "needs_increment=false" >> $GITHUB_OUTPUT
fi
- name: "Update Version in Files"
if: steps.version_increment.outputs.needs_increment == 'true'
run: |
NEW_VERSION="${{ steps.version_increment.outputs.new_version }}"
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
echo "📝 Updating version in package.json..."
cd scripts
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '$NEW_VERSION';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
echo "📝 Updating version in phantom.js..."
cd ..
sed -i.bak "s/$CURRENT_VERSION/$NEW_VERSION/g" phantom.js
rm -f phantom.js.bak
echo "✅ Version updated to $NEW_VERSION"
- name: "Commit Version Update"
if: steps.version_increment.outputs.needs_increment == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add scripts/package.json phantom.js
git commit -m "chore: Auto-increment version to ${{ steps.version_increment.outputs.new_version }} [skip ci]" || exit 0
git push origin main || exit 0
echo "✅ Version update committed"
- name: "Set Final Version"
id: final_version
run: |
FINAL_VERSION="${{ steps.version_increment.outputs.new_version }}"
echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
echo "✅ Final version: $FINAL_VERSION"
minify:
name: "Step 5: Generate Minified"
runs-on: ubuntu-latest
needs: version-check
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: npm ci
- name: "Generate Minified File"
working-directory: ./scripts
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🗜️ Step 5/10: Generating Minified File"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📝 Minifying phantom.js..."
npm run minify
echo "✅ Minified file created: phantom.min.js"
package:
name: "Step 6: Create Package"
runs-on: ubuntu-latest
needs: [version-check, minify]
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: npm ci
- name: "Create Release Package"
working-directory: ./scripts
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Step 6/10: Creating Release Package"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Packaging files into zip archive..."
npm run release
echo "✅ Release package created successfully"
tag:
name: "Step 7: Create Git Tag"
runs-on: ubuntu-latest
needs: [version-check, package]
permissions:
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Create Git Tag"
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🏷️ Step 7/10: Creating Git Tag"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
TAG="v${{ needs.version-check.outputs.version }}"
echo "🔍 Checking if tag $TAG already exists..."
# Fetch all tags first
git fetch --tags
# Check if tag exists locally or remotely
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null 2>&1; then
echo "⚠️ Tag $TAG already exists locally, deleting it..."
git tag -d "$TAG" || true
fi
# Check remote
if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
echo "⚠️ Tag $TAG already exists on remote, deleting it..."
git push origin ":refs/tags/$TAG" || true
fi
echo "📝 Creating annotated tag: $TAG"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG: Auto-generated from main branch merge"
echo "📤 Pushing tag to remote..."
git push origin "$TAG"
echo "✅ Tag $TAG created and pushed successfully"
release-notes:
name: "Step 8: Generate Release Notes"
runs-on: ubuntu-latest
needs: [version-check, tag]
outputs:
notes: ${{ steps.release_notes.outputs.notes }}
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'scripts/package-lock.json'
- name: "Install dependencies"
working-directory: ./scripts
run: npm ci
- name: "Generate Release Notes"
id: release_notes
working-directory: ./scripts
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📝 Step 8/10: Generating Release Notes"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
VERSION="${{ needs.version-check.outputs.version }}"
echo "📋 Analyzing commits since last release..."
echo "🔍 Extracting features, fixes, and changes..."
node generate-release-notes.js "${VERSION}" > /tmp/release_notes.txt || {
echo "⚠️ Failed to generate release notes, using default template"
printf "## Release v%s\n\nThis release includes bug fixes and improvements.\n\n### Changes\n- See commit history for details\n" "${VERSION}" > /tmp/release_notes.txt
}
{
echo "notes<<EOF"
cat /tmp/release_notes.txt
echo "EOF"
} >> $GITHUB_OUTPUT
echo "✅ Release notes generated successfully"
release:
name: "Step 9: Create GitHub Release"
runs-on: ubuntu-latest
needs: [version-check, package, tag, release-notes]
permissions:
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Verify Tag Exists"
run: |
TAG="v${{ needs.version-check.outputs.version }}"
echo "🔍 Verifying tag $TAG exists..."
git fetch --tags
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null 2>&1; then
echo "✅ Tag $TAG exists"
else
echo "❌ Tag $TAG does not exist, creating it..."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG: Auto-generated from main branch merge"
git push origin "$TAG"
echo "✅ Tag $TAG created"
fi
- name: "Create GitHub Release"
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.version-check.outputs.version }}
files: |
release/phantom-${{ needs.version-check.outputs.version }}.zip
body: ${{ needs.release-notes.outputs.notes }}
draft: false
prerelease: true
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
summary:
name: "Step 10: Pipeline Summary"
runs-on: ubuntu-latest
needs: [version-check, release]
if: always()
steps:
- name: "Pipeline Summary"
run: |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Step 10/10: Pipeline Complete"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "🎉 Release v${{ needs.version-check.outputs.version }} created successfully!"
echo ""
echo "📦 Release Package:"
echo " release/phantom-${{ needs.version-check.outputs.version }}.zip"
echo ""
echo "🏷️ Git Tag:"
echo " v${{ needs.version-check.outputs.version }}"
echo ""
echo "🌐 GitHub Release:"
echo " https://github.com/${{ github.repository }}/releases/tag/v${{ needs.version-check.outputs.version }}"
echo ""
echo "🏷️ Label: BETA (Pre-release)"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"