Skip to content

Commit c4b8eb2

Browse files
committed
feat: Auto-increment version and create new release on every merge
- Auto-increment patch version if tag already exists - Update package.json and phantom.js with new version - Commit version update automatically - Always create new tag and release - All releases marked as BETA (pre-release) - Removed tag existence check - always creates new release
1 parent 3de4a33 commit c4b8eb2

1 file changed

Lines changed: 112 additions & 35 deletions

File tree

.github/workflows/main.yml

Lines changed: 112 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -104,48 +104,132 @@ jobs:
104104
runs-on: ubuntu-latest
105105
needs: coverage
106106
permissions:
107-
contents: read
107+
contents: write
108108
outputs:
109-
version: ${{ steps.version.outputs.version }}
110-
tag_exists: ${{ steps.check_tag.outputs.exists }}
109+
version: ${{ steps.final_version.outputs.version }}
111110
steps:
112111
- name: "Checkout code"
113112
uses: actions/checkout@v4
114113
with:
115114
fetch-depth: 0
115+
token: ${{ secrets.GITHUB_TOKEN }}
116+
117+
- name: "Setup Node.js"
118+
uses: actions/setup-node@v4
119+
with:
120+
node-version: '20.x'
121+
cache: 'npm'
122+
cache-dependency-path: 'scripts/package-lock.json'
116123

117-
- name: "Get Version"
118-
id: version
124+
- name: "Install dependencies"
125+
working-directory: ./scripts
126+
run: npm ci
127+
128+
- name: "Get Current Version"
129+
id: current_version
119130
run: |
120131
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
121132
echo "📦 Step 3/10: Detecting Version"
122133
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
123134
echo "🔍 Reading version from package.json..."
124135
VERSION=$(node -p "require('./scripts/package.json').version")
125136
echo "version=$VERSION" >> $GITHUB_OUTPUT
126-
echo "✅ Detected version: $VERSION"
137+
echo "✅ Current version: $VERSION"
127138
128-
- name: "Check if Tag Exists"
129-
id: check_tag
139+
- name: "Check if Tag Exists and Increment Version"
140+
id: version_increment
130141
run: |
131142
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
132-
echo "🏷️ Step 4/10: Checking Git Tag"
143+
echo "🏷️ Step 4/10: Checking Git Tag & Incrementing Version"
133144
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
134-
TAG="v${{ steps.version.outputs.version }}"
145+
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
146+
TAG="v${CURRENT_VERSION}"
147+
135148
echo "🔍 Checking if tag $TAG already exists..."
136149
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null 2>&1; then
137-
echo "exists=true" >> $GITHUB_OUTPUT
138-
echo "⚠️ Tag $TAG already exists, skipping release creation"
150+
echo "⚠️ Tag $TAG already exists, incrementing version..."
151+
152+
# Extract base version (remove -BETA, -ALPHA, etc.)
153+
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-.*//')
154+
SUFFIX=$(echo "$CURRENT_VERSION" | sed 's/.*-//' || echo "")
155+
156+
# Parse version parts
157+
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
158+
159+
# Increment patch version
160+
PATCH=$((PATCH + 1))
161+
162+
# If patch reaches 10, increment minor and reset patch
163+
if [ $PATCH -ge 10 ]; then
164+
PATCH=0
165+
MINOR=$((MINOR + 1))
166+
fi
167+
168+
# If minor reaches 10, increment major and reset minor
169+
if [ $MINOR -ge 10 ]; then
170+
MINOR=0
171+
MAJOR=$((MAJOR + 1))
172+
fi
173+
174+
# Reconstruct version with BETA suffix
175+
if [ -n "$SUFFIX" ]; then
176+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-${SUFFIX}"
177+
else
178+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-BETA"
179+
fi
180+
181+
echo "📈 Incrementing version: $CURRENT_VERSION -> $NEW_VERSION"
182+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
183+
echo "needs_increment=true" >> $GITHUB_OUTPUT
139184
else
140-
echo "exists=false" >> $GITHUB_OUTPUT
141-
echo "✅ Tag $TAG does not exist, proceeding with release"
185+
echo "✅ Tag $TAG does not exist, using current version"
186+
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
187+
echo "needs_increment=false" >> $GITHUB_OUTPUT
142188
fi
189+
190+
- name: "Update Version in Files"
191+
if: steps.version_increment.outputs.needs_increment == 'true'
192+
run: |
193+
NEW_VERSION="${{ steps.version_increment.outputs.new_version }}"
194+
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
195+
196+
echo "📝 Updating version in package.json..."
197+
cd scripts
198+
node -e "
199+
const fs = require('fs');
200+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
201+
pkg.version = '$NEW_VERSION';
202+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
203+
"
204+
205+
echo "📝 Updating version in phantom.js..."
206+
cd ..
207+
sed -i.bak "s/$CURRENT_VERSION/$NEW_VERSION/g" phantom.js
208+
rm -f phantom.js.bak
209+
210+
echo "✅ Version updated to $NEW_VERSION"
211+
212+
- name: "Commit Version Update"
213+
if: steps.version_increment.outputs.needs_increment == 'true'
214+
run: |
215+
git config user.name "github-actions[bot]"
216+
git config user.email "github-actions[bot]@users.noreply.github.com"
217+
git add scripts/package.json phantom.js
218+
git commit -m "chore: Auto-increment version to ${{ steps.version_increment.outputs.new_version }} [skip ci]" || exit 0
219+
git push origin main || exit 0
220+
echo "✅ Version update committed"
221+
222+
- name: "Set Final Version"
223+
id: final_version
224+
run: |
225+
FINAL_VERSION="${{ steps.version_increment.outputs.new_version }}"
226+
echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
227+
echo "✅ Final version: $FINAL_VERSION"
143228
144229
minify:
145230
name: "Step 5: Generate Minified"
146231
runs-on: ubuntu-latest
147232
needs: version-check
148-
if: needs.version-check.outputs.tag_exists == 'false'
149233
steps:
150234
- name: "Checkout code"
151235
uses: actions/checkout@v4
@@ -175,7 +259,6 @@ jobs:
175259
name: "Step 6: Create Package"
176260
runs-on: ubuntu-latest
177261
needs: [version-check, minify]
178-
if: needs.version-check.outputs.tag_exists == 'false'
179262
steps:
180263
- name: "Checkout code"
181264
uses: actions/checkout@v4
@@ -205,7 +288,6 @@ jobs:
205288
name: "Step 7: Create Git Tag"
206289
runs-on: ubuntu-latest
207290
needs: [version-check, package]
208-
if: needs.version-check.outputs.tag_exists == 'false'
209291
permissions:
210292
contents: write
211293
steps:
@@ -232,7 +314,6 @@ jobs:
232314
name: "Step 8: Generate Release Notes"
233315
runs-on: ubuntu-latest
234316
needs: [version-check, tag]
235-
if: needs.version-check.outputs.tag_exists == 'false'
236317
outputs:
237318
notes: ${{ steps.release_notes.outputs.notes }}
238319
steps:
@@ -275,7 +356,6 @@ jobs:
275356
name: "Step 9: Create GitHub Release"
276357
runs-on: ubuntu-latest
277358
needs: [version-check, package, release-notes]
278-
if: needs.version-check.outputs.tag_exists == 'false'
279359
permissions:
280360
contents: write
281361
steps:
@@ -289,7 +369,7 @@ jobs:
289369
release/phantom-${{ needs.version-check.outputs.version }}.zip
290370
body: ${{ needs.release-notes.outputs.notes }}
291371
draft: false
292-
prerelease: ${{ contains(needs.version-check.outputs.version, 'BETA') || contains(needs.version-check.outputs.version, 'ALPHA') || contains(needs.version-check.outputs.version, 'RC') }}
372+
prerelease: true
293373
generate_release_notes: true
294374
env:
295375
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -307,21 +387,18 @@ jobs:
307387
echo "✅ Step 10/10: Pipeline Complete"
308388
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
309389
echo ""
310-
if [ "${{ needs.version-check.outputs.tag_exists }}" == "false" ]; then
311-
echo "🎉 Release v${{ needs.version-check.outputs.version }} created successfully!"
312-
echo ""
313-
echo "📦 Release Package:"
314-
echo " release/phantom-${{ needs.version-check.outputs.version }}.zip"
315-
echo ""
316-
echo "🏷️ Git Tag:"
317-
echo " v${{ needs.version-check.outputs.version }}"
318-
echo ""
319-
echo "🌐 GitHub Release:"
320-
echo " https://github.com/${{ github.repository }}/releases/tag/v${{ needs.version-check.outputs.version }}"
321-
else
322-
echo "ℹ️ Tag v${{ needs.version-check.outputs.version }} already exists"
323-
echo " Skipping release creation"
324-
fi
390+
echo "🎉 Release v${{ needs.version-check.outputs.version }} created successfully!"
391+
echo ""
392+
echo "📦 Release Package:"
393+
echo " release/phantom-${{ needs.version-check.outputs.version }}.zip"
394+
echo ""
395+
echo "🏷️ Git Tag:"
396+
echo " v${{ needs.version-check.outputs.version }}"
397+
echo ""
398+
echo "🌐 GitHub Release:"
399+
echo " https://github.com/${{ github.repository }}/releases/tag/v${{ needs.version-check.outputs.version }}"
400+
echo ""
401+
echo "🏷️ Label: BETA (Pre-release)"
325402
echo ""
326403
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
327404

0 commit comments

Comments
 (0)