diff --git a/README.md b/README.md index 02c6870e9..641b88037 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,137 @@ # android-scripts -This is an utility repo that contain scripts for use in our private repo sdk, -in particular is used as submodule for repos: -* [android-telepass-pay-framework](https://github.com/urbi-mobility/android-telepass-pay-framework) -* [android-urbi-unica-framework](https://github.com/wise-emotions/android-urbi-unica-framework) +Utility submodule used by `android-urbi-framework` (and other Urbi repos). +Contains Gradle scripts for version management, changelog automation, and library publishing. + +--- + +## Contents + +| Path | Purpose | +|---|---| +| `scripts/build.gradle.kts` | Publishing tasks: version bump, changelog update, BoM publish, GitHub Release | +| `gradle/depend.gradle` | Module version definitions (`//---Module Version---//` block) | +| `gradle/libs-urbi.versions.toml` | Version catalog, including the `urbi-bom` version (date-based) | + +--- + +## Gradle Tasks + +### `update-version-lib-changelog` +**Main entry point for a full publish cycle.** + +Reads `[Unreleased]` sections from all module changelogs, aggregates them into `urbisample/changelog.md`, updates the BoM version in the TOML to today's date, then delegates to `upgrade-lib-version`. + +```bash +# Default (patch bump) +./gradlew update-version-lib-changelog + +# Minor or major bump +./gradlew update-version-lib-changelog -Dargs=minor +./gradlew update-version-lib-changelog -Dargs=major +``` + +--- + +### `upgrade-lib-version` +Reads module changelogs for pending `[Unreleased]` entries, bumps the affected library versions in `depend.gradle`, then: + +1. Writes a new entry to `bom/CHANGELOG.md` (see [BoM Changelog](#bom-changelog)) +2. Creates a GitHub Release on `android-urbi-framework` (see [GitHub Release](#github-release)) +3. Publishes the BoM to GitHub Packages (`bom:publishAllBom`) +4. Uploads all changed libraries (`uploadlib`) + +```bash +./gradlew upgrade-lib-version # patch bump, publishes GitHub Release +./gradlew upgrade-lib-version -Dargs=minor +./gradlew upgrade-lib-version -PskipRelease=true # skip GitHub Release creation +``` + +--- + +### `uploadlib` +Publishes all libraries with pending changes to GitHub Packages. +For each module: replaces the `[Unreleased]` section with the new versioned entry in its `changelog.md`, then publishes the artifact. + +```bash +./gradlew uploadlib +./gradlew uploadlib -Pargs=skipService # skip copyServicesProvider +``` + +--- + +### `release-bom` +**Standalone BoM release — no lib upload required.** + +For each module, looks up its current version in `depend.gradle` and reads the matching versioned section in its `changelog.md` (e.g. `## [UTL_6.26.6]`). Writes `bom/CHANGELOG.md`, publishes the BoM to GitHub Packages, and creates a GitHub Release. + +Use this when: +- You uploaded one or more libraries via `uploadlib` (or any other flow) and want to cut a new BoM release. +- You want to publish a new BoM snapshot from the current state of all library versions without running a full upload cycle. + +```bash +./gradlew release-bom # all modules with versioned entries +./gradlew release-bom -Pmodules=utilitylib,composeds # explicit subset +./gradlew release-bom -PskipRelease=true # skip GitHub Release creation +``` + +--- + +### `update-version-lib` +Lighter version of `upgrade-lib-version`: bumps versions and uploads libs, but does **not** update the BoM version, write the BoM changelog, or create a GitHub Release. + +--- + +## BoM Changelog + +`bom/CHANGELOG.md` (in `android-urbi-framework`) is auto-generated on every `upgrade-lib-version` run. + +**Format:** +```markdown +## [2026.05.28] 2026-05-28 + +### composeds — 3.4.1 +- #3027 | Fix orderId nella navigazione al dettaglio storico + +### utilitylib — 6.26.5 +- #3100 | Updated button style +``` + +Each entry lists only the modules that had `[Unreleased]` changes, with their new version and the individual changelog bullets. The BoM version matches the date in `libs-urbi.versions.toml` (`yyyy.MM.dd`). + +--- + +## GitHub Release + +A GitHub Release on `urbi-mobility/android-urbi-framework` is created automatically with tag `bom-` (e.g., `bom-2026.05.28`) and the same content written to `bom/CHANGELOG.md`. + +**Default behaviour:** Release is created on every `upgrade-lib-version` run. + +**To skip** (e.g., dry-run or CI test): +```bash +./gradlew upgrade-lib-version -PskipRelease=true +``` + +Requires the `gh` CLI to be authenticated in the environment (`gh auth login`). + +--- + +## Version Management + +Module versions live in `gradle/depend.gradle` between the `//---Module Version---//` and `//---End---//` markers: + +```groovy +//---Module Version---// + utilityVersion = '6.26.5' + modelVersion = '3.12.0' + // ... +//---End---// +``` + +The BoM version is separate, in `gradle/libs-urbi.versions.toml`: +```toml +[versions] +urbi-bom = "2026.05.28" +``` + +It is updated automatically by `update-version-lib-changelog` to today's date before each publish cycle. diff --git a/gradle/depend.gradle b/gradle/depend.gradle index ac287040d..f6db72d79 100644 --- a/gradle/depend.gradle +++ b/gradle/depend.gradle @@ -5,9 +5,7 @@ ext { ghp_registry_name_third = 'GitHubPackages-Third' urbiGroupId = 'co.urbi.android' urbiGroupThirdId = 'co.urbi.third' - telepassGroupId = 'com.telepass.urbi' urbi_ghp_registry_url = 'https://maven.pkg.github.com/urbi-mobility/android-urbi-framework' - telepass_ghp_registry_url = 'https://maven.pkg.github.com/wise-emotions/android-urbi-unica-framework' telepass_urbi_ghp_registry_url = 'https://maven.pkg.github.com/wise-emotions/android-urbi-framework' urbi_third_ghp_registry_url = 'https://maven.pkg.github.com/urbi-mobility/android-third-party-package-lib' suffixArtifactId='third' @@ -22,7 +20,6 @@ ext { taxiId = 'taxi' scanId = 'scan' transpoId = 'transpo' - atacId = 'atac' evchargingId = 'evcharging' tripoId = 'tripo' mobilitySharingId = 'mobilitysharing' @@ -36,45 +33,35 @@ ext { shopId = 'shop' loginId = 'login' - telepassModelId = 'telepassmodel' - telepassNetworkId = 'telepassnetwork' - telepassLibId = 'telepasslib' - //---Module Version---// - utilityVersion = '4.1.2' - designsystemVersion = '3.1.3hotfix2' - modelVersion = '4.1.5' - coreVersion = '4.1.5' - payVersion = '3.1.3' - ticketVersion = '1.0.3' - searchVersion = '2.0.8' - taxiVersion = '3.1.3' - scanVersion = '2.1.2' - transpoVersion = '3.1.2hotfix3' - evchargingVersion = '3.1.4' - tripoVersion = '3.1.4hotfix2' - mobilitySharingVersion = '4.1.3hotfix2' - commonStateVersion = '2.1.7hotfix2' - commonViewVersion = '2.1.5' - composeNavigationVersion = '1.0.6' - composeDsVersion = '2.1.3hotfix2' + utilityVersion = '4.1.4' + designsystemVersion = '3.1.7' + modelVersion = '4.1.10' + coreVersion = '4.1.10' + payVersion = '3.1.6' + ticketVersion = '1.0.5' + searchVersion = '2.0.10' + taxiVersion = '3.1.9' + scanVersion = '2.1.3' + transpoVersion = '3.1.6' + evchargingVersion = '3.1.6' + tripoVersion = '3.1.10' + mobilitySharingVersion = '4.1.7' + commonStateVersion = '2.1.12' + commonViewVersion = '2.1.13' + composeNavigationVersion = '1.0.8' + composeDsVersion = '2.1.8' historyVersion = '0.4.0' mapVersion = '0.4.0' profileVersion = '0.4.0' shopVersion = '0.4.0' - loginVersion = '2.1.2' + loginVersion = '2.1.12' - telepassModelVersion = '2.7.0' - telepassNetworkVersion = '2.10.0' - telepassLibCode = '7' - telepassLibVersion = '2.13.' + telepassLibCode //---End---// - atacVersion = '2.2.2' urbiBomId = 'bom' urbiBomThirdId = 'bomthird' // BOM versions unified from libs-urbi.versions.toml urbiBomVersion = libsUrbi.versions.urbi.bom.get() - urbiTelepassBomVersion = "$urbiBomVersion" urbiThirdBomVersion = "$urbiBomVersion" // Android android_version_array = ["utility", utilityVersion, "designsystem", designsystemVersion, "modelVersion", modelVersion, "coreVersion", coreVersion, "pay", payVersion, "ticket", ticketVersion, "search", searchVersion, "taxi", taxiVersion, @@ -85,10 +72,6 @@ ext { target_sdk_version = 35 ndk_version = '28.2.13676358' - - //ATAC - atac = "$urbiGroupId:$atacId:$atacVersion@aar" - // URBI designsystem = "$urbiGroupId:$designsystemId" diff --git a/gradle/libs-urbi.versions.toml b/gradle/libs-urbi.versions.toml index b8c0e7a51..0351113e0 100644 --- a/gradle/libs-urbi.versions.toml +++ b/gradle/libs-urbi.versions.toml @@ -1,7 +1,7 @@ [versions] accompanist_compose = "0.37.3" adapter-delegates4 = "4.3.2" -android-gradle-plugin = "8.11.2" +android-gradle-plugin = "8.13.2" android-material = "1.13.0" androidx-activity = "1.11.0" androidx-camera = "1.4.2" @@ -33,7 +33,7 @@ androidx-test-runner = "1.6.2" androidx-work-manager = "2.8.1" androidx-web-kit = "1.12.1" commons-codec = "1.15" -dagger = "2.57.2" +dagger = "2.58" dependencyGuard = "0.5.0" dokka = "1.9.20" facebook = "latest.release" @@ -64,11 +64,11 @@ json-test = "20250107" jmrtd = "0.7.18" junit = "4.13.2" jwt-decode = "2.0.2" -kotlin = "2.2.20" +kotlin = "2.3.21" kotlinx-coroutines = "1.10.2" kotlinter = "5.2.0" kustomer = "4.2.1" -ksp-plugin = "2.2.20-2.0.4" +ksp-plugin = "2.3.9" landscapist-glide = "1.5.2" lottie = "6.4.1" material-datetime-picker = "4.2.3" @@ -93,13 +93,15 @@ triplet-play = "3.10.1" turbine = "1.2.1" zxing = "3.4.1" rootbeer = "0.1.1" +androidx-credentials = "1.3.0" +google-identity-googleid = "1.1.1" androidx-datastore = "1.2.0" detekt = "1.23.8" timber = "5.0.1" tink = "1.20.0" urbi-kit = "1.0.0" sonatype-central-portal = "1.2.4" -urbi-bom = "2026.05.283" +urbi-bom = "2026.07.15" [libraries] adapterdelegates4-kotlin = { group = "com.hannesdorfmann", name = "adapterdelegates4-kotlin-dsl", version.ref = "adapter-delegates4" } @@ -228,6 +230,9 @@ subsampling-sample-image = { group = "com.davemorrissey.labs", name = "subsampli true-time = { group = "com.github.instacart", name = "truetime-android", version.ref = "true-time" } turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" } rootbeer = { group = "com.scottyab", name = "rootbeer-lib", version.ref = "rootbeer" } +androidx-credentials = { group = "androidx.credentials", name = "credentials", version.ref = "androidx-credentials" } +androidx-credentials-play-services-auth = { group = "androidx.credentials", name = "credentials-play-services-auth", version.ref = "androidx-credentials" } +google-identity-googleid = { group = "com.google.android.libraries.identity.googleid", name = "googleid", version.ref = "google-identity-googleid" } androidx-compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" } androidx-datastore = { group = "androidx.datastore", name = "datastore", version.ref = "androidx-datastore" } androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "androidx-datastore" } diff --git a/scripts/build.gradle.kts b/scripts/build.gradle.kts index fcdebe4aa..8bae5755c 100644 --- a/scripts/build.gradle.kts +++ b/scripts/build.gradle.kts @@ -132,9 +132,9 @@ fun getChangelogMap(): LinkedHashMap = linkedMapOf( "composenavigation" to "COMPOSENAVIGATION_", "composeds" to "COMPOSEDS_", "common-state" to "COMMON-STATE_", - "login" to "LOGIN_", "urbiscan" to "SCN_", "commonview" to "COMMONVIEW_", + "login" to "LOGIN_", "urbisearch" to "SRC_", "urbipay" to "PAY_", "ticketlib" to "TCK_", @@ -178,12 +178,12 @@ fun haveModuleThird(key: String): Boolean { "urbipay", "ticketlib", "tripo", - "login", "urbiscan", "commonview", "common-state", "composenavigation", "composeds", + "login", ) return list.contains(key) } @@ -200,11 +200,11 @@ fun haveModuleTPay(key: String): Boolean { "urbipay", "ticketlib", "tripo", - "login", "commonview", "common-state", "composenavigation", "composeds", + "login", "mobilitylib", "ticketlib", "urbitaxi", @@ -216,8 +216,135 @@ fun haveModuleTPay(key: String): Boolean { return list.contains(key) } +fun getBomVersionFromToml(): String { + val tomlFile = if (File("android-scripts/gradle/libs-urbi.versions.toml").exists()) + File("android-scripts/gradle/libs-urbi.versions.toml") + else + File("$rootDir/android-urbi-framework/android-scripts/gradle/libs-urbi.versions.toml") + return try { + tomlFile.readLines() + .firstOrNull { it.trimStart().startsWith("urbi-bom") } + ?.split("=")?.getOrNull(1) + ?.trim()?.removeSurrounding("\"") ?: "unknown" + } catch (e: Exception) { + println("Warning: cannot read BOM version from TOML: ${e.message}") + "unknown" + } +} + +/** + * Reads [Unreleased] entries from each changed module's changelog and writes a new entry + * to bom/CHANGELOG.md. Returns the generated entry text (used for GitHub Release notes). + */ +fun writeBomChangelog( + changedModules: Set, + moduleToVersionKey: Map, + currentVersions: Map, + dataNow: String, + bomVersion: String +): String { + val sb = StringBuilder() + sb.appendLine("## [$bomVersion] $dataNow") + sb.appendLine() + + changedModules.sorted().forEach { module -> + val versionKey = moduleToVersionKey[module] ?: return@forEach + val moduleVersion = currentVersions[versionKey] ?: "unknown" + val changelogFile = when { + File("$module/changelog.md").exists() -> File("$module/changelog.md") + File("$rootDir/android-urbi-framework/$module/changelog.md").exists() -> + File("$rootDir/android-urbi-framework/$module/changelog.md") + else -> null + } + + val entries = mutableListOf() + if (changelogFile != null) { + var inUnreleased = false + run breaking@{ + changelogFile.readLines().forEach { line -> + when { + line.startsWith("## [Unreleased]", ignoreCase = true) -> inUnreleased = true + inUnreleased && line.startsWith("##") -> return@breaking + inUnreleased && line.startsWith("-") -> entries.add(line) + } + } + } + } + + if (entries.isNotEmpty()) { + sb.appendLine("### $module — $moduleVersion") + entries.forEach { sb.appendLine(it) } + sb.appendLine() + } + } + + val newEntry = sb.toString().trimEnd() + val bomChangelogFile = if (File("bom").exists()) + File("bom/CHANGELOG.md") + else + File("$rootDir/android-urbi-framework/bom/CHANGELOG.md") + + val existing = if (bomChangelogFile.exists()) "\n\n${bomChangelogFile.readText()}" else "" + bomChangelogFile.writeText("$newEntry$existing") + println("BOM changelog updated: ${bomChangelogFile.path}") + return newEntry +} + +/** + * Finds the versioned changelog section matching [versionTag] (e.g. "UTL_6.26.6") + * and returns its bullet-point entries. + */ +fun readModuleChangesForVersion(module: String, versionTag: String): List { + val pathFile = "$module/changelog.md" + val changelogFile = when { + File(pathFile).exists() -> File(pathFile) + File("$rootDir/android-urbi-framework/$pathFile").exists() -> + File("$rootDir/android-urbi-framework/$pathFile") + else -> return emptyList() + } + val entries = mutableListOf() + var inSection = false + run breaking@{ + changelogFile.readLines().forEach { line -> + when { + !inSection && line.startsWith("## [") && line.contains(versionTag) -> inSection = true + inSection && line.startsWith("##") -> return@breaking + inSection && line.startsWith("-") -> entries.add(line) + } + } + } + return entries +} + +/** + * Creates a GitHub Release for the given BOM version using the gh CLI. + * Skip with -PskipRelease=true. + */ +fun createGithubRelease(bomVersion: String, releaseNotes: String) { + val tempFile = File.createTempFile("bom-release-notes", ".md") + try { + tempFile.writeText(releaseNotes) + ByteArrayOutputStream().use { os -> + exec { + commandLine( + "gh", "release", "create", "bom-$bomVersion", + "--repo", "urbi-mobility/android-urbi-framework", + "--title", "BoM $bomVersion", + "--notes-file", tempFile.absolutePath + ) + standardOutput = os + } + println(os.toString()) + } + println("GitHub Release created: bom-$bomVersion") + } catch (e: Exception) { + println("Warning: GitHub Release creation failed: ${e.message}") + } finally { + tempFile.delete() + } +} + fun createMapVersion(): HashMap { - val tpaylib = "telepassLibVersion" // Read Version on Gradle file val mapVersion: HashMap = hashMapOf() val gradle = if(File("android-scripts/gradle/depend.gradle").exists()) File("android-scripts/gradle/depend.gradle") else File("$rootDir/android-urbi-framework/android-scripts/gradle/depend.gradle") @@ -231,14 +358,7 @@ fun createMapVersion(): HashMap { line.replace("\\s".toRegex(), "").let { lineW -> lineW.split("=").let { if(it.size > 1) { - if (it[0].equals(tpaylib, true)) { - mapVersion[it[0]] = - it[1].replace("\'".toRegex(), "").replace("\\+".toRegex(), "") - .replace( - "telepassLibCode".toRegex(), mapVersion["telepassLibCode"] - ?: "" - ) - } else mapVersion[it[0]] = it[1].replace("\'".toRegex(), "") + mapVersion[it[0]] = it[1].replace("\'".toRegex(), "") } } } @@ -524,6 +644,15 @@ tasks.register("upgrade-lib-version") { out.println(it) } } + + val format = SimpleDateFormat("yyyy-MM-dd") + val dataNow = format.format(Date()) + val bomVersion = getBomVersionFromToml() + val currentVersions = createMapVersion() + val releaseNotes = writeBomChangelog(keyToChangeVersion, mapVersionUrbi, currentVersions, dataNow, bomVersion) + val skipRelease = project.properties["skipRelease"]?.toString()?.toBoolean() ?: false + if (!skipRelease) createGithubRelease(bomVersion, releaseNotes) + println("Upload BoM") ByteArrayOutputStream().use { os -> val result = exec { @@ -551,6 +680,88 @@ tasks.register("upgrade-lib-version") { } } +/** + * Standalone BoM release — no lib upload required. + * + * For each module, reads the changelog section that matches the module's current version + * in depend.gradle (e.g. ## [UTL_6.26.6]). Writes bom/CHANGELOG.md, publishes the BoM to + * GitHub Packages, and creates a GitHub Release. + * + * Usage: + * ./gradlew release-bom # all modules with versioned entries + * ./gradlew release-bom -Pmodules=utilitylib,composeds # explicit subset + * ./gradlew release-bom -PskipRelease=true # skip GitHub Release creation + */ +tasks.register("release-bom") { + doLast { + val format = SimpleDateFormat("yyyy-MM-dd") + val dataNow = format.format(Date()) + val bomVersion = getBomVersionFromToml() + val changelogPrefixes = getChangelogMap() // module -> tag prefix, e.g. "UTL_" + val versionKeys = getVersionKeyFromModule() // module -> version key, e.g. "utilityVersion" + val currentVersions = createMapVersion() // version key -> version string + + val modulesParam = project.properties["modules"]?.toString() + val candidateModules: Set = if (!modulesParam.isNullOrBlank()) { + modulesParam.split(",").map { it.trim() }.filter { it.isNotEmpty() }.toSet() + } else { + changelogPrefixes.keys.toSet() + } + + val sb = StringBuilder() + sb.appendLine("## [$bomVersion] $dataNow") + sb.appendLine() + + var hasEntries = false + candidateModules.sorted().forEach { module -> + val prefix = changelogPrefixes[module] ?: return@forEach + val versionKey = versionKeys[module] ?: return@forEach + val version = currentVersions[versionKey] ?: return@forEach + val versionTag = "$prefix$version" + val entries = readModuleChangesForVersion(module, versionTag) + if (entries.isNotEmpty()) { + hasEntries = true + sb.appendLine("### $module — $version") + entries.forEach { sb.appendLine(it) } + sb.appendLine() + } + } + + if (!hasEntries) { + println("No versioned changelog entries found for current library versions. Nothing to release.") + return@doLast + } + + val releaseNotes = sb.toString().trimEnd() + + val bomChangelogFile = if (File("bom").exists()) + File("bom/CHANGELOG.md") + else + File("$rootDir/android-urbi-framework/bom/CHANGELOG.md") + val existing = if (bomChangelogFile.exists()) "\n\n${bomChangelogFile.readText()}" else "" + bomChangelogFile.writeText("$releaseNotes$existing") + println("BoM changelog updated: ${bomChangelogFile.path}") + + val publishThirdParty = project.properties["publishThirdParty"]?.toString()?.toBoolean() ?: false + println("Publishing BoM to GitHub Packages...") + ByteArrayOutputStream().use { os -> + val result = exec { + if (publishThirdParty) { + commandLine("./gradlew", "bom:publishAllBom") + } else { + commandLine("./gradlew", "bom:publishAllBomNoThirdParty") + } + standardOutput = os + } + println(os.toString()) + println("Publish BoM: $result") + } + + val skipRelease = project.properties["skipRelease"]?.toString()?.toBoolean() ?: false + if (!skipRelease) createGithubRelease(bomVersion, releaseNotes) + } +} + /** * This scripts read depend.gradle file where libs version are and upgrade patch versionif there is some change in their changelog, and then upload new libs */ diff --git a/scripts/git/hook/pre-commit b/scripts/git/hook/pre-commit index 10ebc75e8..cb73ed09d 100755 --- a/scripts/git/hook/pre-commit +++ b/scripts/git/hook/pre-commit @@ -77,29 +77,28 @@ get_changelog_path() { # Function to get commit message get_commit_message() { - # Try to get commit message from command line arguments + # NOTE: never read .git/COMMIT_EDITMSG here: at pre-commit time it still contains + # the PREVIOUS commit's message (git writes the current one only after this hook), + # which used to leak stale messages like "Merge remote-tracking branch ..." into changelogs. local commit_msg="" - - # Method 1: Check if git commit is in progress and get message from .git/COMMIT_EDITMSG - if [ -f ".git/COMMIT_EDITMSG" ]; then - commit_msg=$(head -n 1 ".git/COMMIT_EDITMSG" 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - fi - - # Method 2: Check parent process command line for -m flag - if [ -z "$commit_msg" ]; then - local parent_cmd=$(ps -o args= $PPID 2>/dev/null || echo "") - if [[ "$parent_cmd" =~ -m[[:space:]]+\"([^\"]+)\" ]]; then - commit_msg="${BASH_REMATCH[1]}" - elif [[ "$parent_cmd" =~ -m[[:space:]]+([^[:space:]]+) ]]; then - commit_msg="${BASH_REMATCH[1]}" - fi + + # Parse the -m/--message flag from the parent `git commit` process command line. + # ps shows arguments unquoted, so capture everything after the flag. + local parent_cmd=$(ps -o args= $PPID 2>/dev/null || echo "") + if [[ "$parent_cmd" =~ --message=(.+)$ ]]; then + commit_msg="${BASH_REMATCH[1]}" + elif [[ "$parent_cmd" =~ [[:space:]]-[a-zA-Z]*m[[:space:]]+(.+)$ ]]; then + commit_msg="${BASH_REMATCH[1]}" fi - - # Fallback to generic message if we can't extract it + + # Strip surrounding whitespace and quotes + commit_msg=$(echo "$commit_msg" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/^"//;s/"$//') + + # Fallback to generic message if we can't extract it (e.g. editor-based commits) if [ -z "$commit_msg" ] || [ "$commit_msg" = "#" ]; then commit_msg="Updated module implementation" fi - + echo "$commit_msg" } @@ -191,32 +190,24 @@ EOF git add "$changelog_file" } -# Get list of changed files in this commit -# During pre-commit hook execution, git provides the file list via the index +# Get list of changed files in this commit (staged files only). +# NOTE: intentionally no fallback on `git status --porcelain` or `git ls-files --stage`: +# the latter lists the WHOLE index (not just staged changes) and used to add a changelog +# line to every module (e.g. on `git commit --amend` where the cached diff is empty). CHANGED_FILES="" -# Primary method: Get files from git diff --cached -CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true) +# Use `git rev-parse --git-dir` instead of a hardcoded .git path: in submodules +# .git is a gitdir pointer file, not a directory. +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null || echo ".git") -# Alternative method 1: Use git diff-index if cached fails -if [ -z "$CHANGED_FILES" ]; then - CHANGED_FILES=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD 2>/dev/null || true) -fi - -# Alternative method 2: Parse git status for staged files -if [ -z "$CHANGED_FILES" ]; then - CHANGED_FILES=$(git status --porcelain 2>/dev/null | grep "^[AMRC]" | sed 's/^...//' || true) -fi - -# Alternative method 3: Get from GIT_INDEX_FILE if available -if [ -z "$CHANGED_FILES" ] && [ -n "$GIT_INDEX_FILE" ]; then - CHANGED_FILES=$(git ls-files --stage | cut -f2 2>/dev/null || true) +if [ -f "$GIT_DIR/MERGE_HEAD" ] || [ -f "$GIT_DIR/CHERRY_PICK_HEAD" ] || [ -f "$GIT_DIR/REBASE_HEAD" ]; then + # Merge/cherry-pick/rebase in progress: incoming changes are already documented + # in their original commits, adding entries here would duplicate them + echo "⏭️ Merge/cherry-pick/rebase in progress, skipping changelog auto-update" +else + CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true) fi -# Debug output to understand what's happening -echo " 🔍 Debug: Primary diff result: '$(git diff --cached --name-only --diff-filter=ACMR 2>/dev/null | wc -l | tr -d ' ')' files" -echo " 🔍 Debug: Status result: '$(git status --porcelain 2>/dev/null | wc -l | tr -d ' ')' lines" - if [ -n "$CHANGED_FILES" ]; then echo "📁 Checking changed files for module updates..." echo " 📋 Found $(echo "$CHANGED_FILES" | wc -l | tr -d ' ') files to process" @@ -241,7 +232,14 @@ if [ -n "$CHANGED_FILES" ]; then for file in $CHANGED_FILES; do echo " 🔍 Checking file: $file" module="" - + + # Skip submodule pointers (gitlinks, staged mode 160000): bumping a submodule + # reference is not a module change + if git ls-files --stage -- "$file" 2>/dev/null | grep -q "^160000"; then + echo " ⏭️ Submodule pointer, skipping" + continue + fi + # Detect module type and extract module name if [[ "$file" =~ ^android-urbi-framework/([^/]+)/ ]]; then # Framework module: android-urbi-framework/MODULE/... (when run from main repo) @@ -297,9 +295,7 @@ if [ -n "$CHANGED_FILES" ]; then echo "✅ Changelog auto-update complete" fi else - echo "ℹ️ No changes detected" - echo " 🔍 Debug: git diff --cached result was empty" - echo " 🔍 Debug: git status result: $(git status --porcelain | wc -l | tr -d ' ') lines" + echo "ℹ️ No staged changes detected, skipping changelog auto-update" fi ##### CHANGELOG AUTO-UPDATE END #####