Skip to content

Commit 1c70078

Browse files
committed
refactor: Combine all workflows into single main CI/CD pipeline
- Merge 4 separate workflows into one unified pipeline - Step-wise execution: 1. Tests run automatically 2. Coverage check for new functions 3. Version detection from package.json 4. Tag creation (if doesn't exist) 5. Minified file generation 6. Release package creation 7. Git tag push 8. GitHub Release creation - Fully automated - triggers on push to main - Removed separate workflows: ci.yml, test-coverage-check.yml, auto-release.yml, release.yml
1 parent 3669438 commit 1c70078

5 files changed

Lines changed: 140 additions & 263 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Main CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'phantom.js'
9+
- 'phantom.test.js'
10+
- 'scripts/package.json'
11+
12+
jobs:
13+
ci-cd:
14+
name: CI/CD Pipeline
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '20.x'
31+
cache: 'npm'
32+
cache-dependency-path: 'scripts/package-lock.json'
33+
34+
- name: Install dependencies
35+
working-directory: ./scripts
36+
run: npm ci
37+
38+
# Step 1: Run tests
39+
- name: Run Tests
40+
working-directory: ./scripts
41+
run: npm test
42+
43+
# Step 2: Check test coverage for new functions
44+
- name: Check Test Coverage
45+
working-directory: ./scripts
46+
run: |
47+
echo "🔍 Checking if new functions have test coverage..."
48+
git fetch origin main:main || true
49+
BASE_SHA=$(git merge-base HEAD~1 HEAD 2>/dev/null || echo "HEAD~1")
50+
echo "Comparing against: $BASE_SHA"
51+
npm run test:check-diff || npm run test:check
52+
53+
# Step 3: Get version from package.json
54+
- name: Get Version
55+
id: version
56+
run: |
57+
VERSION=$(node -p "require('./scripts/package.json').version")
58+
echo "version=$VERSION" >> $GITHUB_OUTPUT
59+
echo "📦 Detected version: $VERSION"
60+
61+
# Step 4: Check if tag already exists
62+
- name: Check if Tag Exists
63+
id: check_tag
64+
run: |
65+
TAG="v${{ steps.version.outputs.version }}"
66+
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null 2>&1; then
67+
echo "exists=true" >> $GITHUB_OUTPUT
68+
echo "⚠️ Tag $TAG already exists, skipping tag creation"
69+
else
70+
echo "exists=false" >> $GITHUB_OUTPUT
71+
echo "✅ Tag $TAG does not exist, will create it"
72+
fi
73+
74+
# Step 5: Generate minified file
75+
- name: Generate Minified File
76+
if: steps.check_tag.outputs.exists == 'false'
77+
working-directory: ./scripts
78+
run: npm run minify
79+
80+
# Step 6: Create release package
81+
- name: Create Release Package
82+
if: steps.check_tag.outputs.exists == 'false'
83+
working-directory: ./scripts
84+
run: npm run release
85+
86+
# Step 7: Create Git tag
87+
- name: Create Git Tag
88+
if: steps.check_tag.outputs.exists == 'false'
89+
run: |
90+
TAG="v${{ steps.version.outputs.version }}"
91+
git config user.name "github-actions[bot]"
92+
git config user.email "github-actions[bot]@users.noreply.github.com"
93+
git tag -a "$TAG" -m "Release $TAG: Auto-generated from main branch merge"
94+
git push origin "$TAG"
95+
echo "✅ Created and pushed tag: $TAG"
96+
97+
# Step 8: Get release notes
98+
- name: Get Release Notes
99+
if: steps.check_tag.outputs.exists == 'false'
100+
id: release_notes
101+
run: |
102+
VERSION="${{ steps.version.outputs.version }}"
103+
if [ -f "docs/RELEASE_NOTES_v${VERSION}.md" ]; then
104+
cat "docs/RELEASE_NOTES_v${VERSION}.md" > /tmp/release_notes.txt
105+
else
106+
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
107+
fi
108+
{
109+
echo "notes<<EOF"
110+
cat /tmp/release_notes.txt
111+
echo "EOF"
112+
} >> $GITHUB_OUTPUT
113+
114+
# Step 9: Create GitHub Release
115+
- name: Create GitHub Release
116+
if: steps.check_tag.outputs.exists == 'false'
117+
uses: softprops/action-gh-release@v1
118+
with:
119+
files: |
120+
release/phantom-${{ steps.version.outputs.version }}.zip
121+
body: ${{ steps.release_notes.outputs.notes }}
122+
draft: false
123+
prerelease: ${{ contains(steps.version.outputs.version, 'BETA') || contains(steps.version.outputs.version, 'ALPHA') || contains(steps.version.outputs.version, 'RC') }}
124+
generate_release_notes: true
125+
env:
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
128+
# Step 10: Summary
129+
- name: Pipeline Summary
130+
run: |
131+
if [ "${{ steps.check_tag.outputs.exists }}" == "true" ]; then
132+
echo "ℹ️ Tag v${{ steps.version.outputs.version }} already exists"
133+
echo " Skipping release creation"
134+
else
135+
echo "✅ Release created successfully!"
136+
echo "📦 Version: v${{ steps.version.outputs.version }}"
137+
echo "📁 Package: release/phantom-${{ steps.version.outputs.version }}.zip"
138+
echo "🔗 View release: https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }}"
139+
fi
140+

.github/workflows/release.yml

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)