-
Notifications
You must be signed in to change notification settings - Fork 0
feat(android): add auto_increment_version_code option for Android builds #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: qodo_action_req_1_base_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1
Are you sure you want to change the base?
Changes from all commits
e843f00
a440abf
a170b5d
1094c16
601b3f9
9e67cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "tauri-cli": minor:feat | ||
| "@tauri-apps/cli": minor:feat | ||
| "tauri-build": minor:feat | ||
| "tauri-utils": minor:feat | ||
| --- | ||
|
|
||
| Add `tauri.conf.json > bundle > android > autoIncrementVersionCode` config option to automatically increment the Android version code. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ use crate::{ | |
| flock, | ||
| }, | ||
| interface::{AppInterface, Interface, Options as InterfaceOptions}, | ||
| mobile::{write_options, CliOptions, TargetDevice}, | ||
| mobile::{android::generate_tauri_properties, write_options, CliOptions, TargetDevice}, | ||
| ConfigValue, Error, Result, | ||
| }; | ||
| use clap::{ArgAction, Parser}; | ||
|
|
@@ -178,6 +178,12 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<BuiltApplica | |
| let mut env = env(options.ci)?; | ||
| configure_cargo(&mut env, &config)?; | ||
|
|
||
| generate_tauri_properties( | ||
| &config, | ||
| tauri_config.lock().unwrap().as_ref().unwrap(), | ||
| false, | ||
| )?; | ||
|
Comment on lines
+181
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. tauri_config double unwrap() • New code calls tauri_config.lock().unwrap().as_ref().unwrap(), which can panic at runtime if the mutex is poisoned or the inner value is None. • This violates the requirement to avoid panics/unwrap() for fallible operations and instead propagate errors via Result. • A panic here would crash the CLI during Android build/dev flows rather than providing actionable error context. Agent prompt
|
||
|
|
||
| crate::build::setup(&interface, &mut build_options, tauri_config.clone(), true)?; | ||
|
|
||
| let installed_targets = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ use cargo_mobile2::{ | |
| util::prompt, | ||
| }; | ||
| use clap::{Parser, Subcommand}; | ||
| use semver::Version; | ||
| use std::{ | ||
| env::set_var, | ||
| fs::{create_dir, create_dir_all, read_dir, write}, | ||
|
|
@@ -620,3 +621,66 @@ fn configure_cargo(env: &mut Env, config: &AndroidConfig) -> Result<()> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn generate_tauri_properties( | ||
| config: &AndroidConfig, | ||
| tauri_config: &TauriConfig, | ||
| dev: bool, | ||
| ) -> Result<()> { | ||
|
Comment on lines
+625
to
+629
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. generate_tauri_properties undocumented • A new public API pub fn generate_tauri_properties(...) was introduced without any /// documentation comments. • This violates the requirement that public functions/methods include documentation explaining purpose, parameters, and behavior. • Lack of docs makes the new behavior (including auto-increment semantics) harder to use correctly. Agent prompt
|
||
| let app_tauri_properties_path = config.project_dir().join("app").join("tauri.properties"); | ||
|
|
||
| let mut app_tauri_properties = Vec::new(); | ||
| if let Some(version) = tauri_config.version.as_ref() { | ||
| app_tauri_properties.push(format!("tauri.android.versionName={version}")); | ||
| if tauri_config.bundle.android.auto_increment_version_code { | ||
| let last_version_code = std::fs::read_to_string(&app_tauri_properties_path) | ||
| .ok() | ||
| .and_then(|content| { | ||
| content | ||
| .lines() | ||
| .find(|line| line.starts_with("tauri.android.versionCode=")) | ||
| .and_then(|line| line.split('=').nth(1)) | ||
| .and_then(|s| s.trim().parse::<u32>().ok()) | ||
| }); | ||
| let new_version_code = last_version_code.map(|v| v.saturating_add(1)).unwrap_or(1); | ||
| app_tauri_properties.push(format!("tauri.android.versionCode={new_version_code}")); | ||
|
Comment on lines
+635
to
+646
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Auto-increment exceeds max • autoIncrementVersionCode increments the previous versionCode read from tauri.properties but never validates/clamps to the documented maximum (2,100,000,000). • Once a repo reaches versionCode=2100000000, the next build will write 2100000001 (still a valid u32) which violates the schema/Play Store constraint and can cause Gradle/Play publishing failures. Agent prompt
|
||
| } else if let Some(version_code) = tauri_config.bundle.android.version_code.as_ref() { | ||
| app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); | ||
| } else if let Ok(version) = Version::parse(version) { | ||
| let mut version_code = version.major * 1000000 + version.minor * 1000 + version.patch; | ||
|
|
||
| if version_code == 0 { | ||
| crate::error::bail!( | ||
| "You must change the `version` in `tauri.conf.json`. The default value `0.0.0` is not allowed for Android package and must be at least `0.0.1`." | ||
| ); | ||
| } else if version_code > 2100000000 { | ||
| crate::error::bail!( | ||
| "Invalid version code {}. Version code must be between 1 and 2100000000. You must change the `version` in `tauri.conf.json`.", | ||
| version_code | ||
| ); | ||
| } | ||
|
|
||
| if dev { | ||
| version_code = version_code.clamp(1, 2100000000); | ||
| } | ||
|
|
||
| app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); | ||
| } | ||
| } | ||
|
|
||
| if !app_tauri_properties.is_empty() { | ||
| let app_tauri_properties_content = format!( | ||
| "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}", | ||
| app_tauri_properties.join("\n") | ||
| ); | ||
| if std::fs::read_to_string(&app_tauri_properties_path) | ||
| .map(|o| app_tauri_properties_content != o) | ||
| .unwrap_or(true) | ||
| { | ||
| write(&app_tauri_properties_path, app_tauri_properties_content) | ||
| .context("failed to write tauri.properties")?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4. Tauri.properties generation regression
🐞 Bug⛯ ReliabilityAgent prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools