Dbrant has submitted this change and it was merged.

Change subject: Add custom channel and package
......................................................................


Add custom channel and package

Add ability to specify a custom channel and package name (app id)
for channel partners.
Added a new 'custom' flavor that can take a custom
channel and applicationId.
Removed obsolete make-beta script.

Change-Id: Ia57edb7aa06427a2ce78ddeabf5da6b20e9d7ad7
---
D scripts/make-beta.py
M scripts/make-release.py
M wikipedia/build.gradle
A wikipedia/gradle.properties
A wikipedia/src/custom/AndroidManifest.xml
5 files changed, 42 insertions(+), 201 deletions(-)

Approvals:
  Dbrant: Looks good to me, approved



diff --git a/scripts/make-beta.py b/scripts/make-beta.py
deleted file mode 100644
index 76723d2..0000000
--- a/scripts/make-beta.py
+++ /dev/null
@@ -1,184 +0,0 @@
-#!/usr/bin/env python
-"""
-Script that helps move the app from org.wikipedia to org.wikipedia.beta
-
-Does the following things in two steps:
-Step 1: (run without arguments):
-    - Creates an annotated tag called 'releases/versionName'
-    - Move package from org.wikipedia to org.wikipedia.beta
-    - Move folders to accommodate new packages
-    - Replace all instances of string 'org.wikipedia' to 'org.wikipedia.beta'
-    - Setup app to use beta icon
-    - Bump versionCode and versionName
-    - Make a new commit on a new branch
-Step 2: (run with --push argument):
-    - Pushes the git tag created in step 1 to the gerrit remote
-
-Requires the python module 'sh' to run. Ensure you have a clean working
-directory before running as well.
-"""
-import sh
-import os
-import re
-import time
-import argparse
-
-PATH_PREFIX = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
-
-
-def p(*path_fragments):
-    """
-    Combine the path fragments with PATH_PREFIX as a base, and return
-    the new full path
-    """
-    return os.path.join(PATH_PREFIX, *path_fragments)
-
-
-def get_beta_name():
-    """
-    Returns name used for beta naming, based on current date
-    """
-    return '2.0-beta-%s' % time.strftime('%Y-%m-%d')
-
-
-def get_git_tag_name():
-    """
-    Returns name used for creating the tag
-    """
-    return 'releases/' + get_beta_name()
-
-
-def git_tag():
-    """
-    Creates an annotated git tag for this release
-    """
-    sh.git.tag('-a', get_git_tag_name(), '-m', 'beta')
-
-
-def push_git_tag():
-    """
-    Pushes the git tag to gerrit
-    """
-    print('pushing ' + get_git_tag_name())
-    sh.git.push('gerrit', get_git_tag_name())
-
-
-def git_mv_dir(dir_path):
-    """
-    Performs git mv from main package to a .beta subpackage
-    """
-    # Need to do the move in two forms, since we can not
-    # move a directory to be its own subdirectory in one step
-    sh.git.mv(
-        p(dir_path, 'src/main/java/org/wikipedia'),
-        p(dir_path, 'src/main/java/org/beta')
-    )
-
-    sh.mkdir('-p', p(dir_path, 'src/main/java/org/wikipedia'))
-
-    sh.git.mv(
-        p(dir_path, 'src/main/java/org/beta'),
-        p(dir_path, 'src/main/java/org/wikipedia')
-    )
-
-
-def transform_file(file_path, *funcs):
-    """
-    Transforms the file given in file_path by passing it
-    serially through all the functions in *func and then
-    writing it back out to file_path
-    """
-    f = open(file_path, 'r+')
-    data = f.read()
-    f.seek(0)
-    for func in funcs:
-        data = func(data)
-    f.write(data)
-    f.close()
-    print file_path
-
-
-def replace_packagenames(data):
-    """
-    Utility function to replace all non-beta package names
-    with beta package names
-    """
-    return data.replace('org.wikipedia', 'org.wikipedia.beta')
-
-
-def change_icon(data):
-    """
-    Utility function to replace launcher icon with
-    beta launcher icon
-    """
-    return data.replace("launcher", "launcher_beta")
-
-
-def change_label(data):
-    """
-    Utility function to replace app label with beta app name
-    """
-    return data.replace('@string/app_name', '@string/app_name_beta')
-
-
-versionCode_regex = re.compile(r'android:versionCode="(\d+)"', re.MULTILINE)
-versionName_regex = re.compile(r'android:versionName="([^"]+)"', re.MULTILINE)
-
-
-def set_version(data):
-    """
-    Utility function to set new versionCode and versionName
-    """
-    new_version_name = get_beta_name()
-    version_code = int(versionCode_regex.search(data).groups()[0])
-
-    data = versionCode_regex.sub(
-        'android:versionCode="%d"' % (version_code + 1),
-        data
-    )
-    data = versionName_regex.sub(
-        'android:versionName="%s"' % new_version_name,
-        data
-    )
-    return data
-
-
-def transform_project(dir_path):
-    """
-    Performs all necessary transformations for a particular project
-    """
-    git_mv_dir(dir_path)
-    for root, dirs, files in os.walk(p(dir_path, 
'src/main/java/org/wikipedia/beta')):
-        for file_name in files:
-            file_path = os.path.join(root, file_name)
-            transform_file(file_path, replace_packagenames)
-
-    for root, dirs, files in os.walk(p(dir_path, 'res')):
-        for file_name in files:
-            if file_name.endswith('.xml'):
-                file_path = os.path.join(root, file_name)
-                transform_file(file_path, replace_packagenames)
-
-    transform_file(p(dir_path, 'AndroidManifest.xml'), replace_packagenames, 
set_version, change_icon, change_label)
-
-
-def make_release():
-    git_tag()
-    sh.git.checkout('-b', 'betas/%s' % get_beta_name())
-    transform_project('wikipedia')
-    transform_project('wikipedia-it')
-    sh.cd(PATH_PREFIX)
-    sh.git.add('-u')
-    sh.git.commit('-m', 'Make release %s' % get_beta_name())
-
-
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--push', help='step 2: push git tag created in step 1 
to gerrit remote', action='store_true')
-    args = parser.parse_args()
-    if args.push:
-        # step 2:
-        push_git_tag()
-    else:
-        # step 1:
-        make_release()
diff --git a/scripts/make-release.py b/scripts/make-release.py
index 551373b..eb6553f 100755
--- a/scripts/make-release.py
+++ b/scripts/make-release.py
@@ -79,10 +79,10 @@
     sh.git.push('gerrit', tag_name)
 
 
-def make_release(flavors):
+def make_release(flavors, custom_channel, custom_app):
     sh.cd(PATH_PREFIX)
     # ./gradlew -q assembleDevDebug
-    args = [GRADLEW, '-q', 'clean']
+    args = [GRADLEW, '-q', 'clean', '-PcustomChannel=' + custom_channel, 
'-PcustomApplicationId=' + custom_app]
     tasks = ['assemble{0}Release'.format(flavor.title()) for flavor in flavors]
     args += tasks
     subprocess.call(args)
@@ -106,22 +106,21 @@
     #                    help='Do not use manually, only for the automated 
build script',
     #                    action='store_true')
     group.add_argument('--prod',
-                       help='Step 1: Google Play stable. git checkout BUMPTAG 
first!',
+                       help='Step 1: Google Play stable.',
                        action='store_true')
-    # group.add_argument('--releasesprod',
-    #                    help='Step 1: releasesdot stable. git checkout 
BUMPTAG first!',
-    #                    action='store_true')
     group.add_argument('--amazon',
-                       help='Step 1: Amazon stable release. git checkout 
BUMPTAG first!',
+                       help='Step 1: Amazon stable release.',
                        action='store_true')
-    # group.add_argument('--channel',
-    #                    help='Step 1: Alphabetic versionName&channel. '
-    #                         'Usually, git checkout BUMPTAG first. OEMs w/ 
Play')
-    # group.add_argument('--custompackage',
-    #                    help='Step 1: Alphabetic versionName&channel&package; 
OEMs wout/ Play.')
-    parser.add_argument('--push', help='Step 2: push git tag created in step 1 
to gerrit remote.',
+    group.add_argument('--channel',
+                       help='Step 1: Custom versionName&channel. OEMs w/ Play')
+    group.add_argument('--app',
+                       help='Step 1: Custom versionName&channel&applicationId '
+                            '(aka. package name). OEMs wout/ Play.')
+    parser.add_argument('--push', help='Step 2: create&push git tag to gerrit 
remote.',
                         action='store_true')
     args = parser.parse_args()
+    custom_channel = 'ignore'
+    custom_app = 'org.wikipedia'
     if args.beta:
         flavors = ['beta']
         targets = flavors
@@ -131,9 +130,15 @@
     elif args.amazon:
         flavors = ['amazon']
         targets = flavors
-    # elif args.channel:
-    #     flavors = [args.channel]
-    #     targets = flavors
+    elif args.channel:
+        flavors = ['custom']
+        targets = [args.channel]
+        custom_channel = args.channel
+    elif args.app:
+        flavors = ['custom']
+        targets = [args.app]
+        custom_channel = args.app
+        custom_app = 'org.wikipedia.' + args.app
     else:
         print('Error. Please specify --beta, --prod, or --amazon')
         sys.exit(-1)
@@ -143,7 +148,7 @@
             git_tag(target)
             push_to_gerrit(target)
     else:
-        make_release(flavors)
+        make_release(flavors, custom_channel, custom_app)
         copy_apk(flavors[0], targets[0])
         if flavors[0] == 'prod':
             copy_apk(flavors[1], flavors[1])
diff --git a/wikipedia/build.gradle b/wikipedia/build.gradle
index 790188f..ac6042d 100644
--- a/wikipedia/build.gradle
+++ b/wikipedia/build.gradle
@@ -43,6 +43,12 @@
         amazon {
             versionName "${versionStart}-amazon-${date}"
         }
+        custom {
+            versionName "${versionStart}-${customChannel}-${date}"
+            applicationId getProperty('customApplicationId')
+            // next line is for injecting a custom channel value into the 
custom/AndroidManifest.xml
+            manifestPlaceholders = 
[customChannel:getProperty('customChannel').toString()]
+        }
     }
     sourceSets {
         // Still using old Maven archetype based directory structure and
diff --git a/wikipedia/gradle.properties b/wikipedia/gradle.properties
new file mode 100644
index 0000000..d90ae5b
--- /dev/null
+++ b/wikipedia/gradle.properties
@@ -0,0 +1,3 @@
+# override on command line like this: -PcustomChannel=qpb 
-PcustomApplicationId=org.wikipedia.qpb
+customChannel=zzz
+customApplicationId=org.wikipedia.zzz
\ No newline at end of file
diff --git a/wikipedia/src/custom/AndroidManifest.xml 
b/wikipedia/src/custom/AndroidManifest.xml
new file mode 100644
index 0000000..e9ea8d5
--- /dev/null
+++ b/wikipedia/src/custom/AndroidManifest.xml
@@ -0,0 +1,11 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android";
+    xmlns:tools="http://schemas.android.com/tools";>
+
+    <application>
+        <meta-data
+            android:name="@string/preference_channel"
+            android:value="${customChannel}"
+            tools:replace="android:value" />
+    </application>
+
+</manifest>

-- 
To view, visit https://gerrit.wikimedia.org/r/169629
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia57edb7aa06427a2ce78ddeabf5da6b20e9d7ad7
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to