mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(android): android internal testing (#8577)
This commit is contained in:
80
tools/playstore-auto-bump/index.ts
Normal file
80
tools/playstore-auto-bump/index.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import {
|
||||
androidpublisher_v3,
|
||||
auth as google_auth,
|
||||
} from '@googleapis/androidpublisher';
|
||||
|
||||
export async function fetchVersionCode(applicationId: string): Promise<number> {
|
||||
const auth = new google_auth.GoogleAuth({
|
||||
scopes: ['https://www.googleapis.com/auth/androidpublisher'],
|
||||
});
|
||||
const androidPublisher = new androidpublisher_v3.Androidpublisher({
|
||||
auth,
|
||||
});
|
||||
const appEdit = await androidPublisher.edits.insert({
|
||||
packageName: applicationId,
|
||||
requestBody: {
|
||||
// 20min
|
||||
expiryTimeSeconds: (Math.floor(Date.now() / 1000) + 12000).toString(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!appEdit.data.id) {
|
||||
throw new Error('Failed to create edit');
|
||||
}
|
||||
|
||||
const lists = await androidPublisher.edits.bundles.list({
|
||||
packageName: applicationId,
|
||||
editId: appEdit.data.id,
|
||||
});
|
||||
|
||||
let versionCode: number = 1;
|
||||
try {
|
||||
versionCode =
|
||||
lists.data.bundles?.[lists.data.bundles.length - 1].versionCode || 1;
|
||||
} catch {}
|
||||
|
||||
console.info(`Remote version code: ${versionCode}`);
|
||||
|
||||
console.info(`Writing edit ID to ${process.env.GITHUB_OUTPUT}`);
|
||||
|
||||
if (process.env.GITHUB_OUTPUT) {
|
||||
execSync(
|
||||
`echo "EDIT_ID=${appEdit.data.id}" >> ${process.env.GITHUB_OUTPUT}`,
|
||||
{
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
const versionCodeRegexPattern = /(versionCode(?:\s|=)*)(.*)/;
|
||||
const gradlePath = join(
|
||||
fileURLToPath(import.meta.url),
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'packages/frontend/apps/android/App/app/build.gradle'
|
||||
);
|
||||
|
||||
let gradleVersionCode = 0;
|
||||
|
||||
const gradleFile = fs.readFileSync(gradlePath, 'utf8');
|
||||
const matched = gradleFile.match(versionCodeRegexPattern);
|
||||
|
||||
const remoteVersion = await fetchVersionCode('app.affine.pro');
|
||||
|
||||
gradleVersionCode = parseInt(matched?.[2] || '0');
|
||||
gradleVersionCode = isNaN(gradleVersionCode) ? 0 : gradleVersionCode;
|
||||
const versionCode = Math.max(gradleVersionCode, remoteVersion) + 1;
|
||||
|
||||
fs.writeFileSync(
|
||||
gradlePath,
|
||||
gradleFile.replace(versionCodeRegexPattern, `$1 ${versionCode}`)
|
||||
);
|
||||
19
tools/playstore-auto-bump/package.json
Normal file
19
tools/playstore-auto-bump/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@affine/playstore-auto-bump",
|
||||
"version": "0.17.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Automatically bump the versionCode and versionName of an Android app from the Google Play Store versions",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"bump": "node --import @oxc-node/core/register index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@googleapis/androidpublisher": "^22.0.0",
|
||||
"@oxc-node/core": "^0.0.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.12",
|
||||
"typescript": "^5.6.3"
|
||||
}
|
||||
}
|
||||
10
tools/playstore-auto-bump/tsconfig.json
Normal file
10
tools/playstore-auto-bump/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler"
|
||||
},
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user