BearND has uploaded a new change for review. https://gerrit.wikimedia.org/r/203156
Change subject: WIP: Change version number format to include versionCode as subminor number ...................................................................... WIP: Change version number format to include versionCode as subminor number I'm proposing to include the versionCode into the version name format. This will make version names more distinct, albeit for now there's a bit of redundancy. Example: 2.0-beta-2015-04-09 becomes 2.0.100-beta-2015-04-09 I think eventually we could even consider getting rid of the date portion but I'll keep it for now to make the transition smoother. Had to also change the make-release.py script since it generated the version name itself based on the date the command was run. I'd like to get away from that and use the apk file to derive the version name. It uses the versionCode from the build.gradle file. To be able to extract the versionName from the apk it needs to know the location of the aapt tool, which is under $ANDROID_HOME/build-tools/<build_tools_version>. Again, the build_tools_version is retrieved from the build.gradle file. Bug: T95584 Change-Id: Icb6a076181bb1e696be5b646a6891c442d4d6d69 --- M scripts/make-release.py M wikipedia/build.gradle 2 files changed, 104 insertions(+), 50 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/56/203156/1 diff --git a/scripts/make-release.py b/scripts/make-release.py index 3fc6e88..9ed30a3 100755 --- a/scripts/make-release.py +++ b/scripts/make-release.py @@ -26,19 +26,22 @@ git log --pretty=format:"%h | %cr | %s" --abbrev-commit --no-merges `git tag -l r/*|tail -1`.. 9) Upload prod apk to store, releasesprod apk to releases.mediawiki.org -Requires the python module 'sh' to run. Ensure you have a clean working -directory before running as well. +Requires the python module 'sh' and the environment variable ANDROID_HOME to run. +Ensure you have a clean working directory before running as well. + +See also https://www.mediawiki.org/wiki/Wikimedia_Apps/Team/Release_process """ +import argparse +import glob +import os +import re import sh import subprocess -import os -import time -import argparse import sys PATH_PREFIX = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) GRADLEW = './gradlew' - +VERSION_START = '2.0' def p(*path_fragments): """ @@ -48,34 +51,25 @@ return os.path.join(PATH_PREFIX, *path_fragments) -def get_release_name(target): - """ - Returns name release, based on target (in release name) and current date. - This should be kept in sync with the versionNames of the various flavors - in build.gradle. - """ - return '2.0-%s-%s' % (target, time.strftime('%Y-%m-%d')) - - -def get_git_tag_name(target): +def get_git_tag_name(target, version_name): """ Returns name used for creating the tag """ - return target + '/' + get_release_name(target) + return target + '/' + version_name -def git_tag(target): +def git_tag(target, version_name): """ Creates an annotated git tag for this release """ - sh.git.tag('-a', get_git_tag_name(target), '-m', target) + sh.git.tag('-a', get_git_tag_name(target, version_name), '-m', target) -def push_to_gerrit(target): +def push_to_gerrit(target, version_name): """ Pushes the git tag to gerrit """ - tag_name = get_git_tag_name(target) + tag_name = get_git_tag_name(target, version_name) print('pushing tag ' + tag_name) sh.git.push('gerrit', tag_name) @@ -93,28 +87,83 @@ subprocess.call(args) -def copy_artifacts(flavor, target): +def copy_artifacts(flavor): folder_path = 'releases' sh.mkdir("-p", folder_path) - copy_apk(flavor, target) - copy_proguard_mapping(flavor, target) + version_name = get_version_name_from_apk(get_original_apk_file_name(flavor)) + copy_apk(flavor, version_name) + copy_proguard_mapping(flavor, version_name) -def copy_apk(flavor, target): +def get_original_apk_file_name(flavor): + return 'wikipedia/build/outputs/apk/wikipedia-%s-release.apk' % flavor + + +def get_android_home(): + android_home = os.environ['ANDROID_HOME'] + if android_home: + return android_home + else: + sys.exit('$ANDROID_HOME not set') + + +def grep_from_build_file(property_name, regex): + build_gradle_file_name = 'wikipedia/build.gradle' + with open(build_gradle_file_name, "r") as build_file: + for line in build_file: + found = re.search(regex, line) + if found: + res = found.groups()[0] + return res + sys.exit("Could not find %s in %s" % (property_name, build_gradle_file_name)) + + +def get_build_tools_version_from_build_file(): + return grep_from_build_file('buildToolsVersion', r'buildToolsVersion\s+\'(\S+)\'') + + +def get_version_code_from_build_file(): + return grep_from_build_file('versionCode', r'versionCode\s+(\S+)') + + +def get_version_name_from_apk(apk_file): + aapt = '%s/build-tools/%s/aapt' % (get_android_home(), get_build_tools_version_from_build_file()) + process = subprocess.check_output([aapt, 'dump', 'badging', apk_file]) + found = re.search(r'versionName=\'(\S+)\'', process) + if found: + apk_version_name = found.groups()[0] + return apk_version_name + else: + sys.exit("Could not get version name from apk " + apk_file) + + +def copy_apk(flavor, version_name): folder_path = 'releases' sh.mkdir("-p", folder_path) - output_file = '%s/wikipedia-%s.apk' % (folder_path, get_release_name(target)) - sh.cp('wikipedia/build/outputs/apk/wikipedia-%s-release.apk' % flavor, output_file) + output_file = '%s/wikipedia-%s.apk' % (folder_path, version_name) + sh.cp(get_original_apk_file_name(flavor), output_file) print ' apk: %s' % output_file -def copy_proguard_mapping(flavor, target): +def copy_proguard_mapping(flavor, version_name): folder_path = 'releases' sh.mkdir("-p", folder_path) - output_file = '%s/wikipedia-%s.mapping.tar.gz' % (folder_path, get_release_name(target)) + output_file = '%s/wikipedia-%s.mapping.tar.gz' % (folder_path, version_name) input_file = 'wikipedia/build/outputs/mapping/%s/release/mapping.txt' % flavor sh.tar('czf', output_file, input_file) print ' proguard mapping: %s' % output_file + + +def find_output_apk_for(label, version_code): + folder_path = 'releases' + file_pattern = '%s/wikipedia-%s.%s-%s-*.apk' % (folder_path, VERSION_START, version_code, label) + apk_files = glob.glob(file_pattern) + if len(apk_files) == 1: + return apk_files[0] + elif len(apk_files) == 0: + sys.exit("Did not find apk files for %s" % file_pattern) + else: + sys.exit("Found too many(%d) files for %s" % (len(apk_files), file_pattern)) def main(): @@ -123,9 +172,6 @@ group.add_argument('--beta', help='Step 1: Google Play Beta. git checkout BUMPTAG first!', action='store_true') - # group.add_argument('--alpha', - # help='Do not use manually, only for the automated build script', - # action='store_true') group.add_argument('--prod', help='Step 1: Google Play stable.', action='store_true') @@ -165,14 +211,20 @@ sys.exit(-1) if args.push: + if custom_channel is 'ignore': + label = flavors[0] + else: + label = custom_channel + apk_file = find_output_apk_for(label, get_version_code_from_build_file()) + version_name = get_version_name_from_apk(apk_file) for target in targets: - git_tag(target) - push_to_gerrit(target) + git_tag(target, version_name) + push_to_gerrit(target, version_name) else: make_release(flavors, custom_channel, custom_app) - copy_artifacts(flavors[0], targets[0]) + copy_artifacts(flavors[0]) if flavors[0] == 'prod': - copy_artifacts(flavors[1], flavors[1]) + copy_artifacts(flavors[1]) print('Please test the APK. After that, run w/ --push flag, and release the tested APK.') print('A useful command for collecting the release notes:') print('git log --pretty=format:"%h | %cr | %s" --abbrev-commit --no-merges ' + diff --git a/wikipedia/build.gradle b/wikipedia/build.gradle index 84407e1..30acc1a 100644 --- a/wikipedia/build.gradle +++ b/wikipedia/build.gradle @@ -2,7 +2,15 @@ apply plugin: 'com.android.application' apply from: '../config/quality.gradle' -def versionStart = '2.0' +def getDate() { + def date = new Date() + def formattedDate = date.format('yyyy-MM-dd') + return formattedDate +} + +def computeVersionName(label) { + return "2.0.${android.defaultConfig.versionCode}-${label}-${date}" +} android { compileSdkVersion 22 @@ -26,27 +34,27 @@ } productFlavors { dev { - versionName "${versionStart}-dev-${date}" + versionName computeVersionName("dev") } prod { - versionName "${versionStart}-r-${date}" + versionName computeVersionName("r") } releasesprod { - versionName "${versionStart}-releasesprod-${date}" + versionName computeVersionName("releasesprod") } alpha { - versionName "${versionStart}-alpha-${date}" + versionName computeVersionName("alpha") applicationId 'org.wikipedia.alpha' } beta { - versionName "${versionStart}-beta-${date}" + versionName computeVersionName("beta") applicationId 'org.wikipedia.beta' } amazon { - versionName "${versionStart}-amazon-${date}" + versionName computeVersionName("amazon") } custom { - versionName "${versionStart}-${customChannel}-${date}" + versionName computeVersionName(customChannel) applicationId getProperty('customApplicationId') // next line is for injecting a custom channel value into the custom/AndroidManifest.xml manifestPlaceholders = [customChannel:getProperty('customChannel').toString()] @@ -81,12 +89,6 @@ disable 'MissingTranslation' warning 'NewApi' // until https://code.google.com/p/android/issues/detail?id=137195 is released } -} - -def getDate() { - def date = new Date() - def formattedDate = date.format('yyyy-MM-dd') - return formattedDate } dependencies { -- To view, visit https://gerrit.wikimedia.org/r/203156 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icb6a076181bb1e696be5b646a6891c442d4d6d69 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: BearND <bsitzm...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits