From 71650ffebd55877657bafd0392308734369488ba Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 7 Jun 2017 10:29:41 +0200 Subject: [PATCH] Add a option to deactivate APKs upload to android play store. APKs are pushed to a http accessible address. This is needed as first association of APKs to an application must be made manually. --- build_custom_app.py | 114 +++++++++++++++++++++++------------------ travis/deploy_apk.sh | 4 +- travis/make_release.sh | 4 +- 3 files changed, 69 insertions(+), 53 deletions(-) diff --git a/build_custom_app.py b/build_custom_app.py index 5a32462..52ba102 100755 --- a/build_custom_app.py +++ b/build_custom_app.py @@ -53,6 +53,7 @@ def parse_args(): advance = parser.add_argument_group('advance', "Some advanced options.") advance.add_argument('--extra-code', type=int, default=0) advance.add_argument('--check-certificate', default=True) + advance.add_argument('--no-android-upload', action='store_false', dest='android_upload') # Hidden options parser.add_argument('--step', default='launch', choices=['launch', 'publish'], help=argparse.SUPPRESS) @@ -163,7 +164,6 @@ def travis_launch_build(organisation, repository, options, zim_size): { 'PACKAGE_NAME': options.package_name}, { 'ZIM_URL': options.zim_url}, { 'EXTRA_CODE': options.extra_code}, - { 'BASE_VERSION': options.base_version}, { 'CONTENT_VERSION_CODE': gen_version_code(0, options.base_version)}, { 'VERSION': options.version}, { 'secure': ('u6MCvCQhAlvU0jNojLVatNXHr6AYj4rjU9CY9JcUUG9CKMsls1t3ERz' @@ -201,57 +201,68 @@ def travis_launch_build(organisation, repository, options, zim_size): data = { 'request': { - 'message' : tmpl_message.format(app=options.custom_app, zim=options.zim_url, uuid=uuid), - 'branch' : "custom_app", - 'config' : { - 'before_install' : [ - ( 'pip3 install pyOpenSSl google-api-python-client' - ' httplib2 apiclient requests'), - ( 'openssl aes-256-cbc -k $google_key' - ' -in travis/googleplay_android_developer-5a411156212c.json.enc' - ' -out travis/googleplay_android_developer-5a411156212c.json' - ' -d'), - ( 'openssl aes-256-cbc -k $google_key' - ' -in travis/test_ks.ks.enc' - ' -out travis/test_ks.ks -d'), - ( 'openssl aes-256-cbc -K $encrypted_eba2f7543984_key' - ' -iv $encrypted_eba2f7543984_iv' - ' -in travis/travisci_builder_id_key.enc' - ' -out travis/travisci_builder_id_key -d'), - 'chmod 600 travis/travisci_builder_id_key' - ], - 'env' : env, - 'script' : 'travis_wait 30 travis/compile_custom_app.sh', - 'deploy' : { - 'provider': 'script', - 'skip_cleanup': True, - 'script': 'travis/deploy_apk.sh', - 'on': { - 'branch': 'custom_app' - } - }, - 'jobs': { - 'include': [ - { - 'stage' : 'make_release', - 'install': 'pip3 install -r requirements_build_custom_app.txt', - 'script': True, - 'env': global_env, - 'deploy' : { - 'provider': 'script', - 'skip_cleanup': True, - 'script': 'travis/make_release.sh', - 'on': { - 'branch': 'custom_app' - } - } - } - ] - } - } + 'message' : tmpl_message.format(app=options.custom_app, zim=options.zim_url, uuid=uuid), + 'branch' : "custom_app", + 'config' : { + 'before_install' : [ + ( 'pip3 install pyOpenSSl google-api-python-client' + ' httplib2 apiclient requests'), + ( 'openssl aes-256-cbc -k $google_key' + ' -in travis/googleplay_android_developer-5a411156212c.json.enc' + ' -out travis/googleplay_android_developer-5a411156212c.json' + ' -d'), + ( 'openssl aes-256-cbc -k $google_key' + ' -in travis/test_ks.ks.enc' + ' -out travis/test_ks.ks -d'), + ( 'openssl aes-256-cbc -K $encrypted_eba2f7543984_key' + ' -iv $encrypted_eba2f7543984_iv' + ' -in travis/travisci_builder_id_key.enc' + ' -out travis/travisci_builder_id_key -d'), + 'chmod 600 travis/travisci_builder_id_key' + ], + 'env' : env, + 'script' : 'travis_wait 30 travis/compile_custom_app.sh', + 'deploy' : { + 'provider': 'script', + 'skip_cleanup': True, + 'script': 'travis/deploy_apk.sh', + 'on': { + 'branch': 'custom_app' + } + } + } } } + if options.android_upload: + data['request']['config']['jobs'] = { + 'include': [ + { + 'stage' : 'make_release', + 'install': 'pip3 install -r requirements_build_custom_app.txt', + 'script': True, + 'env': global_env, + 'deploy' : { + 'provider': 'script', + 'skip_cleanup': True, + 'script': 'travis/make_release.sh', + 'on': { + 'branch': 'custom_app' + } + } + } + ] + } + global_env.append({ + 'DEPLOY_DIR' : '/home/nightlybot/apks/{}_{}'.format( + options.custom_app, options.base_version) + }) + else: + global_env.append({ + 'DEPLOY_DIR' : '/var/www/tmp.kiwix.org/custom_apps/{}_{}'.format( + options.custom_app, options.base_version) + }) + r = requests.post(request_url, headers=headers, json=data) if r.status_code != 202: @@ -293,6 +304,11 @@ def travis_launch_build(organisation, repository, options, zim_size): "the associated build. Have a look here " "https://travis-ci.org/kiwix/kiwix-build/builds" "if you found it.") + if not options.android_upload: + print(("Automatic upload to android play store has been deactivated.\n" + "You will find the apks at this address once they have been compiled :" + " http://tmp.kiwix.org/custom_apps/{}_{}").format( + options.custom_app, options.base_version)) ERROR_MSG_EDIT_CHANGE = "A change was made to the application outside of this Edit, please create a new edit." diff --git a/travis/deploy_apk.sh b/travis/deploy_apk.sh index 896d498..3ea7711 100755 --- a/travis/deploy_apk.sh +++ b/travis/deploy_apk.sh @@ -20,8 +20,8 @@ TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign \ --out ${SIGNED_APK} \ ${INPUT_APK_FILE} -ssh -i ${SSH_KEY} nightlybot@download.kiwix.org "mkdir -p ~/apks/${CUSTOM_APP}_${BASE_VERSION}" +ssh -i ${SSH_KEY} nightlybot@download.kiwix.org "mkdir -p ${DEPLOY_DIR}" scp -i ${SSH_KEY} \ ${SIGNED_APK} \ - nightlybot@download.kiwix.org:~/apks/${CUSTOM_APP}_${BASE_VERSION} + nightlybot@download.kiwix.org:${DEPLOY_DIR} diff --git a/travis/make_release.sh b/travis/make_release.sh index 33b50ab..a7524ee 100755 --- a/travis/make_release.sh +++ b/travis/make_release.sh @@ -13,9 +13,9 @@ BASE_DIR="BUILD_${PLATFORM}" mkdir -p ${HOME}/APKS -scp -i ${SSH_KEY} nightlybot@download.kiwix.org:~/apks/${CUSTOM_APP}_${BASE_VERSION}/* ${HOME}/APKS +scp -i ${SSH_KEY} nightlybot@download.kiwix.org:${DEPLOY_DIR}/* ${HOME}/APKS -ssh -i ${SSH_KEY} nightlybot@download.kiwix.org "rm -rf ~/apks/${CUSTOM_APP}_${BASE_VERSION}" +ssh -i ${SSH_KEY} nightlybot@download.kiwix.org "rm -rf ${DEPLOY_DIR}" ${TRAVIS_BUILD_DIR}/build_custom_app.py \ --step publish \