Skip to content

Commit 869fd12

Browse files
committed
build: add script to auto bump android version
1 parent c9f1ac3 commit 869fd12

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Bug Fixes
2+
3+
- **sync:** rev check code #3661 #3660
4+
### Features
5+
6+
- **android:** improve error handling in request interceptor 3657
7+
- **android:** prepare auto builds
8+
- changes the separators when the user is typing

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"install:android:prod": "adb install -r android/app/build/outputs/apk/fdroid/release/app-fdroid-release.apk && echo 'Production APK installed successfully.'",
8080
"release": "npm run release.changelog && npm run dist",
8181
"release.changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
82-
"version": "npm run prebuild && npm run release.changelog && git add -A",
82+
"version": "npm run prebuild && npm run release.changelog && node ./tools/bump-android-version.js && git add -A",
8383
"buildSchema": "cd tools/schematics && npm run build && cd ../../ && npm i file:./tools/schematics --legacy-peer-deps",
8484
"int": "node ./tools/extract-i18n-single.js",
8585
"int:watch": "node ./tools/extract-i18n-watch.js",

tools/bump-android-version.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Read the version from package.json
5+
const packageJson = require('../package.json');
6+
const version = packageJson.version;
7+
8+
// Define the path to build.gradle
9+
const gradleFilePath = path.join(__dirname, '..', 'android', 'app', 'build.gradle');
10+
11+
// Read the build.gradle file
12+
let gradleFileContent = fs.readFileSync(gradleFilePath, 'utf8');
13+
14+
// Update the versionCode and versionName
15+
const versionCodeDroid = version
16+
.split('.')
17+
.map((num) => num.padStart(2, '0'))
18+
.join('');
19+
20+
gradleFileContent = gradleFileContent.replace(
21+
/versionCode \d+/g,
22+
`versionCode ${versionCodeDroid}`,
23+
);
24+
gradleFileContent = gradleFileContent.replace(
25+
/versionName "[^"]+"/g,
26+
`versionName "${version}"`,
27+
);
28+
29+
// Write the updated content back to build.gradle
30+
fs.writeFileSync(gradleFilePath, gradleFileContent, 'utf8');
31+
32+
console.log(`Updated build.gradle to version ${version}`);
33+
34+
// CREATE fastlane changelog file
35+
// Define the paths
36+
const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md');
37+
const outputDir = path.join(
38+
__dirname,
39+
'..',
40+
'fastlane',
41+
'metadata',
42+
'android',
43+
'en-US',
44+
'changelogs',
45+
);
46+
const outputFilePath = path.join(outputDir, `${versionCodeDroid}.txt`);
47+
48+
// Read the changelog.md file
49+
const changelogContent = fs.readFileSync(changelogPath, 'utf8');
50+
51+
// Extract the latest changes
52+
const lines = changelogContent.split('\n').slice(2); // Remove the first two lines;
53+
let latestChanges = '';
54+
let headerCount = 0;
55+
56+
for (const line of lines) {
57+
if (line.startsWith('# [') || line.startsWith('## [')) {
58+
headerCount++;
59+
if (headerCount === 1) break;
60+
}
61+
latestChanges += line + '\n';
62+
}
63+
// Remove all links from the extracted text
64+
latestChanges = latestChanges
65+
.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1')
66+
.replace(/\s*\([a-f0-9]{7}\)\s*$/gm, '');
67+
68+
// Ensure the output directory exists
69+
if (!fs.existsSync(outputDir)) {
70+
fs.mkdirSync(outputDir, { recursive: true });
71+
}
72+
73+
// Write the latest changes to the versioned changelog file
74+
fs.writeFileSync(outputFilePath, latestChanges, 'utf8');
75+
76+
console.log(`Wrote latest changes to ${outputFilePath}`);
77+
// console.log(latestChanges);

0 commit comments

Comments
 (0)