From 560071929a86803036cc1d69bfdac19d008a793d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 11:42:03 +0100 Subject: [PATCH 01/11] chore(fastlane): ask for release secrets and make the release safer - The keystore passwords and the GitHub API token are asked for instead of being read from the environment, and checked before they are used. Signed builds keep the passwords out of Gradle caches and processes. - incrementVersion offers a menu of version increments and creates the empty release notes file; commitVersion commits and pushes the version change. releasePhase2 checks the release notes, that the branch is pushed and that the artifacts were built from HEAD. - releasePhase2DryRun shows what would be published without publishing. - The bundle is moved to release/ next to the APKs, and all artifacts are checked to be signed. - Every lane ends with a summary of its result and the next steps. printVersionInfo includes the F-Droid version codes in it. App Fastfiles should remove the password entries from their *_SIGNING_PROPERTIES; values still set in the environment are reported. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 683 +++++++++++++++++++++++++++----- 1 file changed, 579 insertions(+), 104 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 2370440..339314d 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -13,6 +13,11 @@ # update plugins # bundle exec fastlane update_plugins +require "json" +require "net/http" +require "open3" +require "tmpdir" + BUILD_NUMBER_RC_START = 51 BUILD_NUMBER_FINAL_START = 90 @@ -26,59 +31,189 @@ FDROID_ABI_MULTIPLIER = 10 TYPE_ALPHA = "alpha" TYPE_RC = "rc" TYPE_FINAL = "final" - -BUNDLE_PATH = "app/build/outputs/bundle/gplayRelease/app-gplay-release.aab" +# increment types to the next hotfix, minor or major version: version part to increment and resulting build number +NEXT_VERSION_TYPES = { + "hotfix-alpha" => ["patch", 0], + "hotfix-rc" => ["patch", BUILD_NUMBER_RC_START], + "hotfix-final" => ["patch", BUILD_NUMBER_FINAL_START], + "minor-alpha" => ["minor", 0], + "minor-rc" => ["minor", BUILD_NUMBER_RC_START], + "minor-final" => ["minor", BUILD_NUMBER_FINAL_START], + "major-alpha" => ["major", 0], +}.freeze +# former names of increment types +INCREMENT_TYPE_ALIASES = { "patch" => "hotfix-alpha", "minor" => "minor-alpha", "major" => "major-alpha" }.freeze +INCREMENT_TYPES_USAGE = "type:(rc|final|#{NEXT_VERSION_TYPES.keys.join("|")})" + +GRADLE_BUNDLE_PATH = "app/build/outputs/bundle/gplayRelease/app-gplay-release.aab" # moved to bundlePath after the build +BUILT_COMMIT_PATH = "app/build/outputs/releaseCommit.txt" +CHANGELOG_DIR = "metadata/android/en-US/changelogs" +RELEASE_NOTES_GUIDE = ".claude/skills/suggest-release-notes/release-notes.md" +CHANGELOG_MAX_LENGTH = 500 # Google Play limit for release notes default_platform(:android) ENV['SUPPLY_UPLOAD_MAX_RETRIES']='10' +# Secrets are not read from the environment but asked for when a release lane starts. +# Filled by askForSigningPasswords, merged into the app's *_SIGNING_PROPERTIES at build time. +SIGNING_STORE_PASSWORD_KEY = "android.injected.signing.store.password" +SIGNING_KEY_PASSWORD_KEY = "android.injected.signing.key.password" +SIGNING_PASSWORDS = {} +# signed builds neither store the signing configuration in the configuration cache nor keep it in a daemon. +# The Kotlin compiler runs inside the build, as a Kotlin daemon started by it would keep the passwords in its +# environment after the build. +SIGNED_BUILD_GRADLE_FLAGS = ["--no-configuration-cache", "--no-daemon", "-Pkotlin.compiler.execution.strategy=in-process"] + platform :android do - # Usage: fastlane incrementVersion type:(major|minor|patch|rc|final) - # For major, minor, and patch: will increment that version number by 1 and set the smaller ones to 0 + # Usage: fastlane incrementVersion [type:(rc|final|hotfix-alpha|hotfix-rc|hotfix-final|minor-alpha|minor-rc|minor-final|major-alpha)] # For rc, final: will set build number to first rc/first final or increment it by 1 - desc "Increment version code and version name" + # For hotfix-*, minor-*, major-*: will increment that version number by 1, set the smaller ones to 0 + # and set the build number to the first alpha, rc or final + # Without type, the resulting versions of all types are shown to choose from. + # rc or final after a final release asks for the next hotfix or minor version, as a released version + # cannot get another rc or final. + desc "Preparation phase 1: Increment version code and version name" lane :incrementVersion do |options| versionInfo = getVersionInfo() versionComponents = parseVersionCode(versionInfo) - newVersionComponents = incrementVersionComponents(versionComponents: versionComponents, type: options[:type]) + type = options[:type] || chooseIncrementType(versionInfo: versionInfo, versionComponents: versionComponents) + if type == TYPE_RC && versionComponents["type"] == TYPE_FINAL + type = chooseIncrementType(versionInfo: versionInfo, versionComponents: versionComponents, + types: ["hotfix-rc", "minor-rc"]) + elsif type == TYPE_FINAL && versionComponents["type"] == TYPE_FINAL + type = chooseIncrementType(versionInfo: versionInfo, versionComponents: versionComponents, + types: ["hotfix-final", "minor-final"]) + end + newVersionComponents = incrementVersionComponents(versionComponents: versionComponents, type: type) versionNameGenerated = generateVersionName(newVersionComponents) versionCodeGenerated = generateVersionCode(newVersionComponents) - promptYesNo(text: "Version code: #{versionInfo["versionCode"]} -> #{versionCodeGenerated}\n" + - "Version name: #{versionInfo["versionName"]} -> #{versionNameGenerated}" + promptYesNo( + title: "Check the new version", + text: "Version name: #{versionInfo["versionName"]} -> #{versionNameGenerated}\n" + + "Version code: #{versionInfo["versionCode"]} -> #{versionCodeGenerated}", + question: "Change the version in app/build.gradle.kts to #{versionNameGenerated}?" ) writeVersions(versionCode: versionCodeGenerated, versionName: versionNameGenerated) + summary = ["Version: #{versionInfo["versionName"]} (#{versionInfo["versionCode"]}) -> " + + "#{versionNameGenerated} (#{versionCodeGenerated}), changed in app/build.gradle.kts"] + if newVersionComponents["type"] == TYPE_ALPHA + summary << "Next: commit app/build.gradle.kts" + else + summary += createChangelogFile(versionCode: versionCodeGenerated) + end + printAtExit(title: "Version changed", lines: summary) + end + + desc "Preparation phase 2: Commit version change and changelog + ask to push" + lane :commitVersion do + versionInfo = getVersionInfo() + checkReleasable(parseVersionCode(versionInfo)) + checkChangelogFile(versionCode: versionInfo["versionCode"]) + + gradleFile = "../app/build.gradle.kts" + changelogFile = changelogPath(versionCode: versionInfo["versionCode"]) + message = "bump version to #{versionInfo["versionName"]}" + changelog = File.read(changelogFile, encoding: "UTF-8") + promptYesNo( + title: "Check the commit and the changelog", + text: "Commit message: #{message}\n" + + "Files: app/build.gradle.kts, fastlane/#{changelogFile}\n" + + "Changelog (#{changelog.strip.length} of #{CHANGELOG_MAX_LENGTH} characters), " + + "used for Google Play and the GitHub release:\n\n" + + changelog, + question: "Commit the version change and this changelog?" + ) + sh("git", "add", "--", gradleFile, changelogFile) + sh("git", "commit", "--signoff", "-m", message, "--", gradleFile, changelogFile) + + branch = sh("git", "symbolic-ref", "--short", "HEAD", log: false).strip + remote, remoteStatus = Open3.capture2("git", "config", "branch.#{branch}.remote") + merge, mergeStatus = Open3.capture2("git", "config", "branch.#{branch}.merge") + if remoteStatus.success? && mergeStatus.success? + target = [remote.strip, "HEAD:#{merge.strip}"] + else + target = ["--set-upstream", "origin", "HEAD"] + end + summary = ["Committed: #{last_git_commit[:abbreviated_commit_hash]} #{message}"] + if UI.confirm("Push branch #{branch} now (git push #{target.join(" ")})?") + sh("git", "push", *target) + summary << "Pushed branch #{branch}" + else + summary << "Not pushed. Push it before releasePhase2: git push #{target.join(" ")}" + end + summary << "Next: run releasePhase1" + printAtExit(title: "Version committed", lines: summary) end - desc "Run tests and build app" + desc "Release phase 1: Run tests and build app" lane :releasePhase1 do + warnAboutUnusedSecrets() + ensure_git_status_clean(show_uncommitted_changes: true) + askForSigningPasswords() + builtCommit = last_git_commit[:commit_hash] + # may hold signing passwords of releases before signed builds were run without configuration cache + sh("rm -rf ../.gradle/configuration-cache") sh("rm -rf ../release/ && mkdir -p ../release") gradle(task: 'clean') versionInfo = getVersionInfo() test() # needs to be overwritten in apps - buildBundle() - buildAPKs(code: versionInfo["versionCode"]) + apks = buildRelease(versionCode: versionInfo["versionCode"]) + File.write("../#{BUILT_COMMIT_PATH}", builtCommit) + + printAtExit(title: "Release phase 1 finished", lines: [ + "Version #{versionInfo["versionName"]} (#{versionInfo["versionCode"]}), built from commit #{builtCommit}", + "App bundle for Google Play: #{File.expand_path("../#{bundlePath(versionCode: versionInfo["versionCode"])}")}", + *apks.map { |apk| "APK: #{File.expand_path(apk[:path])} (signed by #{apk[:signer]})" }, + "Next: test the APKs, then run releasePhase2DryRun and releasePhase2", + "If you find a bug: fix it, commit, and run releasePhase1 again", + ]) end desc "Release phase 2: checks, tag, create GH release, upload to appstores" lane :releasePhase2 do + releasePhase2Steps(dryRun: false) + end + + desc "Release phase 2 dry run: run all checks, show what would be published" + lane :releasePhase2DryRun do + releasePhase2Steps(dryRun: true) + end + + private_lane :releasePhase2Steps do |options| + dryRun = options[:dryRun] + warnAboutUnusedSecrets() ensure_git_status_clean(show_uncommitted_changes: true) + wouldFail = ensurePushed(dryRun: dryRun) + checkArtifactsCommit() versionInfo = getVersionInfo() versionComponents = parseVersionCode(versionInfo) checkReleasable(versionComponents) + checkChangelogFile(versionCode: versionInfo["versionCode"]) + githubToken = askForGithubToken() storeTrack = getPlayStoreTrack(versionComponents) isPrerelease = isPrerelease(versionComponents) tagName = getTagName(versionComponents) - preReleaseChecks(versionInfo: versionInfo, tagName: tagName, type: versionComponents["type"], track: storeTrack, isPrerelease: isPrerelease) - checkArtifactsExist() + preReleaseChecks(versionInfo: versionInfo, tagName: tagName, type: versionComponents["type"], track: storeTrack, isPrerelease: isPrerelease, dryRun: dryRun) + checkArtifactsExist(versionCode: versionInfo["versionCode"]) repoSpecificChecks(isPrerelease: isPrerelease) # needs to be overwritten in apps - tag(name: tagName) - createGithubRelease(name: versionInfo["versionName"], tag: tagName, versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease) - uploadToPlayStore(track: storeTrack) - uploadToHuawei(versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease) + summary = [ + tag(name: tagName, dryRun: dryRun), + createGithubRelease(token: githubToken, name: versionInfo["versionName"], tag: tagName, versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease, dryRun: dryRun), + uploadToPlayStore(track: storeTrack, versionCode: versionInfo["versionCode"], dryRun: dryRun), + uploadToHuawei(versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease, dryRun: dryRun), + ].compact + if dryRun + summary += wouldFail.map { |message| "Would fail in releasePhase2: #{message}" } + summary << (wouldFail.empty? ? "Next: run releasePhase2" : "Next: fix the above, then run releasePhase2") + printAtExit(title: "Dry run of #{versionInfo["versionName"]} finished, nothing was published", lines: summary) + else + summary << "Next: check the GitHub release and the release in the Google Play Console" + printAtExit(title: "#{versionInfo["versionName"]} released", lines: summary) + end end desc "Build ABI APKs for F-Droid in app/build/fdroid/" @@ -94,15 +229,16 @@ platform :android do lane :printVersionInfo do versionInfo = getVersionInfo() versionComponents = parseVersionCode(versionInfo) - print "Version code: #{versionInfo["versionCode"]}\n" - print "Version name: #{versionInfo["versionName"]}\n" - print "Major: #{versionComponents["major"]}\n" - print "Minor: #{versionComponents["minor"]}\n" - print "Patch: #{versionComponents["patch"]}\n" - print "Build: #{versionComponents["build"]}\n" - fdroidAbiVersionCodes(versionCode: versionInfo["versionCode"]).each do |abi, versionCode| - print "F-Droid #{abi} version code: #{versionCode}\n" - end + printAtExit(title: "Version info", lines: [ + "Version code: #{versionInfo["versionCode"]}", + "Version name: #{versionInfo["versionName"]}", + "Major: #{versionComponents["major"]}", + "Minor: #{versionComponents["minor"]}", + "Patch: #{versionComponents["patch"]}", + "Build: #{versionComponents["build"]}", + ] + fdroidAbiVersionCodes(versionCode: versionInfo["versionCode"]).map { |abi, versionCode| + "F-Droid #{abi} version code: #{versionCode}" + }) end desc "Upload Alpha version to play store" @@ -133,6 +269,19 @@ platform :android do { "major" => major, "minor" => minor, "patch" => patch, "build" => build, "type" => type } end + desc "Let the user choose the version increment type, showing the resulting version of each" + private_lane :chooseIncrementType do |options| + types = options[:types] || (options[:versionComponents]["type"] == TYPE_FINAL ? + NEXT_VERSION_TYPES.keys : + [TYPE_RC, TYPE_FINAL, *NEXT_VERSION_TYPES.keys.grep(/-alpha$/)]) + choices = types.map do |type| + components = incrementVersionComponents(versionComponents: options[:versionComponents].dup, type: type) + [generateVersionCode(components), type, generateVersionName(components)] + end.sort.to_h { |code, type, name| ["#{type.ljust(12)} #{name} (#{code})", type] } + UI.message("Current version: #{options[:versionInfo]["versionName"]} (#{options[:versionInfo]["versionCode"]})") + choices[UI.select("Increment to:", choices.keys)] + end + desc "Get version type from build number" private_lane :getVersionType do |options| build = options[:build] @@ -148,7 +297,6 @@ platform :android do desc "Generate versionCode from version components" private_lane :generateVersionCode do |versionComponents| - puts "Generating version code from #{versionComponents}" major = versionComponents["major"] minor = versionComponents["minor"] patch = versionComponents["patch"] @@ -168,7 +316,6 @@ platform :android do private_lane :generateVersionName do |versionComponents| suffix = "" buildNumber = versionComponents["build"] - puts "Generating version name from #{versionComponents}\n" case when versionComponents["type"] == TYPE_RC rcNumber = (buildNumber - BUILD_NUMBER_RC_START) + 1 @@ -190,6 +337,63 @@ platform :android do end end + desc "Get the path of the release bundle for a version code, relative to the repository root" + private_lane :bundlePath do |options| + "release/nextcloud-#{APP}-gplay-#{options[:versionCode]}.aab" + end + + desc "Get the changelog file path for a version code, relative to the fastlane folder" + private_lane :changelogPath do |options| + "#{CHANGELOG_DIR}/#{options[:versionCode]}.txt" + end + + desc "Create empty changelog file for the version code if it does not exist yet, returns what was done and the next steps" + private_lane :createChangelogFile do |options| + path = changelogPath(versionCode: options[:versionCode]) + if File.exist?(path) + summary = ["Changelog: already exists, fastlane/#{path}", "Next: check the changelog"] + else + FileUtils.mkdir_p(CHANGELOG_DIR) + File.write(path, "") + summary = ["Changelog: created empty file fastlane/#{path}"] + if File.exist?("../#{RELEASE_NOTES_GUIDE}") + summary << "Next: fill the changelog, see #{RELEASE_NOTES_GUIDE}, or run /suggest-release-notes in Claude Code" + else + summary << "Next: fill the changelog" + end + end + summary << "Next: run commitVersion" + end + + desc "Print the lines when fastlane exits, after its summary, so they are the last output" + private_lane :printAtExit do |options| + at_exit do + puts("") + UI.header(options[:title]) + options[:lines].each { |line| UI.important(line) } + end + end + + desc "Check that the changelog file for the version code exists, is not empty and fits into Google Play" + private_lane :checkChangelogFile do |options| + path = changelogPath(versionCode: options[:versionCode]) + if !File.exist?(path) + UI.user_error!("Changelog not found: fastlane/#{path}") + end + # independent of the locale, Google Play counts characters of UTF-8 text + text = File.read(path, encoding: "UTF-8") + if !text.valid_encoding? + UI.user_error!("Changelog is not UTF-8 encoded: fastlane/#{path}") + end + length = text.strip.length + if length == 0 + UI.user_error!("Changelog is empty: fastlane/#{path}") + end + if length > CHANGELOG_MAX_LENGTH + UI.user_error!("Changelog has #{length} characters, maximum is #{CHANGELOG_MAX_LENGTH}: fastlane/#{path}") + end + end + desc "Write versions to gradle file" private_lane :writeVersions do |options| File.open("../app/build.gradle.kts","r+") do |file| @@ -204,33 +408,36 @@ platform :android do private_lane :incrementVersionComponents do |options| versionComponents = options[:versionComponents] - case options[:type] - when "major" - versionComponents["major"] = versionComponents["major"] + 1 - versionComponents["minor"] = 0 - versionComponents["patch"] = 0 - versionComponents["build"] = 0 - when "minor" - versionComponents["minor"] = versionComponents["minor"] + 1 - versionComponents["patch"] = 0 - versionComponents["build"] = 0 - when "patch" - versionComponents["patch"] = versionComponents["patch"] + 1 - versionComponents["build"] = 0 - when "rc" - if versionComponents["type"] != TYPE_RC + type = INCREMENT_TYPE_ALIASES.fetch(options[:type], options[:type]) + if NEXT_VERSION_TYPES.key?(type) + part, build = NEXT_VERSION_TYPES[type] + case part + when "major" + versionComponents["major"] = versionComponents["major"] + 1 + versionComponents["minor"] = 0 + versionComponents["patch"] = 0 + when "minor" + versionComponents["minor"] = versionComponents["minor"] + 1 + versionComponents["patch"] = 0 + when "patch" + versionComponents["patch"] = versionComponents["patch"] + 1 + end + versionComponents["build"] = build + elsif type == TYPE_RC + if versionComponents["type"] == TYPE_FINAL + UI.user_error!("There is no rc after a final release, use hotfix-rc or minor-rc") + elsif versionComponents["type"] != TYPE_RC versionComponents["build"] = BUILD_NUMBER_RC_START else versionComponents["build"] = versionComponents["build"] + 1 end - when "final" - if versionComponents["type"] != TYPE_FINAL - versionComponents["build"] = BUILD_NUMBER_FINAL_START - else - versionComponents["build"] = versionComponents["build"] + 1 + elsif type == TYPE_FINAL + if versionComponents["type"] == TYPE_FINAL + UI.user_error!("There is no further final of a released version, use hotfix-final or minor-final") end + versionComponents["build"] = BUILD_NUMBER_FINAL_START else - UI.user_error!("Unknown or missing version increment type #{options[:type]}. Usage: incrementVersion type:(major|minor|patch|rc|final)") + UI.user_error!("Unknown or missing version increment type #{options[:type]}. Usage: incrementVersion #{INCREMENT_TYPES_USAGE}") end versionComponents["type"] = getVersionType(build: versionComponents["build"]) versionComponents @@ -280,64 +487,291 @@ platform :android do end end - desc "Build app bundle" - private_lane :buildBundle do - gradle( - task: 'bundle', - flavor: 'Gplay', - build_type: 'Release', - print_command: false, - properties: GRADLE_SIGNING_PROPERTIES - ) + desc "Run a signed Gradle build, the signing properties are only in the environment of the Gradle process" + private_lane :signedGradleBuild do |options| + env = options[:properties].to_h { |key, value| ["ORG_GRADLE_PROJECT_#{key}", value.to_s] } + # bash instead of the /bin/sh of gradlew, as dash drops environment variables with dots in their names + if !system(env, "bash", "./gradlew", *SIGNED_BUILD_GRADLE_FLAGS, *options[:tasks], chdir: "..") + UI.user_error!("Gradle tasks failed: #{options[:tasks].join(" ")}") + end end - - desc "Build signed APK" - private_lane :SignedRelease do |options| - gradle( - task: 'assemble', - flavor: options[:flavor], - build_type: 'Release', - print_command: false, - properties: defined?(APK_SIGNING_PROPERTIES) ? APK_SIGNING_PROPERTIES : GRADLE_SIGNING_PROPERTIES + + desc "Build signed app bundle and APKs, with one Gradle run per keystore" + private_lane :buildRelease do |options| + apkFlavors = APP == "files" ? ["generic", "gplay", "huawei"] : ["generic", "gplay"] + bundleTasks = ["bundleGplayRelease"] + apkTasks = apkFlavors.map { |flavor| "assemble#{flavor.capitalize}Release" } + uploadProperties = GRADLE_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS.fetch(:gradle)) + if defined?(APK_SIGNING_PROPERTIES) + signedGradleBuild(tasks: bundleTasks, properties: uploadProperties) + signedGradleBuild(tasks: apkTasks, properties: APK_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS.fetch(:apk))) + else + signedGradleBuild(tasks: bundleTasks + apkTasks, properties: uploadProperties) + end + + bundle = bundlePath(versionCode: options[:versionCode]) + # out of Gradle's output folder, which other builds overwrite + sh("mv ../#{GRADLE_BUNDLE_PATH} ../#{bundle}") + checkBundleSigned(path: bundle) + apkFlavors.map do |flavor| + apk = "../release/nextcloud-#{APP}-#{flavor}-#{options[:versionCode]}.apk" + sh("mv ../app/build/outputs/apk/#{flavor}/release/*.apk #{apk}") + { path: apk, signer: checkApkSigned(path: apk) } + end + end + + # A build that does not get the signing properties produces unsigned artifacts without failing. + desc "Check that the app bundle is signed" + private_lane :checkBundleSigned do |options| + jarsigner = ENV["JAVA_HOME"] ? File.join(ENV["JAVA_HOME"], "bin", "jarsigner") : "jarsigner" + begin + output, status = Open3.capture2e(jarsigner, "-J-Duser.language=en", "-verify", "-strict", "../#{options[:path]}") + rescue Errno::ENOENT + UI.user_error!("jarsigner not found, set JAVA_HOME or add jarsigner to PATH") + end + # exit code bits: 1 verification failed, 8 wrong key usage, 16 unsigned entries. + # 4 (certificate chain not validated) is expected for self-signed upload keys. + if status.exitstatus.nil? || (status.exitstatus & (1 | 8 | 16)) != 0 + UI.user_error!("App bundle is not signed correctly: #{options[:path]}\n#{output.strip}") + end + end + + desc "Check that an APK is signed, returns the certificate DN of the signer" + private_lane :checkApkSigned do |options| + sdk = ENV["ANDROID_HOME"] || ENV["ANDROID_SDK_ROOT"] + if sdk.nil? && File.exist?("../local.properties") + sdk = File.read("../local.properties")[/^sdk\.dir=(.*)$/, 1] + end + apksigner = sdk && Dir.glob(File.join(sdk, "build-tools", "*", "apksigner")) + .max_by { |path| File.basename(File.dirname(path)).split(/[.-]/).map(&:to_i) } + if apksigner.nil? + UI.user_error!("apksigner not found, set ANDROID_HOME") + end + output, status = Open3.capture2e(apksigner, "verify", "--print-certs", options[:path]) + if !status.success? + UI.user_error!("APK is not signed correctly: #{options[:path]}\n#{output.strip}") + end + signer = output[/certificate DN: (.*)$/, 1].to_s.strip + UI.message("#{File.basename(options[:path])}: signed by #{signer}") + signer + end + + desc "Ask for keystore passwords (upload keystore, and APK keystore if APK_SIGNING_PROPERTIES is defined)" + private_lane :askForSigningPasswords do + SIGNING_PASSWORDS[:gradle] = { + SIGNING_STORE_PASSWORD_KEY => promptSecret(text: "Enter Upload keystore password:"), + SIGNING_KEY_PASSWORD_KEY => promptSecret(text: "Enter Upload key password:"), + } + checkSigningPasswords(name: "Upload", properties: GRADLE_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:gradle])) + if defined?(APK_SIGNING_PROPERTIES) + SIGNING_PASSWORDS[:apk] = { + SIGNING_STORE_PASSWORD_KEY => promptSecret(text: "Enter APK keystore password:"), + SIGNING_KEY_PASSWORD_KEY => promptSecret(text: "Enter APK key password:"), + } + checkSigningPasswords(name: "APK", properties: APK_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:apk])) + end + end + + desc "Check keystore password, key alias and key password, so mistakes are found before the build" + private_lane :checkSigningPasswords do |options| + properties = options[:properties] + storeFile = File.expand_path(properties["android.injected.signing.store.file"].to_s, "..") + if !File.file?(storeFile) + UI.user_error!("#{options[:name]} keystore not found: #{storeFile}") + end + # Loads the key like the signing does. keytool cannot be used, it ignores the key password of PKCS12 keystores. + source = <<~JAVA + import java.io.File; + import java.security.KeyStore; + + public class CheckKeystore { + public static void main(String[] args) { + try { + KeyStore keyStore = KeyStore.getInstance(new File(args[0]), + System.getenv("FASTLANE_CHECK_STORE_PASSWORD").toCharArray()); + if (!keyStore.isKeyEntry(args[1])) { + System.err.println("Key alias not found: " + args[1]); + System.exit(1); + } + keyStore.getKey(args[1], System.getenv("FASTLANE_CHECK_KEY_PASSWORD").toCharArray()); + } catch (Exception e) { + System.err.println(e); + System.exit(1); + } + } + } + JAVA + java = ENV["JAVA_HOME"] ? File.join(ENV["JAVA_HOME"], "bin", "java") : "java" + # passwords are handed over as environment of the java process only, so they do not show up in ps + env = { + "FASTLANE_CHECK_STORE_PASSWORD" => properties[SIGNING_STORE_PASSWORD_KEY], + "FASTLANE_CHECK_KEY_PASSWORD" => properties[SIGNING_KEY_PASSWORD_KEY], + } + output = nil + status = nil + Dir.mktmpdir do |dir| + sourceFile = File.join(dir, "CheckKeystore.java") + File.write(sourceFile, source) + begin + output, status = Open3.capture2e(env, java, sourceFile, storeFile, + properties["android.injected.signing.key.alias"].to_s) + rescue Errno::ENOENT + UI.user_error!("java not found, set JAVA_HOME or add java to PATH") + end + end + if !status.success? + UI.user_error!("#{options[:name]} keystore check failed: #{output.lines.last.to_s.strip}") + end + end + + desc "Warn about passwords and tokens set in the environment, which are asked for instead" + private_lane :warnAboutUnusedSecrets do + names = ENV.keys.grep(/^FASTLANE_.+_(PASSWORD|GITHUB_API_TOKEN)$/).sort + if !names.empty? + UI.important("Not used, the values are asked for instead. Remove them from your shell configuration: #{names.join(", ")}") + end + end + + desc "Ask for GitHub API token and check that it can push to the repository" + private_lane :askForGithubToken do + token = promptSecret(text: "Enter GitHub API token:").strip + result = githubGet(token: token, path: "/repos/#{REPO}") + if result[:status] != 200 + UI.user_error!("GitHub API token was rejected (HTTP #{result[:status]})") + end + # permissions of the account, the token may have less + if result[:json].dig("permissions", "push") != true + UI.user_error!("Your GitHub account has no push permission for #{REPO}") + end + if result[:scopes].nil? + # fine-grained tokens do not report their permissions + UI.important("Permissions of fine-grained tokens cannot be checked. The token needs read and write access to Contents of #{REPO}.") + else + scopes = result[:scopes].split(",").map(&:strip) + if (scopes & ["repo", "public_repo"]).empty? + UI.user_error!("GitHub API token needs the scope repo or public_repo, it has: #{scopes.empty? ? "none" : scopes.join(", ")}") + end + end + token + end + + desc "GET request to the GitHub API. Unlike fastlane's github_api, it returns the token scopes and never prints the token." + private_lane :githubGet do |options| + uri = URI("https://api.github.com#{options[:path]}") + request = Net::HTTP::Get.new(uri) + request["Authorization"] = "Bearer #{options[:token]}" + request["Accept"] = "application/vnd.github+json" + begin + response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) } + rescue StandardError => e + UI.user_error!("GitHub API request failed: #{e.class}") + end + json = begin + JSON.parse(response.body.to_s) + rescue JSON::ParserError + {} + end + { status: response.code.to_i, scopes: response["X-OAuth-Scopes"], json: json } + end + + desc "Check that all local commits are pushed to the upstream branch, ask if the upstream branch has newer commits. " + + "Returns the problems a dry run only warns about." + private_lane :ensurePushed do |options| + sh("git fetch --quiet") + upstream, status = Open3.capture2("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}") + if !status.success? + message = "Current branch has no upstream branch" + dryRunOr(dryRun: options[:dryRun], message: message) + next [message] + end + problems = [] + upstream = upstream.strip + unpushed = sh("git rev-list --count #{upstream}..HEAD", log: false).strip.to_i + if unpushed > 0 + problems << "#{unpushed} commit(s) not pushed to #{upstream}" + dryRunOr(dryRun: options[:dryRun], message: problems.last) + end + missing = sh("git rev-list --count HEAD..#{upstream}", log: false).strip.to_i + if missing > 0 + promptYesNo( + title: "#{upstream} has newer commits", + text: "#{missing} commit(s) on #{upstream} are not in the local branch and will not be part of this release.", + question: "Release without these commits?" ) - - sh("mv ../app/build/outputs/apk/#{options[:flavor]}/release/*.apk ../release/nextcloud-#{APP}-#{options[:flavor]}-#{options[:versionCode]}.apk") + end + problems end - - desc "Build all APKs" - private_lane :buildAPKs do |options| - SignedRelease(flavor: "generic", versionCode: options[:code]) - SignedRelease(flavor: "gplay", versionCode: options[:code]) - - if APP == "files" - SignedRelease(flavor: "huawei", versionCode: options[:code]) + + desc "Fail with the message, or only warn about it in a dry run" + private_lane :dryRunOr do |options| + if options[:dryRun] + UI.important("[dry run] would fail: #{options[:message]}") + else + UI.user_error!(options[:message]) end end - - desc "Create release tag" + + desc "Check that the release artifacts were built from the current commit" + private_lane :checkArtifactsCommit do + if !File.exist?("../#{BUILT_COMMIT_PATH}") + UI.user_error!("#{BUILT_COMMIT_PATH} not found, run releasePhase1 first") + end + builtCommit = File.read("../#{BUILT_COMMIT_PATH}").strip + headCommit = last_git_commit[:commit_hash] + if builtCommit != headCommit + UI.user_error!("Artifacts were built from #{builtCommit}, but HEAD is #{headCommit}. Run releasePhase1 again.") + end + end + + desc "Create and push release tag, returns a summary. A tag on HEAD from a failed earlier run is reused." private_lane :tag do |options| tagName = options[:name] - add_git_tag( - tag: tagName, - sign: true - ) - push_git_tags(tag: tagName) + existing, status = Open3.capture2("git", "rev-parse", "--quiet", "--verify", "refs/tags/#{tagName}^{commit}") + if status.success? + if existing.strip != last_git_commit[:commit_hash] + UI.user_error!("Tag #{tagName} already exists on another commit: #{existing.strip}") + end + UI.important("Tag #{tagName} already exists on HEAD, it is reused") + summary = "Tag: #{tagName} (already existed on HEAD)" + elsif options[:dryRun] + UI.important("[dry run] would create signed tag #{tagName} on HEAD") + summary = "Tag: #{tagName} would be created on HEAD and pushed" + else + add_git_tag( + tag: tagName, + sign: true + ) + summary = "Tag: #{tagName} created on HEAD" + end + if options[:dryRun] + UI.important("[dry run] would push tag #{tagName}") + else + push_git_tags(tag: tagName) + summary += ", pushed" + end + summary end - desc "Upload release artifacts to Google Play" + desc "Upload release artifacts to Google Play, returns a summary" private_lane :uploadToPlayStore do |options| + if options[:dryRun] + UI.important("[dry run] would upload #{bundlePath(versionCode: options[:versionCode])} to Google Play track #{options[:track]}") + next "Google Play: bundle would be uploaded to track #{options[:track]}" + end upload_to_play_store( skip_upload_images: true, skip_upload_apk: true, track: options[:track], - aab: BUNDLE_PATH + aab: bundlePath(versionCode: options[:versionCode]) ) + "Google Play: bundle uploaded to track #{options[:track]}" end desc "Check if release artifacts exist" - private_lane :checkArtifactsExist do - if !File.exist?("../#{BUNDLE_PATH}") - UI.user_error!("Bundle not found at #{BUNDLE_PATH}") + private_lane :checkArtifactsExist do |options| + bundle = bundlePath(versionCode: options[:versionCode]) + if !File.exist?("../#{bundle}") + UI.user_error!("Bundle not found at #{bundle}, run releasePhase1 first") end end @@ -346,30 +780,57 @@ platform :android do versionInfo = options[:versionInfo] tagName = options[:tagName] currentBranch = git_branch() - text = "Version code: #{versionInfo["versionCode"]}\n" + - "Version name: #{versionInfo["versionName"]}\n" + + text = "Version name: #{versionInfo["versionName"]}\n" + + "Version code: #{versionInfo["versionCode"]}\n" + "Current branch: #{currentBranch}\n" + "Version type: #{options[:type]}\n" + "Tag: #{tagName}\n" + "Track: #{options[:track]}\n" + "Prerelease: #{options[:isPrerelease]}" - promptYesNo(text: text) + if options[:dryRun] + promptYesNo(title: "Check the release (dry run, nothing is published)", text: text, + question: "Run the dry run for this release?") + else + promptYesNo(title: "Check the release, it is published after this question", text: text, + question: "Publish #{versionInfo["versionName"]} now (tag, GitHub release, store uploads)?") + end end + desc "Create GitHub release, returns a summary. A release from a failed earlier run is kept." private_lane :createGithubRelease do |options| - set_github_release( - repository_name: REPO, - api_token: ENV["FASTLANE_NEXTCLOUD_GITHUB_API_TOKEN"], - name: options[:name], - is_prerelease: options[:isPrerelease], - tag_name: options[:tag], - description: (File.read("metadata/android/en-US/changelogs/#{options[:versionCode]}.txt") rescue "No changelog provided"), - upload_assets: Dir.glob(File.expand_path("../release/*.apk")) - ) + existing = githubGet(token: options[:token], path: "/repos/#{REPO}/releases/tags/#{options[:tag]}") + case existing[:status] + when 200 + UI.important("GitHub release for #{options[:tag]} already exists, it is not changed: #{existing[:json]["html_url"]}") + "GitHub release: #{existing[:json]["html_url"]} (already existed, not changed)" + when 404 + if options[:dryRun] + assets = Dir.glob(File.expand_path("../release/*.apk")).map { |path| File.basename(path) } + UI.important("[dry run] would create GitHub release \"#{options[:name]}\" for tag #{options[:tag]}, " + + "prerelease: #{options[:isPrerelease]}, assets: #{assets.empty? ? "none" : assets.join(", ")}") + next "GitHub release: \"#{options[:name]}\" would be created with #{assets.length} APK(s)" + end + set_github_release( + repository_name: REPO, + api_token: options[:token], + name: options[:name], + is_prerelease: options[:isPrerelease], + tag_name: options[:tag], + description: File.read(changelogPath(versionCode: options[:versionCode]), encoding: "UTF-8"), + upload_assets: Dir.glob(File.expand_path("../release/*.apk")) + ) + "GitHub release: #{lane_context[SharedValues::SET_GITHUB_RELEASE_HTML_LINK]}" + else + UI.user_error!("Could not check for an existing GitHub release (HTTP #{existing[:status]})") + end end private_lane :uploadToHuawei do |options| if APP == "files" && options[:isPrerelease] == false + if options[:dryRun] + UI.important("[dry run] would upload release/nextcloud-#{APP}-huawei-#{options[:versionCode]}.apk to Huawei AppGallery") + next "Huawei AppGallery: APK would be uploaded and submitted for review" + end huawei_appgallery_connect( client_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_ID"], client_secret: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_SECRET"], @@ -378,14 +839,28 @@ platform :android do submit_for_review: true, delay_before_submit_for_review: 30, ) + "Huawei AppGallery: APK uploaded and submitted for review" end end end +desc "Show what to check and ask a yes/no question, abort on no" private_lane :promptYesNo do |options| - puts "\n" + options[:text] - answer = prompt(text: "is this okay?", boolean: true) - if !answer + puts("") + UI.header(options[:title] || "Check") + # leading line break, so all lines of the text start at the beginning of a line, after fastlane's timestamp line + puts("\n" + options[:text]) + puts("") + # UI.confirm instead of the prompt action, whose step header would separate the question from the text + if !UI.confirm(options[:question] || "Is this okay?") UI.user_error!("Aborting") end end + +private_lane :promptSecret do |options| + value = prompt(text: options[:text], secure_text: true).to_s + if value.strip.empty? + UI.user_error!("No value entered for: #{options[:text]}") + end + value +end From 5aa0aaf45134a883292e3b3e6208af8234edee68 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 11:42:03 +0100 Subject: [PATCH 02/11] feat: add suggest-release-notes Claude Code skill The skill drafts the release notes file that fastlane incrementVersion creates, from the merged pull requests of the milestone, for Google Play and the GitHub release. Its guide release-notes.md also serves people writing release notes by hand. It is synced to .claude/skills/ of the apps and reads the repository from REPO in fastlane/Fastfile. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- .../skills/suggest-release-notes/SKILL.md | 10 ++ .../suggest-release-notes/release-notes.md | 103 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 config/root/.claude/skills/suggest-release-notes/SKILL.md create mode 100644 config/root/.claude/skills/suggest-release-notes/release-notes.md diff --git a/config/root/.claude/skills/suggest-release-notes/SKILL.md b/config/root/.claude/skills/suggest-release-notes/SKILL.md new file mode 100644 index 0000000..361ad45 --- /dev/null +++ b/config/root/.claude/skills/suggest-release-notes/SKILL.md @@ -0,0 +1,10 @@ +--- +name: suggest-release-notes +description: Fill the release changelog file that fastlane incrementVersion created, named after the version code, for a release candidate or final release. Use when asked to write release notes or a changelog for a release. +--- + + +Read and follow [release-notes.md](release-notes.md). diff --git a/config/root/.claude/skills/suggest-release-notes/release-notes.md b/config/root/.claude/skills/suggest-release-notes/release-notes.md new file mode 100644 index 0000000..d83d859 --- /dev/null +++ b/config/root/.claude/skills/suggest-release-notes/release-notes.md @@ -0,0 +1,103 @@ + +# Writing the release changelog + +`bundle exec fastlane incrementVersion` creates an empty changelog file named after the version code, +usually `fastlane/metadata/android/en-US/changelogs/.txt`, and prints its path. Its content +is used as release notes on Google Play and as description of the GitHub release. `releasePhase2` refuses to release if the file is +empty or longer than 500 characters. + +These instructions describe how to fill that file. They are written so that an AI agent can follow them, +but apply to humans as well. They are shared by several Nextcloud Android apps, which is why they name +no app or repository. + +## 1. Find the release + +Read `versionCode` and `versionName` from `app/build.gradle.kts`, and the GitHub repository (``, +e.g. `nextcloud/talk-android`) from `REPO` in `fastlane/Fastfile`. + +- The last two digits of the version code are the build number: 51–89 is a release candidate, 90–99 is a + final release. Below 51 is an alpha, which gets no changelog. +- The version without suffix (e.g. `25.1.0` for `25.1.0 RC2`) is the title of the GitHub milestone. +- The changelog file is `.txt` in the folder set by `CHANGELOG_DIR` in the fastlane files, + relative to `fastlane/` (usually `metadata/android/en-US/changelogs`). Do not overwrite content that is + already in it without asking. + +## 2. Collect the changes + +The changelog of a release candidate or final release lists all changes of the version, not only those +since the previous release candidate. Collect: + +1. **Previous notes of the same version.** If a release candidate of this version was already published, + start from its notes and add to them: + `gh release list -R ` and `gh release view -R `. + Tags look like `rc-25.1.0-02` (release candidate) and `25.1.0` (final). +2. **Merged pull requests in the milestone.** This is the main source: + ``` + gh api 'repos//milestones?state=all&per_page=100' -q '.[] | select(.title == "") | .number' + gh pr list -R --search 'milestone:"" is:merged' -L 500 --json number,title,body,author,labels + ``` +3. **Commits since the previous tag**, to find changes whose pull request is missing in the milestone: + `git log --oneline ..HEAD`. + +Pull requests titled `[stable-…] …` from `backportbot` are backports. Their body starts with +`Backport of #`. Treat a backport and its original as one change, and use the author of the +original pull request. + +## 3. Select what to mention + +Only mention what a user of the app notices. Leave out: + +- translation and synced file updates (`fix(l10n)`, label `sync`) +- dependency updates, CI, tests, build and release automation +- refactorings and code cleanup without visible effect + +Read the pull request body when the title is not clear enough to describe the change for users. + +## 4. Credit contributors + +Credit authors who are neither members of the Nextcloud GitHub organization nor bots, as `(@login)` +after the item. Several minor fixes by such contributors can be combined into one item, e.g. +`- Various bugs (@login1, @login2)`. + +- Organization membership: `gh api orgs/nextcloud/members/ --silent` succeeds for members + (HTTP 204) and fails for non-members (HTTP 404). +- Bots: logins ending in `[bot]` or starting with `app/`, and accounts like `backportbot`, + `nextcloud-bot`, `renovate` and `dependabot`. + +## 5. Write the file + +Format (sections without items are left out): + +``` +## Added +- Refreshing of conversation list +- Improved bluetooth handling (@login) + +## Fixed +- Notifications sometimes do not show up when using Android 11 or lower +- Various bugs (@login1, @login2) + +Minimum: NC 17 Server, Android 8.0 Oreo + +For a full list, please see https://github.com//milestone/?closed=1 +``` + +- Items are short, user facing English, without issue or pull request numbers and without commit prefixes + like `fix:`. +- Take the `Minimum` line from the previous release notes. Check the Android version against `minSdk` in + `app/build.gradle.kts` and update it if it changed. +- Use the milestone number found in step 2 for the link. + +## 6. Keep it within 500 characters + +Google Play does not accept release notes longer than 500 characters. The limit applies to the whole +file, including the `Minimum` line and the link. Check with `wc -m < `. + +If it is too long, keep the most important additions and fixes, and combine the remaining minor fixes +into `- Various bugs` (keeping the credits) or leave them out. The milestone link lists everything. + +Do not commit the file. Show it to the person doing the release, who reviews it and commits it together +with the version change by running `bundle exec fastlane commitVersion`. From 1df7c900791ad5b6ac9b04dddefd95f2af915241 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 11:56:21 +0100 Subject: [PATCH 03/11] chore: sync Claude Code skills to the apps Skills in config/skills/ are synced to .claude/skills/ of Files, Talk and Notes. Skills the apps keep themselves are not touched, as the sync does not delete files missing in the source. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- .github/sync.yml | 3 +++ .../{root/.claude => }/skills/suggest-release-notes/SKILL.md | 0 .../.claude => }/skills/suggest-release-notes/release-notes.md | 0 3 files changed, 3 insertions(+) rename config/{root/.claude => }/skills/suggest-release-notes/SKILL.md (100%) rename config/{root/.claude => }/skills/suggest-release-notes/release-notes.md (100%) diff --git a/.github/sync.yml b/.github/sync.yml index 87228d1..0b7c5ac 100644 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -18,6 +18,9 @@ group: - source: config/root/ dest: . + + - source: config/skills/ + dest: .claude/skills/ - repos: | nextcloud/android-library@master diff --git a/config/root/.claude/skills/suggest-release-notes/SKILL.md b/config/skills/suggest-release-notes/SKILL.md similarity index 100% rename from config/root/.claude/skills/suggest-release-notes/SKILL.md rename to config/skills/suggest-release-notes/SKILL.md diff --git a/config/root/.claude/skills/suggest-release-notes/release-notes.md b/config/skills/suggest-release-notes/release-notes.md similarity index 100% rename from config/root/.claude/skills/suggest-release-notes/release-notes.md rename to config/skills/suggest-release-notes/release-notes.md From c31d1323c092d3b82317ce917eb1ecc429ef747e Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 12:02:56 +0100 Subject: [PATCH 04/11] chore(fastlane): ask for the Huawei AppGallery credentials The Huawei AppGallery Connect API client ID and secret are no longer read from environment variables set in the shell configuration. releasePhase2 asks for them before anything is published, only when the release is uploaded to Huawei AppGallery (final releases of Files), and checks them by requesting an access token. The app ID is taken from HUAWEI_APP_ID in the app's Fastfile, or asked for. FASTLANE_*_HUAWEI_* values still set in the environment are reported. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 73 +++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 339314d..012bccb 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -196,6 +196,7 @@ platform :android do githubToken = askForGithubToken() storeTrack = getPlayStoreTrack(versionComponents) isPrerelease = isPrerelease(versionComponents) + huaweiCredentials = uploadsToHuawei(isPrerelease: isPrerelease) ? askForHuaweiCredentials() : nil tagName = getTagName(versionComponents) preReleaseChecks(versionInfo: versionInfo, tagName: tagName, type: versionComponents["type"], track: storeTrack, isPrerelease: isPrerelease, dryRun: dryRun) checkArtifactsExist(versionCode: versionInfo["versionCode"]) @@ -204,7 +205,7 @@ platform :android do tag(name: tagName, dryRun: dryRun), createGithubRelease(token: githubToken, name: versionInfo["versionName"], tag: tagName, versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease, dryRun: dryRun), uploadToPlayStore(track: storeTrack, versionCode: versionInfo["versionCode"], dryRun: dryRun), - uploadToHuawei(versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease, dryRun: dryRun), + uploadToHuawei(versionCode: versionInfo["versionCode"], credentials: huaweiCredentials, dryRun: dryRun), ].compact if dryRun summary += wouldFail.map { |message| "Would fail in releasePhase2: #{message}" } @@ -626,7 +627,7 @@ platform :android do desc "Warn about passwords and tokens set in the environment, which are asked for instead" private_lane :warnAboutUnusedSecrets do - names = ENV.keys.grep(/^FASTLANE_.+_(PASSWORD|GITHUB_API_TOKEN)$/).sort + names = ENV.keys.grep(/^FASTLANE_.+_(PASSWORD|GITHUB_API_TOKEN|HUAWEI_CLIENT_ID|HUAWEI_CLIENT_SECRET|HUAWEI_APP_ID)$/).sort if !names.empty? UI.important("Not used, the values are asked for instead. Remove them from your shell configuration: #{names.join(", ")}") end @@ -655,6 +656,37 @@ platform :android do token end + desc "Ask for the Huawei AppGallery Connect API client and check it before anything is published. " + + "The app ID is taken from HUAWEI_APP_ID in the app's Fastfile, or asked for." + private_lane :askForHuaweiCredentials do + clientId = promptSecret(text: "Enter Huawei AppGallery Connect API client ID:").strip + clientSecret = promptSecret(text: "Enter Huawei AppGallery Connect API client secret:").strip + appId = defined?(HUAWEI_APP_ID) ? HUAWEI_APP_ID : prompt(text: "Enter Huawei AppGallery app ID:").to_s.strip + if appId.empty? + UI.user_error!("No Huawei AppGallery app ID entered") + end + # same request the huawei_appgallery_connect plugin makes to get an access token + uri = URI("https://connect-api.cloud.huawei.com/api/oauth2/v1/token") + request = Net::HTTP::Post.new(uri, "Content-Type" => "application/json") + request.body = { client_id: clientId, client_secret: clientSecret, grant_type: "client_credentials" }.to_json + begin + response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) } + rescue StandardError => e + UI.user_error!("Huawei AppGallery Connect request failed: #{e.class}") + end + json = begin + JSON.parse(response.body.to_s) + rescue JSON::ParserError + {} + end + # a rejected client is answered with HTTP 200 and an error in "ret" instead of a token + if json["access_token"].nil? + UI.user_error!("Huawei AppGallery Connect rejected the API client ID or secret: " + + "#{json.dig("ret", "msg") || "HTTP #{response.code}"}") + end + { clientId: clientId, clientSecret: clientSecret, appId: appId } + end + desc "GET request to the GitHub API. Unlike fastlane's github_api, it returns the token scopes and never prints the token." private_lane :githubGet do |options| uri = URI("https://api.github.com#{options[:path]}") @@ -825,22 +857,29 @@ platform :android do end end + desc "Whether the release is uploaded to Huawei AppGallery: final releases of Files" + private_lane :uploadsToHuawei do |options| + APP == "files" && options[:isPrerelease] == false + end + + desc "Upload the Huawei APK to Huawei AppGallery, if credentials were asked for" private_lane :uploadToHuawei do |options| - if APP == "files" && options[:isPrerelease] == false - if options[:dryRun] - UI.important("[dry run] would upload release/nextcloud-#{APP}-huawei-#{options[:versionCode]}.apk to Huawei AppGallery") - next "Huawei AppGallery: APK would be uploaded and submitted for review" - end - huawei_appgallery_connect( - client_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_ID"], - client_secret: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_SECRET"], - app_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_APP_ID"], - apk_path: "release/nextcloud-#{APP}-huawei-#{options[:versionCode]}.apk", - submit_for_review: true, - delay_before_submit_for_review: 30, - ) - "Huawei AppGallery: APK uploaded and submitted for review" - end + credentials = options[:credentials] + next nil if credentials.nil? + apk = "release/nextcloud-#{APP}-huawei-#{options[:versionCode]}.apk" + if options[:dryRun] + UI.important("[dry run] would upload #{apk} to Huawei AppGallery") + next "Huawei AppGallery: APK would be uploaded and submitted for review" + end + huawei_appgallery_connect( + client_id: credentials[:clientId], + client_secret: credentials[:clientSecret], + app_id: credentials[:appId], + apk_path: apk, + submit_for_review: true, + delay_before_submit_for_review: 30, + ) + "Huawei AppGallery: APK uploaded and submitted for review" end end From 1226a8da0bde9950f8f2cebe12006b587d45ff3b Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 13:28:52 +0100 Subject: [PATCH 05/11] chore(fastlane): explain how to set a missing keystore file or key alias When the environment variable for the keystore file or key alias is not set, the keystore check reported the repository folder as missing keystore. It now names the missing setting and points to the comment in fastlane/Fastfile that lists the environment variables to set. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 012bccb..87188c0 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -563,22 +563,30 @@ platform :android do SIGNING_STORE_PASSWORD_KEY => promptSecret(text: "Enter Upload keystore password:"), SIGNING_KEY_PASSWORD_KEY => promptSecret(text: "Enter Upload key password:"), } - checkSigningPasswords(name: "Upload", properties: GRADLE_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:gradle])) + checkSigningPasswords(name: "Upload", constant: "GRADLE_SIGNING_PROPERTIES", properties: GRADLE_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:gradle])) if defined?(APK_SIGNING_PROPERTIES) SIGNING_PASSWORDS[:apk] = { SIGNING_STORE_PASSWORD_KEY => promptSecret(text: "Enter APK keystore password:"), SIGNING_KEY_PASSWORD_KEY => promptSecret(text: "Enter APK key password:"), } - checkSigningPasswords(name: "APK", properties: APK_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:apk])) + checkSigningPasswords(name: "APK", constant: "APK_SIGNING_PROPERTIES", properties: APK_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:apk])) end end desc "Check keystore password, key alias and key password, so mistakes are found before the build" private_lane :checkSigningPasswords do |options| properties = options[:properties] - storeFile = File.expand_path(properties["android.injected.signing.store.file"].to_s, "..") + # the app's Fastfile reads keystore file and key alias from environment variables, listed in its header comment + hint = "Set the environment variable that #{options[:constant]} in fastlane/Fastfile reads for it, " + + "e.g. in your shell configuration, see the comment at the top of fastlane/Fastfile." + { "android.injected.signing.store.file" => "file", "android.injected.signing.key.alias" => "key alias" }.each do |key, what| + if properties[key].to_s.strip.empty? + UI.user_error!("#{options[:name]} keystore #{what} is not set (#{key}). #{hint}") + end + end + storeFile = File.expand_path(properties["android.injected.signing.store.file"], "..") if !File.file?(storeFile) - UI.user_error!("#{options[:name]} keystore not found: #{storeFile}") + UI.user_error!("#{options[:name]} keystore not found: #{storeFile}. Check the path. #{hint}") end # Loads the key like the signing does. keytool cannot be used, it ignores the key password of PKCS12 keystores. source = <<~JAVA From 19b9a74400f5156800f5f768fe65d51722cac88d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 13:30:31 +0100 Subject: [PATCH 06/11] chore(fastlane): check keystore settings before asking for passwords The keystore file and key alias of the upload keystore and, if defined, the APK keystore are checked before the first password is asked for, so a missing setting is reported before the passwords are typed. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 87188c0..cba616e 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -559,22 +559,27 @@ platform :android do desc "Ask for keystore passwords (upload keystore, and APK keystore if APK_SIGNING_PROPERTIES is defined)" private_lane :askForSigningPasswords do + # before any password is asked for, so a missing setting does not waste the typing + checkSigningSettings(name: "Upload", constant: "GRADLE_SIGNING_PROPERTIES", properties: GRADLE_SIGNING_PROPERTIES) + if defined?(APK_SIGNING_PROPERTIES) + checkSigningSettings(name: "APK", constant: "APK_SIGNING_PROPERTIES", properties: APK_SIGNING_PROPERTIES) + end SIGNING_PASSWORDS[:gradle] = { SIGNING_STORE_PASSWORD_KEY => promptSecret(text: "Enter Upload keystore password:"), SIGNING_KEY_PASSWORD_KEY => promptSecret(text: "Enter Upload key password:"), } - checkSigningPasswords(name: "Upload", constant: "GRADLE_SIGNING_PROPERTIES", properties: GRADLE_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:gradle])) + checkSigningPasswords(name: "Upload", properties: GRADLE_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:gradle])) if defined?(APK_SIGNING_PROPERTIES) SIGNING_PASSWORDS[:apk] = { SIGNING_STORE_PASSWORD_KEY => promptSecret(text: "Enter APK keystore password:"), SIGNING_KEY_PASSWORD_KEY => promptSecret(text: "Enter APK key password:"), } - checkSigningPasswords(name: "APK", constant: "APK_SIGNING_PROPERTIES", properties: APK_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:apk])) + checkSigningPasswords(name: "APK", properties: APK_SIGNING_PROPERTIES.merge(SIGNING_PASSWORDS[:apk])) end end - desc "Check keystore password, key alias and key password, so mistakes are found before the build" - private_lane :checkSigningPasswords do |options| + desc "Check that keystore file and key alias are set and the keystore exists" + private_lane :checkSigningSettings do |options| properties = options[:properties] # the app's Fastfile reads keystore file and key alias from environment variables, listed in its header comment hint = "Set the environment variable that #{options[:constant]} in fastlane/Fastfile reads for it, " + @@ -588,6 +593,12 @@ platform :android do if !File.file?(storeFile) UI.user_error!("#{options[:name]} keystore not found: #{storeFile}. Check the path. #{hint}") end + end + + desc "Check keystore password, key alias and key password, so mistakes are found before the build" + private_lane :checkSigningPasswords do |options| + properties = options[:properties] + storeFile = File.expand_path(properties["android.injected.signing.store.file"], "..") # Loads the key like the signing does. keytool cannot be used, it ignores the key password of PKCS12 keystores. source = <<~JAVA import java.io.File; From f23c75da4301769ab9746ec475bb19c208a36dcc Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 14:56:30 +0100 Subject: [PATCH 07/11] chore: keep release notes guide inside the skill and fix markdownlint The guide was a separate file next to SKILL.md, so Claude had to read a second file after loading the skill. It is now the content of SKILL.md, which fastlane points to after incrementVersion. Lines are wrapped at 80 characters and code blocks have a language, as Codacy asks for. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 2 +- config/skills/suggest-release-notes/SKILL.md | 116 +++++++++++++++++- .../suggest-release-notes/release-notes.md | 103 ---------------- 3 files changed, 116 insertions(+), 105 deletions(-) delete mode 100644 config/skills/suggest-release-notes/release-notes.md diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index cba616e..97bdefe 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -48,7 +48,7 @@ INCREMENT_TYPES_USAGE = "type:(rc|final|#{NEXT_VERSION_TYPES.keys.join("|")})" GRADLE_BUNDLE_PATH = "app/build/outputs/bundle/gplayRelease/app-gplay-release.aab" # moved to bundlePath after the build BUILT_COMMIT_PATH = "app/build/outputs/releaseCommit.txt" CHANGELOG_DIR = "metadata/android/en-US/changelogs" -RELEASE_NOTES_GUIDE = ".claude/skills/suggest-release-notes/release-notes.md" +RELEASE_NOTES_GUIDE = ".claude/skills/suggest-release-notes/SKILL.md" CHANGELOG_MAX_LENGTH = 500 # Google Play limit for release notes default_platform(:android) diff --git a/config/skills/suggest-release-notes/SKILL.md b/config/skills/suggest-release-notes/SKILL.md index 361ad45..454c24a 100644 --- a/config/skills/suggest-release-notes/SKILL.md +++ b/config/skills/suggest-release-notes/SKILL.md @@ -6,5 +6,119 @@ description: Fill the release changelog file that fastlane incrementVersion crea ~ SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors ~ SPDX-License-Identifier: GPL-3.0-or-later --> +# Suggest release notes -Read and follow [release-notes.md](release-notes.md). +`bundle exec fastlane incrementVersion` creates an empty changelog file named +after the version code, usually +`fastlane/metadata/android/en-US/changelogs/.txt`, and prints its +path. Its content is used as release notes on Google Play and as description +of the GitHub release. `releasePhase2` refuses to release if the file is empty +or longer than 500 characters. + +These instructions describe how to fill that file. They are written so that an +AI agent can follow them, but apply to humans as well. They are shared by +several Nextcloud Android apps, which is why they name no app or repository. + +## 1. Find the release + +Read `versionCode` and `versionName` from `app/build.gradle.kts`, and the +GitHub repository (``, e.g. `nextcloud/talk-android`) from `REPO` in +`fastlane/Fastfile`. + +- The last two digits of the version code are the build number: 51–89 is a + release candidate, 90–99 is a final release. Below 51 is an alpha, which + gets no changelog. +- The version without suffix (e.g. `25.1.0` for `25.1.0 RC2`) is the title of + the GitHub milestone. +- The changelog file is `.txt` in the folder set by + `CHANGELOG_DIR` in the fastlane files, relative to `fastlane/` (usually + `metadata/android/en-US/changelogs`). Do not overwrite content that is + already in it without asking. + +## 2. Collect the changes + +The changelog of a release candidate or final release lists all changes of the +version, not only those since the previous release candidate. Collect: + +1. **Previous notes of the same version.** If a release candidate of this + version was already published, start from its notes and add to them: + `gh release list -R ` and `gh release view -R `. + Tags look like `rc-25.1.0-02` (release candidate) and `25.1.0` (final). +2. **Merged pull requests in the milestone.** This is the main source: + + ```bash + gh api 'repos//milestones?state=all&per_page=100' \ + -q '.[] | select(.title == "") | .number' + gh pr list -R --search 'milestone:"" is:merged' -L 500 \ + --json number,title,body,author,labels + ``` + +3. **Commits since the previous tag**, to find changes whose pull request is + missing in the milestone: `git log --oneline ..HEAD`. + +Pull requests titled `[stable-…] …` from `backportbot` are backports. Their +body starts with `Backport of #`. Treat a backport and its original as +one change, and use the author of the original pull request. + +## 3. Select what to mention + +Only mention what a user of the app notices. Leave out: + +- translation and synced file updates (`fix(l10n)`, label `sync`) +- dependency updates, CI, tests, build and release automation +- refactorings and code cleanup without visible effect + +Read the pull request body when the title is not clear enough to describe the +change for users. + +## 4. Credit contributors + +Credit authors who are neither members of the Nextcloud GitHub organization nor +bots, as `(@login)` after the item. Several minor fixes by such contributors +can be combined into one item, e.g. `- Various bugs (@login1, @login2)`. + +- Organization membership: `gh api orgs/nextcloud/members/ --silent` + succeeds for members (HTTP 204) and fails for non-members (HTTP 404). +- Bots: logins ending in `[bot]` or starting with `app/`, and accounts like + `backportbot`, `nextcloud-bot`, `renovate` and `dependabot`. + +## 5. Write the file + +Format (sections without items are left out): + + +```markdown +## Added +- Refreshing of conversation list +- Improved bluetooth handling (@login) + +## Fixed +- Notifications sometimes do not show up when using Android 11 or lower +- Various bugs (@login1, @login2) + +Minimum: NC 17 Server, Android 8.0 Oreo + +For a full list, please see https://github.com//milestone/?closed=1 +``` + + +- Items are short, user facing English, without issue or pull request numbers + and without commit prefixes like `fix:`. +- Take the `Minimum` line from the previous release notes. Check the Android + version against `minSdk` in `app/build.gradle.kts` and update it if it + changed. +- Use the milestone number found in step 2 for the link. + +## 6. Keep it within 500 characters + +Google Play does not accept release notes longer than 500 characters. The limit +applies to the whole file, including the `Minimum` line and the link. Check +with `wc -m < `. + +If it is too long, keep the most important additions and fixes, and combine +the remaining minor fixes into `- Various bugs` (keeping the credits) or leave +them out. The milestone link lists everything. + +Do not commit the file. Show it to the person doing the release, who reviews it +and commits it together with the version change by running +`bundle exec fastlane commitVersion`. diff --git a/config/skills/suggest-release-notes/release-notes.md b/config/skills/suggest-release-notes/release-notes.md deleted file mode 100644 index d83d859..0000000 --- a/config/skills/suggest-release-notes/release-notes.md +++ /dev/null @@ -1,103 +0,0 @@ - -# Writing the release changelog - -`bundle exec fastlane incrementVersion` creates an empty changelog file named after the version code, -usually `fastlane/metadata/android/en-US/changelogs/.txt`, and prints its path. Its content -is used as release notes on Google Play and as description of the GitHub release. `releasePhase2` refuses to release if the file is -empty or longer than 500 characters. - -These instructions describe how to fill that file. They are written so that an AI agent can follow them, -but apply to humans as well. They are shared by several Nextcloud Android apps, which is why they name -no app or repository. - -## 1. Find the release - -Read `versionCode` and `versionName` from `app/build.gradle.kts`, and the GitHub repository (``, -e.g. `nextcloud/talk-android`) from `REPO` in `fastlane/Fastfile`. - -- The last two digits of the version code are the build number: 51–89 is a release candidate, 90–99 is a - final release. Below 51 is an alpha, which gets no changelog. -- The version without suffix (e.g. `25.1.0` for `25.1.0 RC2`) is the title of the GitHub milestone. -- The changelog file is `.txt` in the folder set by `CHANGELOG_DIR` in the fastlane files, - relative to `fastlane/` (usually `metadata/android/en-US/changelogs`). Do not overwrite content that is - already in it without asking. - -## 2. Collect the changes - -The changelog of a release candidate or final release lists all changes of the version, not only those -since the previous release candidate. Collect: - -1. **Previous notes of the same version.** If a release candidate of this version was already published, - start from its notes and add to them: - `gh release list -R ` and `gh release view -R `. - Tags look like `rc-25.1.0-02` (release candidate) and `25.1.0` (final). -2. **Merged pull requests in the milestone.** This is the main source: - ``` - gh api 'repos//milestones?state=all&per_page=100' -q '.[] | select(.title == "") | .number' - gh pr list -R --search 'milestone:"" is:merged' -L 500 --json number,title,body,author,labels - ``` -3. **Commits since the previous tag**, to find changes whose pull request is missing in the milestone: - `git log --oneline ..HEAD`. - -Pull requests titled `[stable-…] …` from `backportbot` are backports. Their body starts with -`Backport of #`. Treat a backport and its original as one change, and use the author of the -original pull request. - -## 3. Select what to mention - -Only mention what a user of the app notices. Leave out: - -- translation and synced file updates (`fix(l10n)`, label `sync`) -- dependency updates, CI, tests, build and release automation -- refactorings and code cleanup without visible effect - -Read the pull request body when the title is not clear enough to describe the change for users. - -## 4. Credit contributors - -Credit authors who are neither members of the Nextcloud GitHub organization nor bots, as `(@login)` -after the item. Several minor fixes by such contributors can be combined into one item, e.g. -`- Various bugs (@login1, @login2)`. - -- Organization membership: `gh api orgs/nextcloud/members/ --silent` succeeds for members - (HTTP 204) and fails for non-members (HTTP 404). -- Bots: logins ending in `[bot]` or starting with `app/`, and accounts like `backportbot`, - `nextcloud-bot`, `renovate` and `dependabot`. - -## 5. Write the file - -Format (sections without items are left out): - -``` -## Added -- Refreshing of conversation list -- Improved bluetooth handling (@login) - -## Fixed -- Notifications sometimes do not show up when using Android 11 or lower -- Various bugs (@login1, @login2) - -Minimum: NC 17 Server, Android 8.0 Oreo - -For a full list, please see https://github.com//milestone/?closed=1 -``` - -- Items are short, user facing English, without issue or pull request numbers and without commit prefixes - like `fix:`. -- Take the `Minimum` line from the previous release notes. Check the Android version against `minSdk` in - `app/build.gradle.kts` and update it if it changed. -- Use the milestone number found in step 2 for the link. - -## 6. Keep it within 500 characters - -Google Play does not accept release notes longer than 500 characters. The limit applies to the whole -file, including the `Minimum` line and the link. Check with `wc -m < `. - -If it is too long, keep the most important additions and fixes, and combine the remaining minor fixes -into `- Various bugs` (keeping the credits) or leave them out. The milestone link lists everything. - -Do not commit the file. Show it to the person doing the release, who reviews it and commits it together -with the version change by running `bundle exec fastlane commitVersion`. From 7b5a8a4b97613dfb903165c50dcf6d2843cc4c1b Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 15:34:19 +0100 Subject: [PATCH 08/11] chore(fastlane): do not take git warnings for uncommitted changes ensure_git_status_clean reads stdout and stderr of git status together, so a warning like "untracked cache is disabled on this system or location" stopped releasePhase1 and releasePhase2 although the working tree was clean. The release lanes now check only the changes git status lists, and show warnings without failing. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 97bdefe..9eccfdf 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -150,7 +150,7 @@ platform :android do desc "Release phase 1: Run tests and build app" lane :releasePhase1 do warnAboutUnusedSecrets() - ensure_git_status_clean(show_uncommitted_changes: true) + ensureCleanWorkingTree() askForSigningPasswords() builtCommit = last_git_commit[:commit_hash] # may hold signing passwords of releases before signed builds were run without configuration cache @@ -186,7 +186,7 @@ platform :android do private_lane :releasePhase2Steps do |options| dryRun = options[:dryRun] warnAboutUnusedSecrets() - ensure_git_status_clean(show_uncommitted_changes: true) + ensureCleanWorkingTree() wouldFail = ensurePushed(dryRun: dryRun) checkArtifactsCommit() versionInfo = getVersionInfo() @@ -725,6 +725,21 @@ platform :android do { status: response.code.to_i, scopes: response["X-OAuth-Scopes"], json: json } end + desc "Fail if the working tree has changes or untracked files. Unlike ensure_git_status_clean, " + + "warnings git prints on stderr (e.g. about the untracked cache) are not taken for changes." + private_lane :ensureCleanWorkingTree do + changes, warnings, status = Open3.capture3("git", "status", "--porcelain") + if !status.success? + UI.user_error!("git status failed: #{warnings.strip}") + end + if !changes.strip.empty? + UI.user_error!("Working tree is not clean, commit, stash or discard these changes first:\n#{changes.rstrip}") + end + if !warnings.strip.empty? + UI.important("git status warned: #{warnings.strip}") + end + end + desc "Check that all local commits are pushed to the upstream branch, ask if the upstream branch has newer commits. " + "Returns the problems a dry run only warns about." private_lane :ensurePushed do |options| From d316ab895ce7cb7b730831c473776d1149729414 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 15:51:41 +0100 Subject: [PATCH 09/11] chore(fastlane): push the release branch in releasePhase2 instead of commitVersion commitVersion pushed the version change before releasePhase1 had run the tests and built the release, so a failing release left a version bump on the shared branch, and testing the lanes changed a real branch. commitVersion now only commits, and releasePhase1 stays local. releasePhase2 fetches and checks the branch before anything is published: it stops if the branch has diverged from its upstream branch, asks if the upstream branch has newer commits, and shows what it will push in the confirmation. It pushes the branch before the tag, or with a new upstream branch if there is none. releasePhase2DryRun shows what would be pushed. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 98 ++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 9eccfdf..508e795 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -106,7 +106,7 @@ platform :android do printAtExit(title: "Version changed", lines: summary) end - desc "Preparation phase 2: Commit version change and changelog + ask to push" + desc "Preparation phase 2: Commit version change and changelog, releasePhase2 pushes them" lane :commitVersion do versionInfo = getVersionInfo() checkReleasable(parseVersionCode(versionInfo)) @@ -128,23 +128,11 @@ platform :android do sh("git", "add", "--", gradleFile, changelogFile) sh("git", "commit", "--signoff", "-m", message, "--", gradleFile, changelogFile) - branch = sh("git", "symbolic-ref", "--short", "HEAD", log: false).strip - remote, remoteStatus = Open3.capture2("git", "config", "branch.#{branch}.remote") - merge, mergeStatus = Open3.capture2("git", "config", "branch.#{branch}.merge") - if remoteStatus.success? && mergeStatus.success? - target = [remote.strip, "HEAD:#{merge.strip}"] - else - target = ["--set-upstream", "origin", "HEAD"] - end - summary = ["Committed: #{last_git_commit[:abbreviated_commit_hash]} #{message}"] - if UI.confirm("Push branch #{branch} now (git push #{target.join(" ")})?") - sh("git", "push", *target) - summary << "Pushed branch #{branch}" - else - summary << "Not pushed. Push it before releasePhase2: git push #{target.join(" ")}" - end - summary << "Next: run releasePhase1" - printAtExit(title: "Version committed", lines: summary) + printAtExit(title: "Version committed", lines: [ + "Committed: #{last_git_commit[:abbreviated_commit_hash]} #{message}", + "Not pushed: releasePhase2 pushes the branch after releasePhase1 has tested and built it", + "Next: run releasePhase1", + ]) end desc "Release phase 1: Run tests and build app" @@ -187,7 +175,7 @@ platform :android do dryRun = options[:dryRun] warnAboutUnusedSecrets() ensureCleanWorkingTree() - wouldFail = ensurePushed(dryRun: dryRun) + push = checkBranchPushable(dryRun: dryRun) checkArtifactsCommit() versionInfo = getVersionInfo() versionComponents = parseVersionCode(versionInfo) @@ -198,18 +186,19 @@ platform :android do isPrerelease = isPrerelease(versionComponents) huaweiCredentials = uploadsToHuawei(isPrerelease: isPrerelease) ? askForHuaweiCredentials() : nil tagName = getTagName(versionComponents) - preReleaseChecks(versionInfo: versionInfo, tagName: tagName, type: versionComponents["type"], track: storeTrack, isPrerelease: isPrerelease, dryRun: dryRun) + preReleaseChecks(versionInfo: versionInfo, tagName: tagName, type: versionComponents["type"], track: storeTrack, isPrerelease: isPrerelease, push: push, dryRun: dryRun) checkArtifactsExist(versionCode: versionInfo["versionCode"]) repoSpecificChecks(isPrerelease: isPrerelease) # needs to be overwritten in apps summary = [ + pushBranch(push: push, dryRun: dryRun), tag(name: tagName, dryRun: dryRun), createGithubRelease(token: githubToken, name: versionInfo["versionName"], tag: tagName, versionCode: versionInfo["versionCode"], isPrerelease: isPrerelease, dryRun: dryRun), uploadToPlayStore(track: storeTrack, versionCode: versionInfo["versionCode"], dryRun: dryRun), uploadToHuawei(versionCode: versionInfo["versionCode"], credentials: huaweiCredentials, dryRun: dryRun), ].compact if dryRun - summary += wouldFail.map { |message| "Would fail in releasePhase2: #{message}" } - summary << (wouldFail.empty? ? "Next: run releasePhase2" : "Next: fix the above, then run releasePhase2") + summary += push[:problems].map { |message| "Would fail in releasePhase2: #{message}" } + summary << (push[:problems].empty? ? "Next: run releasePhase2" : "Next: fix the above, then run releasePhase2") printAtExit(title: "Dry run of #{versionInfo["versionName"]} finished, nothing was published", lines: summary) else summary << "Next: check the GitHub release and the release in the Google Play Console" @@ -740,32 +729,62 @@ platform :android do end end - desc "Check that all local commits are pushed to the upstream branch, ask if the upstream branch has newer commits. " + - "Returns the problems a dry run only warns about." - private_lane :ensurePushed do |options| - sh("git fetch --quiet") - upstream, status = Open3.capture2("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}") + desc "Check that the branch can be pushed before anything is published: it must not have diverged from its upstream " + + "branch, and if the upstream branch has newer commits, ask. Returns what pushBranch pushes, and the problems a dry run only warns about." + private_lane :checkBranchPushable do |options| + branch, status = Open3.capture2("git", "symbolic-ref", "--quiet", "--short", "HEAD") if !status.success? - message = "Current branch has no upstream branch" - dryRunOr(dryRun: options[:dryRun], message: message) - next [message] + UI.user_error!("HEAD is detached, check out the release branch first") + end + branch = branch.strip + remote, remoteStatus = Open3.capture2("git", "config", "branch.#{branch}.remote") + merge, mergeStatus = Open3.capture2("git", "config", "branch.#{branch}.merge") + if !remoteStatus.success? || !mergeStatus.success? + next { + target: ["--set-upstream", "origin", "HEAD"], + description: "branch #{branch} to origin, as new upstream branch", + problems: [], + } end + remote = remote.strip + merge = merge.strip + sh("git", "fetch", "--quiet", remote) + upstream = sh("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}", log: false).strip + unpushed = sh("git", "rev-list", "--count", "#{upstream}..HEAD", log: false).strip.to_i + missing = sh("git", "rev-list", "--count", "HEAD..#{upstream}", log: false).strip.to_i problems = [] - upstream = upstream.strip - unpushed = sh("git rev-list --count #{upstream}..HEAD", log: false).strip.to_i - if unpushed > 0 - problems << "#{unpushed} commit(s) not pushed to #{upstream}" + if unpushed > 0 && missing > 0 + problems << "#{branch} and #{upstream} have diverged (#{unpushed} local, #{missing} upstream commit(s)), " + + "rebase onto or reset to #{upstream} first" dryRunOr(dryRun: options[:dryRun], message: problems.last) - end - missing = sh("git rev-list --count HEAD..#{upstream}", log: false).strip.to_i - if missing > 0 + elsif missing > 0 promptYesNo( title: "#{upstream} has newer commits", text: "#{missing} commit(s) on #{upstream} are not in the local branch and will not be part of this release.", question: "Release without these commits?" ) end - problems + if !problems.empty? + # only reached in a dry run, the push would be rejected + next { target: nil, description: "nothing, #{branch} has diverged from #{upstream}", problems: problems } + end + { + target: unpushed > 0 ? [remote, "HEAD:#{merge}"] : nil, + description: unpushed > 0 ? "#{unpushed} commit(s) of #{branch} to #{upstream}" : "nothing, #{branch} is pushed", + problems: problems, + } + end + + desc "Push the release branch, as checked by checkBranchPushable, returns a summary" + private_lane :pushBranch do |options| + push = options[:push] + next nil if push[:target].nil? + if options[:dryRun] + UI.important("[dry run] would push #{push[:description]}: git push #{push[:target].join(" ")}") + next "Branch: would push #{push[:description]}" + end + sh("git", "push", *push[:target]) + "Branch: pushed #{push[:description]}" end desc "Fail with the message, or only warn about it in a dry run" @@ -849,6 +868,7 @@ platform :android do text = "Version name: #{versionInfo["versionName"]}\n" + "Version code: #{versionInfo["versionCode"]}\n" + "Current branch: #{currentBranch}\n" + + "Push: #{options[:push][:description]}\n" + "Version type: #{options[:type]}\n" + "Tag: #{tagName}\n" + "Track: #{options[:track]}\n" + @@ -858,7 +878,7 @@ platform :android do question: "Run the dry run for this release?") else promptYesNo(title: "Check the release, it is published after this question", text: text, - question: "Publish #{versionInfo["versionName"]} now (tag, GitHub release, store uploads)?") + question: "Publish #{versionInfo["versionName"]} now (push, tag, GitHub release, store uploads)?") end end From 82a152681bd6bcd691dd5e3b178f76fb24d7d631 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 17:39:53 +0100 Subject: [PATCH 10/11] chore: use the skill format of the Files app for suggest-release-notes The license moves from an HTML comment into the frontmatter, the description becomes a folded block starting with "Use when", and the frontmatter gets metadata with author and version, as in the skills of nextcloud/android. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/skills/suggest-release-notes/SKILL.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/config/skills/suggest-release-notes/SKILL.md b/config/skills/suggest-release-notes/SKILL.md index 454c24a..2b4b07b 100644 --- a/config/skills/suggest-release-notes/SKILL.md +++ b/config/skills/suggest-release-notes/SKILL.md @@ -1,11 +1,19 @@ --- name: suggest-release-notes -description: Fill the release changelog file that fastlane incrementVersion created, named after the version code, for a release candidate or final release. Use when asked to write release notes or a changelog for a release. +description: > + Use when asked to write release notes or a changelog for a release candidate + or final release. Fills the changelog file that fastlane incrementVersion + created, named after the version code, from the merged pull requests of the + milestone, crediting external contributors and keeping it within the 500 + character limit of Google Play. +license: GPL-3.0-or-later +SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +SPDX-License-Identifier: GPL-3.0-or-later +metadata: + author: Nextcloud Android + version: "1.0.0" --- - + # Suggest release notes `bundle exec fastlane incrementVersion` creates an empty changelog file named From 80ebe0ad8e5ae5b1f3ffd411fb9723f8ff01eabf Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Nov 2026 17:52:40 +0100 Subject: [PATCH 11/11] chore(fastlane): rename release lanes to build, release and releaseDryRun I renamed the lanes and descriptions because it gets confusing to have descriptions like "release phase 2" but it needs a different number as input, like "4". Happened to me several times that i entered "2" instead. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- config/fastlane/common.Fastfile | 42 ++++++++++---------- config/skills/suggest-release-notes/SKILL.md | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/config/fastlane/common.Fastfile b/config/fastlane/common.Fastfile index 508e795..aed14b9 100644 --- a/config/fastlane/common.Fastfile +++ b/config/fastlane/common.Fastfile @@ -73,7 +73,7 @@ platform :android do # Without type, the resulting versions of all types are shown to choose from. # rc or final after a final release asks for the next hotfix or minor version, as a released version # cannot get another rc or final. - desc "Preparation phase 1: Increment version code and version name" + desc "Increment version code and version name" lane :incrementVersion do |options| versionInfo = getVersionInfo() versionComponents = parseVersionCode(versionInfo) @@ -106,7 +106,7 @@ platform :android do printAtExit(title: "Version changed", lines: summary) end - desc "Preparation phase 2: Commit version change and changelog, releasePhase2 pushes them" + desc "Commit version change and changelog (push is done later in release lane)" lane :commitVersion do versionInfo = getVersionInfo() checkReleasable(parseVersionCode(versionInfo)) @@ -130,13 +130,13 @@ platform :android do printAtExit(title: "Version committed", lines: [ "Committed: #{last_git_commit[:abbreviated_commit_hash]} #{message}", - "Not pushed: releasePhase2 pushes the branch after releasePhase1 has tested and built it", - "Next: run releasePhase1", + "Not pushed: the release lane pushes the branch after the build lane has tested and built it", + "Next: run build", ]) end - desc "Release phase 1: Run tests and build app" - lane :releasePhase1 do + desc "Run tests and build app" + lane :build do warnAboutUnusedSecrets() ensureCleanWorkingTree() askForSigningPasswords() @@ -152,26 +152,26 @@ platform :android do apks = buildRelease(versionCode: versionInfo["versionCode"]) File.write("../#{BUILT_COMMIT_PATH}", builtCommit) - printAtExit(title: "Release phase 1 finished", lines: [ + printAtExit(title: "Build finished", lines: [ "Version #{versionInfo["versionName"]} (#{versionInfo["versionCode"]}), built from commit #{builtCommit}", "App bundle for Google Play: #{File.expand_path("../#{bundlePath(versionCode: versionInfo["versionCode"])}")}", *apks.map { |apk| "APK: #{File.expand_path(apk[:path])} (signed by #{apk[:signer]})" }, - "Next: test the APKs, then run releasePhase2DryRun and releasePhase2", - "If you find a bug: fix it, commit, and run releasePhase1 again", + "Next: test the APKs, then run releaseDryRun and release", + "If you find a bug: fix it, commit, and run build again", ]) end - desc "Release phase 2: checks, tag, create GH release, upload to appstores" - lane :releasePhase2 do - releasePhase2Steps(dryRun: false) + desc "Checks, tag, create GH release, upload to appstores" + lane :release do + releaseSteps(dryRun: false) end - desc "Release phase 2 dry run: run all checks, show what would be published" - lane :releasePhase2DryRun do - releasePhase2Steps(dryRun: true) + desc "Run all checks, show what would be published" + lane :releaseDryRun do + releaseSteps(dryRun: true) end - private_lane :releasePhase2Steps do |options| + private_lane :releaseSteps do |options| dryRun = options[:dryRun] warnAboutUnusedSecrets() ensureCleanWorkingTree() @@ -197,8 +197,8 @@ platform :android do uploadToHuawei(versionCode: versionInfo["versionCode"], credentials: huaweiCredentials, dryRun: dryRun), ].compact if dryRun - summary += push[:problems].map { |message| "Would fail in releasePhase2: #{message}" } - summary << (push[:problems].empty? ? "Next: run releasePhase2" : "Next: fix the above, then run releasePhase2") + summary += push[:problems].map { |message| "Would fail in release: #{message}" } + summary << (push[:problems].empty? ? "Next: run release" : "Next: fix the above, then run release") printAtExit(title: "Dry run of #{versionInfo["versionName"]} finished, nothing was published", lines: summary) else summary << "Next: check the GitHub release and the release in the Google Play Console" @@ -799,12 +799,12 @@ platform :android do desc "Check that the release artifacts were built from the current commit" private_lane :checkArtifactsCommit do if !File.exist?("../#{BUILT_COMMIT_PATH}") - UI.user_error!("#{BUILT_COMMIT_PATH} not found, run releasePhase1 first") + UI.user_error!("#{BUILT_COMMIT_PATH} not found, run build first") end builtCommit = File.read("../#{BUILT_COMMIT_PATH}").strip headCommit = last_git_commit[:commit_hash] if builtCommit != headCommit - UI.user_error!("Artifacts were built from #{builtCommit}, but HEAD is #{headCommit}. Run releasePhase1 again.") + UI.user_error!("Artifacts were built from #{builtCommit}, but HEAD is #{headCommit}. Run build again.") end end @@ -856,7 +856,7 @@ platform :android do private_lane :checkArtifactsExist do |options| bundle = bundlePath(versionCode: options[:versionCode]) if !File.exist?("../#{bundle}") - UI.user_error!("Bundle not found at #{bundle}, run releasePhase1 first") + UI.user_error!("Bundle not found at #{bundle}, run build first") end end diff --git a/config/skills/suggest-release-notes/SKILL.md b/config/skills/suggest-release-notes/SKILL.md index 2b4b07b..894cd16 100644 --- a/config/skills/suggest-release-notes/SKILL.md +++ b/config/skills/suggest-release-notes/SKILL.md @@ -20,7 +20,7 @@ metadata: after the version code, usually `fastlane/metadata/android/en-US/changelogs/.txt`, and prints its path. Its content is used as release notes on Google Play and as description -of the GitHub release. `releasePhase2` refuses to release if the file is empty +of the GitHub release. `release` refuses to release if the file is empty or longer than 500 characters. These instructions describe how to fill that file. They are written so that an