@@ -21,39 +21,102 @@ permissions:
2121 contents : read
2222
2323jobs :
24- # ─── Job 1: Run all unit tests ──────────────────────────────── ────────────────
24+ # ─── Job 1: Run all unit tests (+ bump version on push events) ────────────────
2525 test :
2626 name : Unit Tests
2727 runs-on : ubuntu-22.04
28+ # Version bump needs write access on push events; PRs only need read
29+ permissions :
30+ contents : write
31+
32+ outputs :
33+ new-version : ${{ steps.bump.outputs.new-version }}
2834
2935 steps :
3036 - name : Checkout
3137 uses : actions/checkout@v6
38+ with :
39+ # Use GITHUB_TOKEN so the bot can push the version bump commit back
40+ token : ${{ secrets.GITHUB_TOKEN }}
3241
3342 - name : Setup Node.js
3443 uses : actions/setup-node@v6
3544 with :
3645 node-version : ' 24'
3746 cache : ' npm'
3847
48+ # ── Version bump (push events only, not PRs, not main/uat) ────────────────
49+ # Format: MAJOR.ALPHA.BETA.BUILD
50+ # develop → increment BUILD (4th digit)
51+ # alpha → increment ALPHA (2nd digit), reset BUILD to 0
52+ # beta → increment BETA (3rd digit), reset BUILD to 0
53+ - name : Bump version
54+ id : bump
55+ if : github.event_name == 'push' && github.ref_name != 'main' && github.ref_name != 'uat'
56+ run : |
57+ VERSION=$(node -p "require('./package.json').version")
58+ IFS='.' read -r MAJOR ALPHA BETA BUILD <<< "$VERSION"
59+
60+ case "${{ github.ref_name }}" in
61+ develop)
62+ BUILD=$((BUILD + 1))
63+ ;;
64+ alpha)
65+ ALPHA=$((ALPHA + 1))
66+ BUILD=0
67+ ;;
68+ beta)
69+ BETA=$((BETA + 1))
70+ BUILD=0
71+ ;;
72+ esac
73+
74+ NEW_VERSION="${MAJOR}.${ALPHA}.${BETA}.${BUILD}"
75+ node -e "
76+ const fs = require('fs');
77+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
78+ pkg.version = '${NEW_VERSION}';
79+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
80+ "
81+ echo "new-version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
82+ echo "Bumped to: ${NEW_VERSION}"
83+
3984 - name : Install dependencies
4085 run : npm ci
4186
4287 - name : Run unit tests
4388 run : npm run test:run
4489
90+ # Push the version bump commit AFTER tests pass so a failed test doesn't
91+ # advance the version counter.
92+ - name : Commit and push version bump
93+ if : github.event_name == 'push' && github.ref_name != 'main' && github.ref_name != 'uat' && steps.bump.outputs.new-version != ''
94+ run : |
95+ NEW_VERSION="${{ steps.bump.outputs.new-version }}"
96+ git config user.name "github-actions[bot]"
97+ git config user.email "github-actions[bot]@users.noreply.github.com"
98+ git add package.json
99+ # Only commit if package.json actually changed (idempotent guard)
100+ git diff --cached --quiet || git commit -m "chore: bump version to ${NEW_VERSION} [skip ci]"
101+ git push
102+
45103 # ─── Job 2: Build the .deb installer (only runs when all tests pass) ──────────
46104 build :
47105 name : Build Linux DEB
48106 runs-on : ubuntu-22.04
49107 needs : test
108+ # Only build on direct pushes (not PRs)
109+ if : github.event_name == 'push'
50110 permissions :
51111 contents : read # required for actions/checkout
52112 actions : write # required to list and delete artifacts
53113
54114 steps :
115+ # Checkout the branch tip (picks up the version bump commit from the test job)
55116 - name : Checkout
56117 uses : actions/checkout@v6
118+ with :
119+ ref : ${{ github.ref_name }}
57120
58121 - name : Setup Node.js
59122 uses : actions/setup-node@v6
@@ -115,3 +178,4 @@ jobs:
115178 console.log(`Deleted: ${artifact.name} id=${artifact.id} created=${artifact.created_at}`);
116179 }
117180 console.log(`Kept ${Math.min(artifacts.length, 5)}, deleted ${toDelete.length}.`);
181+
0 commit comments