From cbbc62ea4b3c29da21478727d1aeb35812e6f055 Mon Sep 17 00:00:00 2001 From: LemonNeko Date: Tue, 31 Mar 2026 18:29:22 +0800 Subject: [PATCH] feat(stage-pocket-android): bump version with bumpp --- .../android/app-version.properties | 2 + .../stage-pocket/android/app/build.gradle.kts | 14 ++- bump.config.ts | 85 +++++++++++++------ 3 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 apps/stage-pocket/android/app-version.properties diff --git a/apps/stage-pocket/android/app-version.properties b/apps/stage-pocket/android/app-version.properties new file mode 100644 index 000000000..dcc4a1429 --- /dev/null +++ b/apps/stage-pocket/android/app-version.properties @@ -0,0 +1,2 @@ +AIRI_VERSION_NAME=0.9.0-beta.3 +AIRI_VERSION_CODE=2 diff --git a/apps/stage-pocket/android/app/build.gradle.kts b/apps/stage-pocket/android/app/build.gradle.kts index f55159d0c..8b46818ed 100644 --- a/apps/stage-pocket/android/app/build.gradle.kts +++ b/apps/stage-pocket/android/app/build.gradle.kts @@ -1,5 +1,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import java.util.Properties + val minSdkVersion: Int by rootProject.extra val compileSdkVersion: Int by rootProject.extra val targetSdkVersion: Int by rootProject.extra @@ -13,6 +15,14 @@ val androidxEspressoCoreVersion: String by rootProject.extra val androidMinSdk = minSdkVersion val androidCompileSdk = compileSdkVersion val androidTargetSdk = targetSdkVersion +val appVersionProperties = Properties().apply { + rootProject.file("app-version.properties").inputStream().use(::load) +} +val androidVersionName = appVersionProperties.getProperty("AIRI_VERSION_NAME") + ?: error("AIRI_VERSION_NAME is missing in android/app-version.properties") +val androidVersionCode = appVersionProperties.getProperty("AIRI_VERSION_CODE") + ?.toIntOrNull() + ?: error("AIRI_VERSION_CODE is missing or invalid in android/app-version.properties") plugins { id("com.android.application") @@ -27,8 +37,8 @@ android { applicationId = "ai.moeru.airi_pocket" minSdk = androidMinSdk targetSdk = androidTargetSdk - versionCode = 1 - versionName = "1.0" + versionCode = androidVersionCode + versionName = androidVersionName testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/bump.config.ts b/bump.config.ts index 5864ef20f..823fff202 100644 --- a/bump.config.ts +++ b/bump.config.ts @@ -6,41 +6,72 @@ import { defineConfig } from 'bumpp' import { parse, stringify } from 'smol-toml' import { x } from 'tinyexec' +const androidVersionFile = join(cwd(), 'apps/stage-pocket/android/app-version.properties') + +const androidVersionCodePattern = /^AIRI_VERSION_CODE=(\d+)$/m + +async function syncCargoToml() { + const cargoTomlFile = await readFile(join(cwd(), 'Cargo.toml')) + const cargoToml = parse(cargoTomlFile.toString('utf-8')) as { + workspace?: { + package?: { + version?: string + } + } + } + + if (typeof cargoToml !== 'object' || cargoToml === null) { + throw new TypeError('Cargo.toml does not contain a valid object') + } + if (typeof cargoToml.workspace?.package?.version !== 'string') { + throw new TypeError('Cargo.toml does not contain a valid version in workspace.package.version') + } + + const packageJSONFile = join(cwd(), 'package.json') + const packageJSON = JSON.parse(await readFile(packageJSONFile, 'utf-8')) + if (typeof packageJSON?.version !== 'string' || packageJSON?.version === null) { + throw new TypeError('package.json does not contain a valid version') + } + + cargoToml.workspace.package.version = packageJSON.version + console.info(`Bumping Cargo.toml version to ${cargoToml.workspace.package.version} (from package.json, ${packageJSON.version})`) + + await writeFile(join(cwd(), 'Cargo.toml'), stringify(cargoToml)) +} + +async function syncAndroidVersion(version: string) { + const androidVersionContent = await readFile(androidVersionFile, 'utf-8') + const currentVersionCodeMatch = androidVersionContent.match(androidVersionCodePattern) + + if (!currentVersionCodeMatch) { + throw new TypeError('Android version file does not contain a valid AIRI_VERSION_CODE') + } + + const currentVersionCode = Number.parseInt(currentVersionCodeMatch[1], 10) + + if (!Number.isSafeInteger(currentVersionCode) || currentVersionCode < 1) { + throw new TypeError(`Android AIRI_VERSION_CODE is invalid: ${currentVersionCodeMatch[1]}`) + } + + const nextVersionCode = currentVersionCode + 1 + const nextAndroidVersionContent = `AIRI_VERSION_NAME=${version}\nAIRI_VERSION_CODE=${nextVersionCode}\n` + + await writeFile(androidVersionFile, nextAndroidVersionContent) + console.info(`Bumping Android version to ${version} (${currentVersionCode} -> ${nextVersionCode})`) +} + export default defineConfig({ recursive: true, commit: 'release: v%s', sign: false, push: false, all: true, - execute: async () => { + execute: async (operation) => { await x('pnpm', ['publish', '-r', '--access', 'public', '--no-git-checks', '--dry-run']) + const nextVersion = operation.state.newVersion - const cargoTomlFile = await readFile(join(cwd(), 'Cargo.toml')) - const cargoToml = parse(cargoTomlFile.toString('utf-8')) as { - workspace?: { - package?: { - version?: string - } - } - } - - if (typeof cargoToml !== 'object' || cargoToml === null) { - throw new TypeError('Cargo.toml does not contain a valid object') - } - if (typeof cargoToml.workspace?.package?.version !== 'string') { - throw new TypeError('Cargo.toml does not contain a valid version in workspace.package.version') - } - - const packageJSONFile = join(cwd(), 'package.json') - const packageJSON = JSON.parse(await readFile(packageJSONFile, 'utf-8')) - if (typeof packageJSON?.version !== 'string' || packageJSON?.version === null) { - throw new TypeError('package.json does not contain a valid version') - } - - cargoToml.workspace.package.version = packageJSON.version - console.info(`Bumping Cargo.toml version to ${cargoToml.workspace.package.version} (from package.json, ${packageJSON.version})`) - - await writeFile(join(cwd(), 'Cargo.toml'), stringify(cargoToml)) + await syncCargoToml() + await syncAndroidVersion(nextVersion) await x('cargo', ['generate-lockfile']) }, })