Skip to content

Commit bdd6852

Browse files
authored
Merge pull request #20 from typelets/fix/unified-versioning
fix: implement unified versioning for main and mobile apps
2 parents da15f8b + 9cee425 commit bdd6852

File tree

3 files changed

+26
-124
lines changed

3 files changed

+26
-124
lines changed

.releaserc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[
1313
"@semantic-release/exec",
1414
{
15-
"prepareCmd": "node scripts/update-version.js ${nextRelease.version} && node scripts/update-mobile-version.js"
15+
"prepareCmd": "node scripts/update-version.js ${nextRelease.version} && node scripts/update-mobile-version.js ${nextRelease.version}"
1616
}
1717
],
1818
[

scripts/update-mobile-version.js

Lines changed: 24 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,62 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
4-
import { execSync } from 'child_process';
54

65
const __filename = fileURLToPath(import.meta.url);
76
const __dirname = path.dirname(__filename);
87

9-
// Get commits since last mobile version bump
10-
function getCommitsSinceLastMobileBump() {
11-
try {
12-
// Find the last commit that changed mobile package.json version
13-
// This is typically a "chore(mobile): bump mobile app version" commit
14-
const lastBumpCommit = execSync(
15-
'git log -1 --format=%H --grep="chore(mobile): bump mobile app version" -- apps/mobile/v1/package.json',
16-
{ encoding: 'utf8' }
17-
).trim();
8+
/**
9+
* Unified Versioning Script for Mobile App
10+
*
11+
* This script syncs the mobile app version to match the main app version.
12+
* Both main and mobile use the SAME version number for simplicity.
13+
*
14+
* Usage: Called by semantic-release with the new version as argument
15+
*/
1816

19-
if (lastBumpCommit) {
20-
// Get commits since that bump commit
21-
const commits = execSync(
22-
`git log ${lastBumpCommit}..HEAD --pretty=format:"%s"`,
23-
{ encoding: 'utf8' }
24-
);
25-
return commits.split('\n').filter(Boolean);
26-
}
17+
const version = process.argv[2];
2718

28-
// If no bump commit found, just get the last commit
29-
const lastCommit = execSync('git log -1 --pretty=format:"%s"', { encoding: 'utf8' });
30-
return lastCommit ? [lastCommit] : [];
31-
} catch (error) {
32-
// Fallback to last commit
33-
try {
34-
const lastCommit = execSync('git log -1 --pretty=format:"%s"', { encoding: 'utf8' });
35-
return lastCommit ? [lastCommit] : [];
36-
} catch {
37-
return [];
38-
}
39-
}
19+
if (!version) {
20+
console.error('Version not provided');
21+
process.exit(1);
4022
}
4123

42-
// Check if there are mobile commits
43-
function hasMobileCommits(commits) {
44-
return commits.some(commit => commit.includes('(mobile)'));
45-
}
46-
47-
// Determine version bump type for mobile based on the HIGHEST priority commit
48-
function getMobileVersionBump(commits) {
49-
const mobileCommits = commits.filter(commit => commit.includes('(mobile)'));
50-
51-
// Check for breaking changes (highest priority)
52-
if (mobileCommits.some(commit => commit.includes('BREAKING CHANGE') || commit.startsWith('feat(mobile)!'))) {
53-
return 'major';
54-
}
55-
56-
// Check for features (medium priority)
57-
if (mobileCommits.some(commit => commit.startsWith('feat(mobile)'))) {
58-
return 'minor';
59-
}
60-
61-
// Check for fixes (low priority)
62-
if (mobileCommits.some(commit => commit.startsWith('fix(mobile)'))) {
63-
return 'patch';
64-
}
65-
66-
// For chore, style, refactor, etc. - still bump patch
67-
if (mobileCommits.length > 0) {
68-
return 'patch';
69-
}
70-
71-
return null;
72-
}
73-
74-
// Bump version
75-
function bumpVersion(version, type) {
76-
const parts = version.split('.').map(Number);
77-
78-
switch (type) {
79-
case 'major':
80-
return `${parts[0] + 1}.0.0`;
81-
case 'minor':
82-
return `${parts[0]}.${parts[1] + 1}.0`;
83-
case 'patch':
84-
return `${parts[0]}.${parts[1]}.${parts[2] + 1}`;
85-
default:
86-
return version;
87-
}
88-
}
89-
90-
// Main execution
91-
const commits = getCommitsSinceLastMobileBump();
92-
93-
if (!hasMobileCommits(commits)) {
94-
console.log('No mobile commits found, skipping mobile version bump');
95-
process.exit(0);
96-
}
97-
98-
const bumpType = getMobileVersionBump(commits);
99-
if (!bumpType) {
100-
console.log('No mobile version bump needed');
101-
process.exit(0);
102-
}
24+
console.log(`\n📱 Syncing mobile app to version ${version}...`);
10325

10426
// Update mobile app package.json
10527
const mobilePackagePath = path.join(__dirname, '../apps/mobile/v1/package.json');
10628
const mobilePackage = JSON.parse(fs.readFileSync(mobilePackagePath, 'utf8'));
10729
const oldVersion = mobilePackage.version;
108-
const newVersion = bumpVersion(oldVersion, bumpType);
109-
mobilePackage.version = newVersion;
30+
mobilePackage.version = version;
11031
fs.writeFileSync(mobilePackagePath, JSON.stringify(mobilePackage, null, 2) + '\n');
111-
console.log(`Updated mobile package.json from ${oldVersion} to ${newVersion} (${bumpType})`);
32+
console.log(`Updated apps/mobile/v1/package.json: ${oldVersion} ${version}`);
11233

11334
// Update mobile app.json
11435
const mobileAppJsonPath = path.join(__dirname, '../apps/mobile/v1/app.json');
11536
const mobileAppJson = JSON.parse(fs.readFileSync(mobileAppJsonPath, 'utf8'));
116-
mobileAppJson.expo.version = newVersion;
37+
mobileAppJson.expo.version = version;
11738

118-
// Also bump build numbers for iOS and Android
39+
// Bump build numbers for iOS and Android
11940
if (mobileAppJson.expo.ios) {
12041
const currentBuildNumber = parseInt(mobileAppJson.expo.ios.buildNumber || '1', 10);
12142
mobileAppJson.expo.ios.buildNumber = String(currentBuildNumber + 1);
122-
console.log(`Updated iOS buildNumber to ${mobileAppJson.expo.ios.buildNumber}`);
43+
console.log(`✓ Bumped iOS buildNumber to ${mobileAppJson.expo.ios.buildNumber}`);
12344
}
12445

12546
if (mobileAppJson.expo.android) {
12647
const currentVersionCode = parseInt(mobileAppJson.expo.android.versionCode || 1, 10);
12748
mobileAppJson.expo.android.versionCode = currentVersionCode + 1;
128-
console.log(`Updated Android versionCode to ${mobileAppJson.expo.android.versionCode}`);
49+
console.log(`✓ Bumped Android versionCode to ${mobileAppJson.expo.android.versionCode}`);
12950
}
13051

13152
fs.writeFileSync(mobileAppJsonPath, JSON.stringify(mobileAppJson, null, 2) + '\n');
132-
console.log(`Updated mobile app.json to version ${newVersion}`);
53+
console.log(`Updated apps/mobile/v1/app.json`);
13354

13455
// Update mobile version.ts
13556
const mobileVersionPath = path.join(__dirname, '../apps/mobile/v1/src/constants/version.ts');
136-
const mobileVersionContent = `export const APP_VERSION = '${newVersion}';\n`;
57+
const mobileVersionContent = `export const APP_VERSION = '${version}';\n`;
13758
fs.writeFileSync(mobileVersionPath, mobileVersionContent);
138-
console.log(`Updated mobile version.ts to ${newVersion}`);
59+
console.log(`Updated apps/mobile/v1/src/constants/version.ts`);
13960

140-
console.log(`\n✅ Mobile app version bumped: ${oldVersion}${newVersion} (${bumpType})`);
61+
console.log(`\n✅ Mobile app synced to version ${version}`);
62+
console.log(` (Unified versioning: main and mobile always match)\n`);

scripts/update-version.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,7 @@ if (!version) {
1313
process.exit(1);
1414
}
1515

16-
// Check if this release is mobile-only
17-
function isMobileOnlyRelease() {
18-
try {
19-
const commits = execSync('git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%s"', { encoding: 'utf8' });
20-
const commitList = commits.split('\n').filter(Boolean);
21-
22-
// Check if all commits are mobile-scoped
23-
const hasMobile = commitList.some(commit => commit.includes('(mobile)'));
24-
const hasNonMobile = commitList.some(commit => !commit.includes('(mobile)') && !commit.includes('[skip ci]'));
25-
26-
return hasMobile && !hasNonMobile;
27-
} catch (error) {
28-
return false;
29-
}
30-
}
31-
32-
// Skip web version updates if this is a mobile-only release
33-
if (isMobileOnlyRelease()) {
34-
console.log('Mobile-only release detected, skipping web version updates');
35-
process.exit(0);
36-
}
16+
console.log(`\n🔄 Updating main app version to ${version}...`);
3717

3818
// Update version constants file
3919
const versionFilePath = path.join(__dirname, '../src/constants/version.ts');

0 commit comments

Comments
 (0)