From ac93cc24bbf8c37bf771732895cbe7c7cd421370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 15 Mar 2019 17:56:58 +0100 Subject: [PATCH 01/67] WIP begin seperation build and signing --- build.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ build_ipa.sh | 74 +++++++++++++++++++++++++++++++++++ index.js | 10 ++++- 3 files changed, 190 insertions(+), 2 deletions(-) create mode 100755 build.sh create mode 100755 build_ipa.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e4ecf78 --- /dev/null +++ b/build.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +# This task builds ipas and apks for Cordova projects with associated +# ios/android container projects. +# +# ENVIRONMENT VARIABLES: +# +# Defined via Gitlab Job: +# +# CONFIG Name of deploy configuration. Determines which +# *.config and *.yml files are used in +# project's `deploy/ios/configs` directory. +# BUILD_NUMBER Unique Build number to identify the build. I.e. pipline no. +# BUILD_IPA +# BUILD_APK +# +# Config specific variables are loaded from the core project's files +# `deploy/base.config` and `deploy/configs/$CONFIG.config`. See +# documentation in ipa.sh for further information on environment +# variables required for building and publishing the ipa file. + + +# Output every command and fail if any command fails +set -ex +export SHELLDIR=$(dirname $0) +export WORKSPACE=$(pwd) +export CORDOVA_APP_DIR=$WORKSPACE/cordova/$(ls -1 cordova) +export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms +export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android +export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios +export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ +export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') + +function replaceConfigXmlVars { + cd $CORDOVA_APP_DIR + for cvar in ${!CONFIGXML_VAR_*}; do + echo "Replacing variable ${cvar} in config.xml with ${!cvar}" + sed -i '' "s/$cvar/${!cvar}/g" config.xml + done +} + +# Copy resource-files +RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" +RESOURCES_FILES="$RESOURCES_DIR*.$CONFIG" + +if [ -d "$RESOURCES_DIR" ]; then + if compgen -G "$RESOURCES_FILES" > /dev/null; then + echo "Copying resource files from $RESOURCES_FILES to cordova root dir..." + for f in ${RESOURCES_FILES}; do + [ -e "$f" ] || continue + target_filename="$(basename "$f" .$CONFIG)" + echo "... copy ${f##*/} to $CORDOVA_APP_DIR/$target_filename" + cp "$f" "$CORDOVA_APP_DIR/$target_filename" + done + fi +fi + +export PATH=$PATH:/opt/local/bin +export LANG=de_DE.UTF-8 + +# Export deploy config for ipa script +export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ + PROVISIONING_PROFILE_FILE_NAME PROVISIONING_PROFILE_ID \ + WIDGET_PROVISIONING_PROFILE_FILE_NAME WIDGET_PROVISIONING_PROFILE_ID \ + BUNDLE_IDENTIFIER PRODUCT_NAME APP_NAME \ + KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR + +# prepare cordova projects + +cd $CORDOVA_APP_DIR + +# Cordova fetch is totally broken for git urls comming not from known hosters. It uses this module, which has been patched to know codevise gitlab. +npm install https://github.com/jrunkel/hosted-git-info.git#latest +npm install xml2js +npm install cordova-custom-config + +rm -rf platforms/android +rm -rf platforms/ios + +if [ "$BUILD_IPA" == 'true' ]; then + rm -rf plugins/* + replaceConfigXmlVars + sed -i '' "s/&2 + exit 1 +} + +set -ex + +[ -f $HUDSON_NODE_HOME/hudson_ipa.config ] && source $HUDSON_NODE_HOME/hudson_ipa.config + +cd $IOS_CONTAINER +security unlock-keychain -p $KEYCHAIN_PASSWORD +agvtool new-version -all $BUILD_NUMBER + +if [ -n "$BUNDLE_VERSION" ]; then + agvtool new-marketing-version $BUNDLE_VERSION +fi + +PROVISIONING_PROFILES_DIR=$HOME"/Library/MobileDevice/Provisioning Profiles/" +# Copy provisioning profile to provisioning profiles dir +[ -d "$PROVISIONING_PROFILES_DIR" ] || mkdir -p "$PROVISIONING_PROFILES_DIR" +provisioning_profiles_source_dir="$WORKSPACE/deploy/ios/profiles/" + +# Copy main profile +provisioning_profile_source="$provisioning_profiles_source_dir/$PROVISIONING_PROFILE_FILE_NAME" +[ -f "$provisioning_profile_source" ] || fail "Profile '$PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" +provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$PROVISIONING_PROFILE_ID.mobileprovision" +[ -f "$provisioning_profile_file_name" ] || cp "$provisioning_profile_source" "$provisioning_profile_file_name" + + +#Optional copy widget profile +if [ -n "$WIDGET_PROVISIONING_PROFILE_FILE_NAME" ]; then + echo "WIDGET: $WIDGET_PROVISIONING_PROFILE_FILE_NAME" + widget_provisioning_profile_source="$provisioning_profiles_source_dir/$WIDGET_PROVISIONING_PROFILE_FILE_NAME" + [ -f "$widget_provisioning_profile_source" ] || fail "Widget Profile '$WIDGET_PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" + widget_provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$WIDGET_PROVISIONING_PROFILE_ID.mobileprovision" + [ -f "$widget_provisioning_profile_file_name" ] || cp "$widget_provisioning_profile_source" "$widget_provisioning_profile_file_name" +fi + +scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') + +# Install pods if any +if [ -f "Podfile" ]; then + echo "Installing Pods" + pod install +fi + +mkdir export +xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -configuration $CONFIGURATION -archivePath $(pwd)/build/${scheme_name}.xcarchive -sdk iphoneos -scheme $scheme_name archive PROVISIONING_PROFILE=$PROVISIONING_PROFILE_ID WIDGET_PROVISIONING_PROFILE=$WIDGET_PROVISIONING_PROFILE_ID CODE_SIGN_IDENTITY="$DISTRIBUTION_CERTIFICATE" CODE_SIGN_STYLE="Manual" || fail "xcodebuild failed." diff --git a/index.js b/index.js index 3cfcd41..75bc0c4 100755 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ program .arguments('') .option('-i, --ipa', 'Build IPA') .option('-a, --apk', 'Build APK') +.option('-b, --build', 'Only build - dont sign') .action(function(conf) { config = conf; }) @@ -27,6 +28,11 @@ if (program.apk) process.env['BUILD_APK'] = 'true'; process.env['CONFIG'] = config; if (program.ipa || program.apk) { - var child = shspawn(path + '/cordova.sh'); - process.exit(child.status); + if (program.build) { + var child = shspawn(path + '/build.sh'); + process.exit(child.status); + } else { + var child = shspawn(path + '/cordova.sh'); + process.exit(child.status); + } } -- GitLab From 589517c3c6cfd03ed8e75993e1f82c8ece78d733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 10:43:21 +0100 Subject: [PATCH 02/67] add www --- build.sh | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index e4ecf78..db0f690 100755 --- a/build.sh +++ b/build.sh @@ -76,6 +76,7 @@ npm install cordova-custom-config rm -rf platforms/android rm -rf platforms/ios +mkdir www if [ "$BUILD_IPA" == 'true' ]; then rm -rf plugins/* diff --git a/package.json b/package.json index dca125b..ed116a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-ci-module", - "version": "0.4.0", + "version": "0.5.0", "description": "Command line utilities to configure, build and sign cordova apps", "main": "index.js", "scripts": { -- GitLab From de769db5bb9a7011fffc664c759ef2d82990a37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 11:35:24 +0100 Subject: [PATCH 03/67] set config to development for native build --- build.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index db0f690..c40c45d 100755 --- a/build.sh +++ b/build.sh @@ -5,11 +5,6 @@ # # ENVIRONMENT VARIABLES: # -# Defined via Gitlab Job: -# -# CONFIG Name of deploy configuration. Determines which -# *.config and *.yml files are used in -# project's `deploy/ios/configs` directory. # BUILD_NUMBER Unique Build number to identify the build. I.e. pipline no. # BUILD_IPA # BUILD_APK @@ -39,6 +34,8 @@ function replaceConfigXmlVars { done } +export CONFIG=development + # Copy resource-files RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" RESOURCES_FILES="$RESOURCES_DIR*.$CONFIG" -- GitLab From ebae5a70d56adf1bf6ffc1b16f7034b45eba94f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 14:02:57 +0100 Subject: [PATCH 04/67] load config --- build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.sh b/build.sh index c40c45d..ea5e047 100755 --- a/build.sh +++ b/build.sh @@ -34,7 +34,10 @@ function replaceConfigXmlVars { done } +# Load configurations export CONFIG=development +[ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" +[ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" # Copy resource-files RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" -- GitLab From 4bf0c10f09f075f2bbfaa73936326760643238d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 14:50:10 +0100 Subject: [PATCH 05/67] fix --- build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.sh b/build.sh index ea5e047..6e1b721 100755 --- a/build.sh +++ b/build.sh @@ -88,6 +88,7 @@ if [ "$BUILD_IPA" == 'true' ]; then # Invoke ipa build and upload source $SHELLDIR/build_ipa.sh + cd $CORDOVA_APP_DIR mv platforms/ios platforms_release/ fi @@ -101,6 +102,7 @@ if [ "$BUILD_APK" == 'true' ]; then # Invoke apk build and upload source $SHELLDIR/build_apk.sh + cd $CORDOVA_APP_DIR mv platforms/ios platforms_release/ fi -- GitLab From acbb393bb54785e21bb710b78fa3e0b3b5716fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 15:22:25 +0100 Subject: [PATCH 06/67] add build_apk --- build_apk.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 build_apk.sh diff --git a/build_apk.sh b/build_apk.sh new file mode 100755 index 0000000..b4333c5 --- /dev/null +++ b/build_apk.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# WORKSPACE +# BUILD_NUMBER +# APP_NAME +# ANDROID_SIGNING_KEY_FILE_NAME +# ANDROID_SIGNING_KEY_ALIAS +# ANDROID_SIGNING_KEY_STORE_PASSWORD +# ANDROID_SIGNING_KEY_ALIAS_PASSWORD +# ANDROID_REMOTE_PATH +# ANDROID_SDK_PATH +# REMOTE_HOST +# CONFIG + +function fail() { + echo "FAILED: $@" >&2 + exit 1 +} + +cd $CORDOVA_APP_DIR +../../node_modules/cordova/bin/cordova build android --release + +cd $ANDROID_CONTAINER/build/outputs/apk/ || fail "Build directory does not exist." -- GitLab From d0f81feb48b26c9264b37822f8dfc1833adad353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 15:36:58 +0100 Subject: [PATCH 07/67] add android platform --- build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sh b/build.sh index 6e1b721..7fd9e0d 100755 --- a/build.sh +++ b/build.sh @@ -98,6 +98,7 @@ if [ "$BUILD_APK" == 'true' ]; then replaceConfigXmlVars sed -i '' "s/ Date: Mon, 18 Mar 2019 19:44:25 +0100 Subject: [PATCH 08/67] try --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 7fd9e0d..75d4682 100755 --- a/build.sh +++ b/build.sh @@ -67,13 +67,13 @@ export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ # prepare cordova projects -cd $CORDOVA_APP_DIR # Cordova fetch is totally broken for git urls comming not from known hosters. It uses this module, which has been patched to know codevise gitlab. npm install https://github.com/jrunkel/hosted-git-info.git#latest npm install xml2js npm install cordova-custom-config +cd $CORDOVA_APP_DIR rm -rf platforms/android rm -rf platforms/ios mkdir www -- GitLab From 9c8cc9fe88490b65f2ccdc14e58f3f45cb7db029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 20:55:58 +0100 Subject: [PATCH 09/67] add npm deps to package.json --- build.sh | 6 +++--- package.json | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 75d4682..3fd2a48 100755 --- a/build.sh +++ b/build.sh @@ -69,9 +69,9 @@ export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ # Cordova fetch is totally broken for git urls comming not from known hosters. It uses this module, which has been patched to know codevise gitlab. -npm install https://github.com/jrunkel/hosted-git-info.git#latest -npm install xml2js -npm install cordova-custom-config +#npm install https://github.com/jrunkel/hosted-git-info.git#latest +#npm install xml2js +#npm install cordova-custom-config cd $CORDOVA_APP_DIR rm -rf platforms/android diff --git a/package.json b/package.json index ed116a7..89eb949 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ }, "dependencies": { "commander": "^2.12.2", - "cordova": "^8.0.0" + "cordova": "^8.0.0", + "hosted-git-info": "git+https://github.com/jrunkel/hosted-git-info.git#latest", + "ncp": "^2.0.0", + "xml2js": "^0.4.19", + "cordova-custom-config": "^5.0.3" } } -- GitLab From f402ed64c79baec22b3272372abaddc7bcff9896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 18 Mar 2019 23:04:33 +0100 Subject: [PATCH 10/67] rm obsolete hudson_ipa file --- build_ipa.sh | 2 -- ipa.sh | 6 ------ 2 files changed, 8 deletions(-) diff --git a/build_ipa.sh b/build_ipa.sh index a8fda34..2a30073 100755 --- a/build_ipa.sh +++ b/build_ipa.sh @@ -31,8 +31,6 @@ function fail() { set -ex -[ -f $HUDSON_NODE_HOME/hudson_ipa.config ] && source $HUDSON_NODE_HOME/hudson_ipa.config - cd $IOS_CONTAINER security unlock-keychain -p $KEYCHAIN_PASSWORD agvtool new-version -all $BUILD_NUMBER diff --git a/ipa.sh b/ipa.sh index e57949c..2f0d5bc 100755 --- a/ipa.sh +++ b/ipa.sh @@ -4,11 +4,7 @@ # # WORKSPACE Automatically defined by Hudson. # HUDSON_NODE_HOME Home directory of Hudson user on current node. -# Configured in environment variables of Hudson node. -# Node specific variables (defined in `$HUDSON_NODE_HOME/hudson_ipa.config`): -# # KEYCHAIN_PASSWORD Password to unlock the OS X keychain tools. Most -# likely the Hudson user's login keyword. # CONFIG Environment e.g. development or production # Config specific variables: # @@ -31,8 +27,6 @@ function fail() { set -ex -[ -f $HUDSON_NODE_HOME/hudson_ipa.config ] && source $HUDSON_NODE_HOME/hudson_ipa.config - cd $IOS_CONTAINER security unlock-keychain -p $KEYCHAIN_PASSWORD agvtool new-version -all $BUILD_NUMBER -- GitLab From 02048cc71de70e80666ccdd4e2b80e50fe07e3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 16:36:00 +0100 Subject: [PATCH 11/67] creatr platfor_release dir --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 3fd2a48..b9a7b95 100755 --- a/build.sh +++ b/build.sh @@ -76,7 +76,7 @@ export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ cd $CORDOVA_APP_DIR rm -rf platforms/android rm -rf platforms/ios -mkdir www +mkdir platforms_release if [ "$BUILD_IPA" == 'true' ]; then rm -rf plugins/* @@ -104,7 +104,7 @@ if [ "$BUILD_APK" == 'true' ]; then # Invoke apk build and upload source $SHELLDIR/build_apk.sh cd $CORDOVA_APP_DIR - mv platforms/ios platforms_release/ + mv platforms/android platforms_release/ fi -- GitLab From f9b8f75a96ec288713044a2e9af951e4bdc0999f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 17:02:02 +0100 Subject: [PATCH 12/67] fix cordova dir --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index b9a7b95..2ccbe6d 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$WORKSPACE/cordova/$(ls -1 cordova) +export CORDOVA_APP_DIR=basename $(ls -d $WORKSPACE/cordova/*/) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -- GitLab From 26586f9640d9b1f4f76bbf04819e37f608e0b790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 17:21:06 +0100 Subject: [PATCH 13/67] fix cordova dir --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 2ccbe6d..17be9f2 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=basename $(ls -d $WORKSPACE/cordova/*/) +export CORDOVA_APP_DIR=basename $(ls -d -1 $WORKSPACE/cordova/*/) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -- GitLab From 53a478e601ee31f500f2cd1f78587c4ad459ad12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 17:41:30 +0100 Subject: [PATCH 14/67] fix --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 17be9f2..5db1c55 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=basename $(ls -d -1 $WORKSPACE/cordova/*/) +export CORDOVA_APP_DIR=$(basename $(ls -d -1 $WORKSPACE/cordova/*/)) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -- GitLab From e3f8265dcf0d452ca2a4ba1169362f379924b087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 17:47:23 +0100 Subject: [PATCH 15/67] try --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 5db1c55..940a8fe 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$(basename $(ls -d -1 $WORKSPACE/cordova/*/)) +export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*/) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -- GitLab From e563680b645f8a7c2152f24da7984c732ccdd38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 21:52:08 +0100 Subject: [PATCH 16/67] WIP sign stuff --- index.js | 3 ++ sign.sh | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sign_ipa.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100755 sign.sh create mode 100755 sign_ipa.sh diff --git a/index.js b/index.js index 75bc0c4..8d78b2f 100755 --- a/index.js +++ b/index.js @@ -31,6 +31,9 @@ if (program.ipa || program.apk) { if (program.build) { var child = shspawn(path + '/build.sh'); process.exit(child.status); + } else if (program.sign){ + var child = shspawn(path + '/sign.sh'); + process.exit(child.status); } else { var child = shspawn(path + '/cordova.sh'); process.exit(child.status); diff --git a/sign.sh b/sign.sh new file mode 100755 index 0000000..9351000 --- /dev/null +++ b/sign.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# This task builds ipas and apks for Cordova projects with associated +# ios/android container projects. +# +# ENVIRONMENT VARIABLES: +# +# Defined via Gitlab Job: +# +# CONFIG Name of deploy configuration. Determines which +# *.config and *.yml files are used in +# project's `deploy/ios/configs` directory. +# BUILD_NUMBER Unique Build number to identify the build. I.e. pipline no. +# BUILD_IPA +# BUILD_APK +# +# Config specific variables are loaded from the core project's files +# `deploy/base.config` and `deploy/configs/$CONFIG.config`. See +# documentation in ipa.sh for further information on environment +# variables required for building and publishing the ipa file. + + +# Output every command and fail if any command fails +set -ex +export SHELLDIR=$(dirname $0) +export WORKSPACE=$(pwd) +export CORDOVA_APP_DIR=$WORKSPACE/cordova/$(ls -1 cordova) +export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms_release +export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android +export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios +export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ +export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') + +# Load configurations +[ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" +[ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" + +cd $WORKSPACE +if [ -f "deploy/configs/$CONFIG.json" ] +then + # Configure project with JSON configs -- deprecated variant + echo "Deprecation warning: App configuration using JSON configs is deprecated." + cp "deploy/configs/$CONFIG.json" src/config/config.json + sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json +elif [ -f "deploy/configs/$CONFIG.js" ] +then + # Configure project with JS configs + cp "deploy/configs/$CONFIG.js" src/conf.js + sed -i '' "s/buildVersion:.*/buildVersion: '${BUILD_NUMBER}.${BRANCH}',/g" src/conf.js +else + echo "No valid configuration found for environment $CONFIG in deploy/config/" + exit 1 +fi + +export PATH=$PATH:/opt/local/bin +export LANG=de_DE.UTF-8 + +# Export deploy config for ipa script +export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ + PROVISIONING_PROFILE_FILE_NAME PROVISIONING_PROFILE_ID \ + WIDGET_PROVISIONING_PROFILE_FILE_NAME WIDGET_PROVISIONING_PROFILE_ID \ + BUNDLE_IDENTIFIER PRODUCT_NAME APP_NAME \ + KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR + + +# Build JS +node_modules/.bin/webpack -p webpack.prod.config.js + + +cd $CORDOVA_APP_DIR + +if [ "$BUILD_IPA" == 'true' ]; then + + cd $CORDOVA_APP_DIR + source $SHELLDIR/sign_ipa.sh + + bundle exec rake app_distributor:submit:ipa +fi + +if [ "$BUILD_APK" == 'true' ]; then + + cd $CORDOVA_APP_DIR + source $SHELLDIR/sign_apk.sh + + bundle exec rake app_distributor:submit:apk +fi + + + diff --git a/sign_ipa.sh b/sign_ipa.sh new file mode 100755 index 0000000..b18c390 --- /dev/null +++ b/sign_ipa.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# ENVIRONMENT VARIABLES: +# +# WORKSPACE Automatically defined by Hudson. +# HUDSON_NODE_HOME Home directory of Hudson user on current node. +# KEYCHAIN_PASSWORD Password to unlock the OS X keychain tools. Most +# CONFIG Environment e.g. development or production +# Config specific variables: +# +# SDK Name of the ios SDK, i.e. 'iphoneos'. +# CONFIGURATION Name of the Xcode configuration, i.e. 'Release' +# or 'Debug'. +# DISTRIBUTION_CERTIFICATE Name of the distribution certificate, i.e. +# 'iPhone Distribution: Your Company Pty Ltd'. +# PROVISIONING_PROFILE_FILE_NAME File name of the provisioning profile inside the +# season project's `deploy/ios/profiles` directory. +# PROVISIONING_PROFILE_ID Unique ID of provisioning profile of the form +# xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx. +# BUNDLE_IDENTIFIER_IOS Bundle identifier to name the ipa with. +# PRODUCT_NAME Display name of the application. + +function fail() { + echo "FAILED: $@" >&2 + exit 1 +} + +set -ex + +cd $IOS_CONTAINER +security unlock-keychain -p $KEYCHAIN_PASSWORD +agvtool new-version -all $BUILD_NUMBER + +if [ -n "$BUNDLE_VERSION" ]; then + agvtool new-marketing-version $BUNDLE_VERSION +fi + +PROVISIONING_PROFILES_DIR=$HOME"/Library/MobileDevice/Provisioning Profiles/" +# Copy provisioning profile to provisioning profiles dir +[ -d "$PROVISIONING_PROFILES_DIR" ] || mkdir -p "$PROVISIONING_PROFILES_DIR" +provisioning_profiles_source_dir="$WORKSPACE/deploy/ios/profiles/" + +# Copy main profile +provisioning_profile_source="$provisioning_profiles_source_dir/$PROVISIONING_PROFILE_FILE_NAME" +[ -f "$provisioning_profile_source" ] || fail "Profile '$PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" +provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$PROVISIONING_PROFILE_ID.mobileprovision" +[ -f "$provisioning_profile_file_name" ] || cp "$provisioning_profile_source" "$provisioning_profile_file_name" + + +#Optional copy widget profile +if [ -n "$WIDGET_PROVISIONING_PROFILE_FILE_NAME" ]; then + echo "WIDGET: $WIDGET_PROVISIONING_PROFILE_FILE_NAME" + widget_provisioning_profile_source="$provisioning_profiles_source_dir/$WIDGET_PROVISIONING_PROFILE_FILE_NAME" + [ -f "$widget_provisioning_profile_source" ] || fail "Widget Profile '$WIDGET_PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" + widget_provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$WIDGET_PROVISIONING_PROFILE_ID.mobileprovision" + [ -f "$widget_provisioning_profile_file_name" ] || cp "$widget_provisioning_profile_source" "$widget_provisioning_profile_file_name" +fi + +scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') + + +APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app +cp -r ../../www/* $APP_FOLDER/www/ + +mkdir export + +xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${scheme_name}.xcarchive -exportOptionsPlist "${provisioning_profiles_source_dir}/${CONFIG}-export-options.plist" -exportPath "export/" +# Copy app folder containing Info.plist needed for app distributor to export directory +cp -r $APP_FOLDER export/ + +# Build simulator image +#cd $IOS_CONTAINER +#xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ +# CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" + +#simulator_directory="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" +#simulator_file_name="$scheme_name.zip" +#zip -r "export/$simulator_file_name" $simulator_directory -- GitLab From ec1f1ebf947f33ab5ac365c635d188b32498a8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 22:08:33 +0100 Subject: [PATCH 17/67] add sign option --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 8d78b2f..e950ee3 100755 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ program .option('-i, --ipa', 'Build IPA') .option('-a, --apk', 'Build APK') .option('-b, --build', 'Only build - dont sign') +.option('-s, --sign', 'Sign and upload to app distributor') .action(function(conf) { config = conf; }) -- GitLab From f16c349823f1b3f22ed8b576e107abd7623e3fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 22:18:10 +0100 Subject: [PATCH 18/67] do not fail on existin export dir --- sign_ipa.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sign_ipa.sh b/sign_ipa.sh index b18c390..a4e5a90 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -62,7 +62,7 @@ scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app cp -r ../../www/* $APP_FOLDER/www/ -mkdir export +mkdir -p export xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${scheme_name}.xcarchive -exportOptionsPlist "${provisioning_profiles_source_dir}/${CONFIG}-export-options.plist" -exportPath "export/" # Copy app folder containing Info.plist needed for app distributor to export directory -- GitLab From 2cb106b397810a0a52bbeaad15dac143f725a6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Wed, 20 Mar 2019 22:37:09 +0100 Subject: [PATCH 19/67] fix webpack cmd --- sign.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sign.sh b/sign.sh index 9351000..41463c0 100755 --- a/sign.sh +++ b/sign.sh @@ -64,7 +64,7 @@ export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ # Build JS -node_modules/.bin/webpack -p webpack.prod.config.js +node_modules/.bin/webpack --config webpack.prod.config.js cd $CORDOVA_APP_DIR -- GitLab From cba796911926fb3ee736102d621fc24fb64f1c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 11:58:29 +0100 Subject: [PATCH 20/67] save cache --- build.sh | 28 ++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index 940a8fe..dc8398f 100755 --- a/build.sh +++ b/build.sh @@ -34,8 +34,26 @@ function replaceConfigXmlVars { done } +function getCacheFilename { + local DIR_HASH=$(git ls-files -s $CORDOVA_APP_DIR | git hash-object --stdin) + local DIR_KEY=$CONFIG-$DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ + local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz + echo "$CACHE_FILE" +} + +function saveCache { + tar -cvzf $(getCacheFilename) $CORDOVA_APP_DIR/platforms_release +} + +if [-f $(getCacheFilename)]; then + echo "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." + exit 0 +fi +echo "No native build cache '$CACHE_FILE' found. Building..." + + # Load configurations -export CONFIG=development [ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" [ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" @@ -67,12 +85,6 @@ export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ # prepare cordova projects - -# Cordova fetch is totally broken for git urls comming not from known hosters. It uses this module, which has been patched to know codevise gitlab. -#npm install https://github.com/jrunkel/hosted-git-info.git#latest -#npm install xml2js -#npm install cordova-custom-config - cd $CORDOVA_APP_DIR rm -rf platforms/android rm -rf platforms/ios @@ -109,4 +121,4 @@ if [ "$BUILD_APK" == 'true' ]; then fi - +saveCache diff --git a/package.json b/package.json index 89eb949..b6794b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-ci-module", - "version": "0.5.0", + "version": "0.6.0", "description": "Command line utilities to configure, build and sign cordova apps", "main": "index.js", "scripts": { -- GitLab From 559163a27b97aacdd65358ad8c52c45af7eabe81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 12:30:42 +0100 Subject: [PATCH 21/67] fix if --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index dc8398f..6e2681c 100755 --- a/build.sh +++ b/build.sh @@ -46,7 +46,7 @@ function saveCache { tar -cvzf $(getCacheFilename) $CORDOVA_APP_DIR/platforms_release } -if [-f $(getCacheFilename)]; then +if [ -f "$(getCacheFilename)"]; then echo "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." exit 0 fi -- GitLab From da4c42deee2211bc4f49c0f728733c773fb5ac8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 12:32:38 +0100 Subject: [PATCH 22/67] fix www --- build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 6e2681c..efa02b0 100755 --- a/build.sh +++ b/build.sh @@ -88,7 +88,8 @@ export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ cd $CORDOVA_APP_DIR rm -rf platforms/android rm -rf platforms/ios -mkdir platforms_release +mkdir -p www +mkdir -p platforms_release if [ "$BUILD_IPA" == 'true' ]; then rm -rf plugins/* -- GitLab From c4098e91f84fa237ff888462abbca4dc5279ed77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 13:03:11 +0100 Subject: [PATCH 23/67] fix --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index efa02b0..1ab508a 100755 --- a/build.sh +++ b/build.sh @@ -46,7 +46,7 @@ function saveCache { tar -cvzf $(getCacheFilename) $CORDOVA_APP_DIR/platforms_release } -if [ -f "$(getCacheFilename)"]; then +if [ -f "$(getCacheFilename)" ]; then echo "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." exit 0 fi -- GitLab From bdb621d7a01231b58389f0975f323dd890b92f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 14:10:35 +0100 Subject: [PATCH 24/67] WIP --- build.sh | 11 +++++++---- sign.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 1ab508a..5375343 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*/) +export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios @@ -35,7 +35,7 @@ function replaceConfigXmlVars { } function getCacheFilename { - local DIR_HASH=$(git ls-files -s $CORDOVA_APP_DIR | git hash-object --stdin) + local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') local DIR_KEY=$CONFIG-$DIR_HASH local CACHE_DIR=/Users/apfel/buildcache/ local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz @@ -43,10 +43,13 @@ function getCacheFilename { } function saveCache { - tar -cvzf $(getCacheFilename) $CORDOVA_APP_DIR/platforms_release + cd $CORDOVA_APP_DIR/platforms_release + tar -cvzf $(getCacheFilename) . + cd - } -if [ -f "$(getCacheFilename)" ]; then +CACHE_FILE=$(getCacheFilename) +if [ -f "$CACHE_FILE" ]; then echo "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." exit 0 fi diff --git a/sign.sh b/sign.sh index 41463c0..11b75b4 100755 --- a/sign.sh +++ b/sign.sh @@ -19,6 +19,18 @@ # documentation in ipa.sh for further information on environment # variables required for building and publishing the ipa file. +RED="\033[1;31m" +GREEN="\033[1;32m" +NOCOLOR="\033[0m" + +function echo_ok () { + echo "[${GREEN}OK${NOCOLOR}] $1" +} +function echo_fail () { + echo "[${GREEN}ERROR${NOCOLOR}] $1" +} + + # Output every command and fail if any command fails set -ex @@ -31,6 +43,29 @@ export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') + +# Restore cache +function getCacheFilename { + local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') + local DIR_KEY=$CONFIG-$DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ + local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz + echo "$CACHE_FILE" +} + +function restoreCache { + tar -zxvf $(getCacheFilename) $CORDOVA_APP_DIR/platforms_release +} + +CACHE_FILE=$(getCacheFilename) +if [ -f "$CACHE_FILE" ]; then + echo_ok "Native build cache '$CACHE_FILE' found. Continue..." + restoreCache +else + echo_fail "No native build cache '$CACHE_FILE' found. This should not happen!" + exit 1 +fi + # Load configurations [ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" [ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" -- GitLab From 425159101899c658b38be514aebccc3807ad33d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 14:29:40 +0100 Subject: [PATCH 25/67] WIP --- sign.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sign.sh b/sign.sh index 11b75b4..c124fd4 100755 --- a/sign.sh +++ b/sign.sh @@ -21,13 +21,19 @@ RED="\033[1;31m" GREEN="\033[1;32m" +YELLOW="\033[1;93m" NOCOLOR="\033[0m" function echo_ok () { - echo "[${GREEN}OK${NOCOLOR}] $1" + echo -e "[${GREEN}OK${NOCOLOR}] $1" } + function echo_fail () { - echo "[${GREEN}ERROR${NOCOLOR}] $1" + echo -e "[${GREEN}ERROR${NOCOLOR}] $1" +} + +function echo_warn () { + echo -e "[${YELLOW}WARN${NOCOLOR}] $1" } @@ -36,7 +42,7 @@ function echo_fail () { set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$WORKSPACE/cordova/$(ls -1 cordova) +export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms_release export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios @@ -54,7 +60,9 @@ function getCacheFilename { } function restoreCache { - tar -zxvf $(getCacheFilename) $CORDOVA_APP_DIR/platforms_release + cd $CORDOVA_APP_DIR/platforms_release + tar -zxvf $(getCacheFilename) + cd - } CACHE_FILE=$(getCacheFilename) @@ -74,7 +82,7 @@ cd $WORKSPACE if [ -f "deploy/configs/$CONFIG.json" ] then # Configure project with JSON configs -- deprecated variant - echo "Deprecation warning: App configuration using JSON configs is deprecated." + echo_warn "Deprecation warning: App configuration using JSON configs is deprecated." cp "deploy/configs/$CONFIG.json" src/config/config.json sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json elif [ -f "deploy/configs/$CONFIG.js" ] @@ -83,7 +91,7 @@ then cp "deploy/configs/$CONFIG.js" src/conf.js sed -i '' "s/buildVersion:.*/buildVersion: '${BUILD_NUMBER}.${BRANCH}',/g" src/conf.js else - echo "No valid configuration found for environment $CONFIG in deploy/config/" + echo_fail "No valid configuration found for environment $CONFIG in deploy/config/" exit 1 fi @@ -119,6 +127,3 @@ if [ "$BUILD_APK" == 'true' ]; then bundle exec rake app_distributor:submit:apk fi - - - -- GitLab From f50dc3bee52abfc283dd862e25db1f60a7f0d51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 14:47:39 +0100 Subject: [PATCH 26/67] WIP --- sign.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/sign.sh b/sign.sh index c124fd4..2d6b391 100755 --- a/sign.sh +++ b/sign.sh @@ -60,6 +60,7 @@ function getCacheFilename { } function restoreCache { + mkdir -p $CORDOVA_APP_DIR/platforms_release cd $CORDOVA_APP_DIR/platforms_release tar -zxvf $(getCacheFilename) cd - -- GitLab From 8ddd98a49f07bcbdc85e6ce1c147d24629a509a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 15:16:25 +0100 Subject: [PATCH 27/67] WIP --- build.sh | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/build.sh b/build.sh index 5375343..0f17ca6 100755 --- a/build.sh +++ b/build.sh @@ -17,36 +17,9 @@ # Output every command and fail if any command fails set -ex -export SHELLDIR=$(dirname $0) -export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) -export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms -export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android -export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ -export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') - -function replaceConfigXmlVars { - cd $CORDOVA_APP_DIR - for cvar in ${!CONFIGXML_VAR_*}; do - echo "Replacing variable ${cvar} in config.xml with ${!cvar}" - sed -i '' "s/$cvar/${!cvar}/g" config.xml - done -} - -function getCacheFilename { - local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') - local DIR_KEY=$CONFIG-$DIR_HASH - local CACHE_DIR=/Users/apfel/buildcache/ - local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz - echo "$CACHE_FILE" -} - -function saveCache { - cd $CORDOVA_APP_DIR/platforms_release - tar -cvzf $(getCacheFilename) . - cd - -} + +source include/env.sh +source include/funcs.sh CACHE_FILE=$(getCacheFilename) if [ -f "$CACHE_FILE" ]; then -- GitLab From 1c3531237a1f8b47bcfbf034229ac68660dbbfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 15:19:08 +0100 Subject: [PATCH 28/67] WIP --- include/env.sh | 13 +++++++++++++ include/funcs.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 include/env.sh create mode 100644 include/funcs.sh diff --git a/include/env.sh b/include/env.sh new file mode 100644 index 0000000..d9c02a4 --- /dev/null +++ b/include/env.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +export SHELLDIR=$(dirname $0) +export WORKSPACE=$(pwd) +export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) +export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms +export CORDOVA_PLATFORM_RELEASE_DIR=$CORDOVA_APP_DIR/platforms_release +export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android +export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios +export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ +export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') + + diff --git a/include/funcs.sh b/include/funcs.sh new file mode 100644 index 0000000..371d443 --- /dev/null +++ b/include/funcs.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +function replaceConfigXmlVars { + cd $CORDOVA_APP_DIR + for cvar in ${!CONFIGXML_VAR_*}; do + echo "Replacing variable ${cvar} in config.xml with ${!cvar}" + sed -i '' "s/$cvar/${!cvar}/g" config.xml + done +} + + +# Native build Cache related Functions + +function getCacheFilename { + local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') + local DIR_KEY=$CONFIG-$DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ + local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz + echo "$CACHE_FILE" +} + +function saveCache { + cd $CORDOVA_APP_DIR/platforms_release + tar -cvzf $(getCacheFilename) . + cd - +} + -- GitLab From cafef0a84fe39f847506cf6d9b518bc3ebd38469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 15:26:54 +0100 Subject: [PATCH 29/67] WIP --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6794b0..0ed9d27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-ci-module", - "version": "0.6.0", + "version": "0.6.1", "description": "Command line utilities to configure, build and sign cordova apps", "main": "index.js", "scripts": { -- GitLab From 5a4682afc9a0cf722770197176fcd41fd035ef5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 15:31:30 +0100 Subject: [PATCH 30/67] WIP --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 0f17ca6..ae415c5 100755 --- a/build.sh +++ b/build.sh @@ -18,8 +18,8 @@ # Output every command and fail if any command fails set -ex -source include/env.sh -source include/funcs.sh +source $(dirname $0)/include/env.sh +source $(dirname $0)/include/funcs.sh CACHE_FILE=$(getCacheFilename) if [ -f "$CACHE_FILE" ]; then -- GitLab From 0d1f964b2c2d04071dd1ee3e267fc1765345cdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 16:15:55 +0100 Subject: [PATCH 31/67] WIP --- README.md | 4 --- build.sh | 63 +++++++++++---------------------------- build_ipa.sh | 63 +++++++-------------------------------- include/env.sh | 17 +++++++++++ include/funcs.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++- ipa.sh | 20 ------------- sign_ipa.sh | 20 ------------- 7 files changed, 122 insertions(+), 142 deletions(-) diff --git a/README.md b/README.md index ed63434..f77de53 100644 --- a/README.md +++ b/README.md @@ -53,10 +53,6 @@ Define environment variables for your build here. The following variables are mandatory: ``` -PRODUCT_NAME='my_app' # iOS: used in resulting app filename - -APP_NAME='my_app' # Android: used in resulting app filename - ANDROID_SIGNING_KEY_FILE_NAME='my_app-release-key.keystore' ANDROID_SIGNING_KEY_ALIAS='my_app' ANDROID_SIGNING_KEY_STORE_PASSWORD='password' diff --git a/build.sh b/build.sh index ae415c5..47e92f2 100755 --- a/build.sh +++ b/build.sh @@ -11,56 +11,26 @@ # # Config specific variables are loaded from the core project's files # `deploy/base.config` and `deploy/configs/$CONFIG.config`. See -# documentation in ipa.sh for further information on environment -# variables required for building and publishing the ipa file. - - -# Output every command and fail if any command fails -set -ex +# documentation in include/env.sh for further information on environment +# variables required for building and publishing source $(dirname $0)/include/env.sh source $(dirname $0)/include/funcs.sh CACHE_FILE=$(getCacheFilename) if [ -f "$CACHE_FILE" ]; then - echo "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." + echo_ok "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." exit 0 fi -echo "No native build cache '$CACHE_FILE' found. Building..." - +echo_ok "No native build cache '$CACHE_FILE' found. Building..." -# Load configurations -[ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" -[ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" - -# Copy resource-files -RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" -RESOURCES_FILES="$RESOURCES_DIR*.$CONFIG" - -if [ -d "$RESOURCES_DIR" ]; then - if compgen -G "$RESOURCES_FILES" > /dev/null; then - echo "Copying resource files from $RESOURCES_FILES to cordova root dir..." - for f in ${RESOURCES_FILES}; do - [ -e "$f" ] || continue - target_filename="$(basename "$f" .$CONFIG)" - echo "... copy ${f##*/} to $CORDOVA_APP_DIR/$target_filename" - cp "$f" "$CORDOVA_APP_DIR/$target_filename" - done - fi -fi +echo_info "Load configuration for current env" +loadDeployConfiguration -export PATH=$PATH:/opt/local/bin -export LANG=de_DE.UTF-8 - -# Export deploy config for ipa script -export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ - PROVISIONING_PROFILE_FILE_NAME PROVISIONING_PROFILE_ID \ - WIDGET_PROVISIONING_PROFILE_FILE_NAME WIDGET_PROVISIONING_PROFILE_ID \ - BUNDLE_IDENTIFIER PRODUCT_NAME APP_NAME \ - KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR - -# prepare cordova projects +echo_info "Copy resource-files" +copyResourceFiles +echo_info "Prepare cordova projects" cd $CORDOVA_APP_DIR rm -rf platforms/android rm -rf platforms/ios @@ -68,34 +38,37 @@ mkdir -p www mkdir -p platforms_release if [ "$BUILD_IPA" == 'true' ]; then + echo_info "Building IOS project" rm -rf plugins/* replaceConfigXmlVars - sed -i '' "s/&2 - exit 1 -} - -set -ex +source $(dirname $0)/include/env.sh +source $(dirname $0)/include/funcs.sh cd $IOS_CONTAINER security unlock-keychain -p $KEYCHAIN_PASSWORD -agvtool new-version -all $BUILD_NUMBER +echo_info "Setting XCode versions to $BUILD_NUMBER.$BUNDLE_VERSION" +agvtool new-version -all $BUILD_NUMBER if [ -n "$BUNDLE_VERSION" ]; then agvtool new-marketing-version $BUNDLE_VERSION fi -PROVISIONING_PROFILES_DIR=$HOME"/Library/MobileDevice/Provisioning Profiles/" -# Copy provisioning profile to provisioning profiles dir -[ -d "$PROVISIONING_PROFILES_DIR" ] || mkdir -p "$PROVISIONING_PROFILES_DIR" -provisioning_profiles_source_dir="$WORKSPACE/deploy/ios/profiles/" - -# Copy main profile -provisioning_profile_source="$provisioning_profiles_source_dir/$PROVISIONING_PROFILE_FILE_NAME" -[ -f "$provisioning_profile_source" ] || fail "Profile '$PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" -provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$PROVISIONING_PROFILE_ID.mobileprovision" -[ -f "$provisioning_profile_file_name" ] || cp "$provisioning_profile_source" "$provisioning_profile_file_name" - - -#Optional copy widget profile -if [ -n "$WIDGET_PROVISIONING_PROFILE_FILE_NAME" ]; then - echo "WIDGET: $WIDGET_PROVISIONING_PROFILE_FILE_NAME" - widget_provisioning_profile_source="$provisioning_profiles_source_dir/$WIDGET_PROVISIONING_PROFILE_FILE_NAME" - [ -f "$widget_provisioning_profile_source" ] || fail "Widget Profile '$WIDGET_PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" - widget_provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$WIDGET_PROVISIONING_PROFILE_ID.mobileprovision" - [ -f "$widget_provisioning_profile_file_name" ] || cp "$widget_provisioning_profile_source" "$widget_provisioning_profile_file_name" -fi +echo_info "Copy provisioning profiles for $CONFIG" +setupIOSProvisioningProfiles +echo_ok "Done." scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') # Install pods if any if [ -f "Podfile" ]; then - echo "Installing Pods" + echo_info "Installing Pods" pod install fi mkdir export +echo_info "Building IOS archive..." xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -configuration $CONFIGURATION -archivePath $(pwd)/build/${scheme_name}.xcarchive -sdk iphoneos -scheme $scheme_name archive PROVISIONING_PROFILE=$PROVISIONING_PROFILE_ID WIDGET_PROVISIONING_PROFILE=$WIDGET_PROVISIONING_PROFILE_ID CODE_SIGN_IDENTITY="$DISTRIBUTION_CERTIFICATE" CODE_SIGN_STYLE="Manual" || fail "xcodebuild failed." + +echo_ok "Done." diff --git a/include/env.sh b/include/env.sh index d9c02a4..060df48 100644 --- a/include/env.sh +++ b/include/env.sh @@ -9,5 +9,22 @@ export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') +export PATH=$PATH:/opt/local/bin +export LANG=de_DE.UTF-8 + +function loadDeployConfiguration { + [ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" + [ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" + + # Export deploy config for dependend scripts + export CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ + PROVISIONING_PROFILE_FILE_NAME PROVISIONING_PROFILE_ID \ + WIDGET_PROVISIONING_PROFILE_FILE_NAME WIDGET_PROVISIONING_PROFILE_ID \ + BUNDLE_IDENTIFIER PRODUCT_NAME APP_NAME \ + KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR +} + +# Output every command and fail if any command fails +set -ex diff --git a/include/funcs.sh b/include/funcs.sh index 371d443..0d9e1f4 100644 --- a/include/funcs.sh +++ b/include/funcs.sh @@ -1,5 +1,6 @@ #!/bin/bash +# Replace environment specific vars in config.xml function replaceConfigXmlVars { cd $CORDOVA_APP_DIR for cvar in ${!CONFIGXML_VAR_*}; do @@ -9,8 +10,52 @@ function replaceConfigXmlVars { } -# Native build Cache related Functions +# Copy environment specific resource-files to cordova +function copyResourceFiles { + local RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" + local RESOURCES_FILES="$RESOURCES_DIR*.$CONFIG" + + if [ -d "$RESOURCES_DIR" ]; then + if compgen -G "$RESOURCES_FILES" > /dev/null; then + echo "Copying resource files from $RESOURCES_FILES to cordova root dir..." + for f in ${RESOURCES_FILES}; do + [ -e "$f" ] || continue + target_filename="$(basename "$f" .$CONFIG)" + echo "... copy ${f##*/} to $CORDOVA_APP_DIR/$target_filename" + cp "$f" "$CORDOVA_APP_DIR/$target_filename" + done + fi + fi +} + +function setBundleIdentifier () { + sed -i '' "s/&2 + exit 1 +} + +# Fancy console coloring +RED="\033[1;31m" +BLUE="\033[1;34m" +GREEN="\033[1;32m" +YELLOW="\033[1;93m" +NOCOLOR="\033[0m" + +function echo_ok () { + echo -e "[${GREEN}OK${NOCOLOR}] $1" +} + +function echo_fail () { + echo -e "[${GREEN}ERROR${NOCOLOR}] $1" +} + +function echo_warn () { + echo -e "[${YELLOW}WARN${NOCOLOR}] $1" +} + +function echo_info () { + echo -e "[${BLUE}INFO${NOCOLOR}] $1" +} + + diff --git a/ipa.sh b/ipa.sh index 2f0d5bc..645d8b2 100755 --- a/ipa.sh +++ b/ipa.sh @@ -1,25 +1,5 @@ #!/bin/bash -# ENVIRONMENT VARIABLES: -# -# WORKSPACE Automatically defined by Hudson. -# HUDSON_NODE_HOME Home directory of Hudson user on current node. -# KEYCHAIN_PASSWORD Password to unlock the OS X keychain tools. Most -# CONFIG Environment e.g. development or production -# Config specific variables: -# -# SDK Name of the ios SDK, i.e. 'iphoneos'. -# CONFIGURATION Name of the Xcode configuration, i.e. 'Release' -# or 'Debug'. -# DISTRIBUTION_CERTIFICATE Name of the distribution certificate, i.e. -# 'iPhone Distribution: Your Company Pty Ltd'. -# PROVISIONING_PROFILE_FILE_NAME File name of the provisioning profile inside the -# season project's `deploy/ios/profiles` directory. -# PROVISIONING_PROFILE_ID Unique ID of provisioning profile of the form -# xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx. -# BUNDLE_IDENTIFIER_IOS Bundle identifier to name the ipa with. -# PRODUCT_NAME Display name of the application. - function fail() { echo "FAILED: $@" >&2 exit 1 diff --git a/sign_ipa.sh b/sign_ipa.sh index a4e5a90..5c081a1 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -1,25 +1,5 @@ #!/bin/bash -# ENVIRONMENT VARIABLES: -# -# WORKSPACE Automatically defined by Hudson. -# HUDSON_NODE_HOME Home directory of Hudson user on current node. -# KEYCHAIN_PASSWORD Password to unlock the OS X keychain tools. Most -# CONFIG Environment e.g. development or production -# Config specific variables: -# -# SDK Name of the ios SDK, i.e. 'iphoneos'. -# CONFIGURATION Name of the Xcode configuration, i.e. 'Release' -# or 'Debug'. -# DISTRIBUTION_CERTIFICATE Name of the distribution certificate, i.e. -# 'iPhone Distribution: Your Company Pty Ltd'. -# PROVISIONING_PROFILE_FILE_NAME File name of the provisioning profile inside the -# season project's `deploy/ios/profiles` directory. -# PROVISIONING_PROFILE_ID Unique ID of provisioning profile of the form -# xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx. -# BUNDLE_IDENTIFIER_IOS Bundle identifier to name the ipa with. -# PRODUCT_NAME Display name of the application. - function fail() { echo "FAILED: $@" >&2 exit 1 -- GitLab From 4b61c47a970327048fe09698a9b6e29ba5c95cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 16:44:22 +0100 Subject: [PATCH 32/67] WUP --- include/funcs.sh | 39 ++++++++++++++++++--- sign.sh | 90 ++++++------------------------------------------ sign_ipa.sh | 57 +++++++++--------------------- 3 files changed, 61 insertions(+), 125 deletions(-) diff --git a/include/funcs.sh b/include/funcs.sh index 0d9e1f4..a5a7cc4 100644 --- a/include/funcs.sh +++ b/include/funcs.sh @@ -55,6 +55,26 @@ function setupIOSProvisioningProfiles { fi } +# Configure config for JS project +function configureJavascript { + cd $WORKSPACE + if [ -f "deploy/configs/$CONFIG.json" ] + then + # Configure project with JSON configs -- deprecated variant + echo_warn "Deprecation warning: App configuration using JSON configs is deprecated." + cp "deploy/configs/$CONFIG.json" src/config/config.json + sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json + elif [ -f "deploy/configs/$CONFIG.js" ] + then + # Configure project with JS configs + cp "deploy/configs/$CONFIG.js" src/conf.js + sed -i '' "s/buildVersion:.*/buildVersion: '${BUILD_NUMBER}.${BRANCH}',/g" src/conf.js + else + echo_fail "No valid configuration found for environment $CONFIG in deploy/config/" + exit 1 + fi +} + # Native build Cache related Functions function getCacheFilename { local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') @@ -66,11 +86,19 @@ function getCacheFilename { function saveCache { cd $CORDOVA_APP_DIR/platforms_release - tar -cvzf $(getCacheFilename) . + tar -czf $(getCacheFilename) . + cd - +} + +function restoreCache { + mkdir -p $CORDOVA_APP_DIR/platforms_release + cd $CORDOVA_APP_DIR/platforms_release + tar -zxf $(getCacheFilename) cd - } +# Utility functions function fail() { echo_fail "$@" >&2 exit 1 @@ -81,22 +109,23 @@ RED="\033[1;31m" BLUE="\033[1;34m" GREEN="\033[1;32m" YELLOW="\033[1;93m" +WHITE="\033[1;97m" NOCOLOR="\033[0m" function echo_ok () { - echo -e "[${GREEN}OK${NOCOLOR}] $1" + echo -e "[${GREEN}OK${NOCOLOR}] ${WHITE}$1${NOCOLOR}" } function echo_fail () { - echo -e "[${GREEN}ERROR${NOCOLOR}] $1" + echo -e "[${GREEN}ERROR${NOCOLOR}] ${WHITE}$1${NOCOLOR}" } function echo_warn () { - echo -e "[${YELLOW}WARN${NOCOLOR}] $1" + echo -e "[${YELLOW}WARN${NOCOLOR}] ${WHITE}$1${NOCOLOR}" } function echo_info () { - echo -e "[${BLUE}INFO${NOCOLOR}] $1" + echo -e "[${BLUE}INFO${NOCOLOR}] ${WHITE}$1${NOCOLOR}" } diff --git a/sign.sh b/sign.sh index 2d6b391..fcd6355 100755 --- a/sign.sh +++ b/sign.sh @@ -19,52 +19,8 @@ # documentation in ipa.sh for further information on environment # variables required for building and publishing the ipa file. -RED="\033[1;31m" -GREEN="\033[1;32m" -YELLOW="\033[1;93m" -NOCOLOR="\033[0m" - -function echo_ok () { - echo -e "[${GREEN}OK${NOCOLOR}] $1" -} - -function echo_fail () { - echo -e "[${GREEN}ERROR${NOCOLOR}] $1" -} - -function echo_warn () { - echo -e "[${YELLOW}WARN${NOCOLOR}] $1" -} - - - -# Output every command and fail if any command fails -set -ex -export SHELLDIR=$(dirname $0) -export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) -export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms_release -export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android -export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ -export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') - - -# Restore cache -function getCacheFilename { - local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') - local DIR_KEY=$CONFIG-$DIR_HASH - local CACHE_DIR=/Users/apfel/buildcache/ - local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz - echo "$CACHE_FILE" -} - -function restoreCache { - mkdir -p $CORDOVA_APP_DIR/platforms_release - cd $CORDOVA_APP_DIR/platforms_release - tar -zxvf $(getCacheFilename) - cd - -} +source $(dirname $0)/include/env.sh +source $(dirname $0)/include/funcs.sh CACHE_FILE=$(getCacheFilename) if [ -f "$CACHE_FILE" ]; then @@ -75,49 +31,23 @@ else exit 1 fi -# Load configurations -[ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" -[ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" +echo_info "Load configuration for current env" +loadDeployConfiguration -cd $WORKSPACE -if [ -f "deploy/configs/$CONFIG.json" ] -then - # Configure project with JSON configs -- deprecated variant - echo_warn "Deprecation warning: App configuration using JSON configs is deprecated." - cp "deploy/configs/$CONFIG.json" src/config/config.json - sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json -elif [ -f "deploy/configs/$CONFIG.js" ] -then - # Configure project with JS configs - cp "deploy/configs/$CONFIG.js" src/conf.js - sed -i '' "s/buildVersion:.*/buildVersion: '${BUILD_NUMBER}.${BRANCH}',/g" src/conf.js -else - echo_fail "No valid configuration found for environment $CONFIG in deploy/config/" - exit 1 -fi - -export PATH=$PATH:/opt/local/bin -export LANG=de_DE.UTF-8 - -# Export deploy config for ipa script -export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ - PROVISIONING_PROFILE_FILE_NAME PROVISIONING_PROFILE_ID \ - WIDGET_PROVISIONING_PROFILE_FILE_NAME WIDGET_PROVISIONING_PROFILE_ID \ - BUNDLE_IDENTIFIER PRODUCT_NAME APP_NAME \ - KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR +echo_info "Set JS config for env '$CONFIG'" +configureJavascript - -# Build JS +echo_info "Build JS project" node_modules/.bin/webpack --config webpack.prod.config.js - +echo_info "Copy JS build to native projects and sign" cd $CORDOVA_APP_DIR - if [ "$BUILD_IPA" == 'true' ]; then cd $CORDOVA_APP_DIR source $SHELLDIR/sign_ipa.sh + echo_info "Submit IPA" bundle exec rake app_distributor:submit:ipa fi @@ -126,5 +56,7 @@ if [ "$BUILD_APK" == 'true' ]; then cd $CORDOVA_APP_DIR source $SHELLDIR/sign_apk.sh + echo_info "Submit APK" bundle exec rake app_distributor:submit:apk fi + diff --git a/sign_ipa.sh b/sign_ipa.sh index 5c081a1..7e01fd4 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -1,58 +1,33 @@ #!/bin/bash -function fail() { - echo "FAILED: $@" >&2 - exit 1 -} - -set -ex +source $(dirname $0)/include/env.sh +source $(dirname $0)/include/funcs.sh cd $IOS_CONTAINER -security unlock-keychain -p $KEYCHAIN_PASSWORD -agvtool new-version -all $BUILD_NUMBER - -if [ -n "$BUNDLE_VERSION" ]; then - agvtool new-marketing-version $BUNDLE_VERSION -fi - -PROVISIONING_PROFILES_DIR=$HOME"/Library/MobileDevice/Provisioning Profiles/" -# Copy provisioning profile to provisioning profiles dir -[ -d "$PROVISIONING_PROFILES_DIR" ] || mkdir -p "$PROVISIONING_PROFILES_DIR" -provisioning_profiles_source_dir="$WORKSPACE/deploy/ios/profiles/" - -# Copy main profile -provisioning_profile_source="$provisioning_profiles_source_dir/$PROVISIONING_PROFILE_FILE_NAME" -[ -f "$provisioning_profile_source" ] || fail "Profile '$PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" -provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$PROVISIONING_PROFILE_ID.mobileprovision" -[ -f "$provisioning_profile_file_name" ] || cp "$provisioning_profile_source" "$provisioning_profile_file_name" - - -#Optional copy widget profile -if [ -n "$WIDGET_PROVISIONING_PROFILE_FILE_NAME" ]; then - echo "WIDGET: $WIDGET_PROVISIONING_PROFILE_FILE_NAME" - widget_provisioning_profile_source="$provisioning_profiles_source_dir/$WIDGET_PROVISIONING_PROFILE_FILE_NAME" - [ -f "$widget_provisioning_profile_source" ] || fail "Widget Profile '$WIDGET_PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" - widget_provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$WIDGET_PROVISIONING_PROFILE_ID.mobileprovision" - [ -f "$widget_provisioning_profile_file_name" ] || cp "$widget_provisioning_profile_source" "$widget_provisioning_profile_file_name" -fi +cd $CORDOVA_PLATFORM_RELEASE_DIR/ios -scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') +echo_info "Copy provisioning profiles for $CONFIG" +setupIOSProvisioningProfiles +echo_ok "Done." +scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app cp -r ../../www/* $APP_FOLDER/www/ mkdir -p export +echo_info "ExportArchive for IPA" xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${scheme_name}.xcarchive -exportOptionsPlist "${provisioning_profiles_source_dir}/${CONFIG}-export-options.plist" -exportPath "export/" + # Copy app folder containing Info.plist needed for app distributor to export directory cp -r $APP_FOLDER export/ -# Build simulator image -#cd $IOS_CONTAINER -#xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ -# CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" +echo_info "Build simulator image" +cd $IOS_CONTAINER +xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ + CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" -#simulator_directory="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" -#simulator_file_name="$scheme_name.zip" -#zip -r "export/$simulator_file_name" $simulator_directory +simulator_directory="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" +simulator_file_name="$scheme_name.zip" +zip -r "export/$simulator_file_name" $simulator_directory -- GitLab From 79059377586bca51acdcafc286cfb1de81878285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 17:12:57 +0100 Subject: [PATCH 33/67] WIP --- build_ipa.sh | 3 --- include/env.sh | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/build_ipa.sh b/build_ipa.sh index aedddd2..cccecdd 100755 --- a/build_ipa.sh +++ b/build_ipa.sh @@ -1,8 +1,5 @@ #!/bin/bash -source $(dirname $0)/include/env.sh -source $(dirname $0)/include/funcs.sh - cd $IOS_CONTAINER security unlock-keychain -p $KEYCHAIN_PASSWORD diff --git a/include/env.sh b/include/env.sh index 060df48..fc58474 100644 --- a/include/env.sh +++ b/include/env.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Output every command and fail if any command fails +set -ex + + export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) @@ -24,7 +28,4 @@ function loadDeployConfiguration { KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR } -# Output every command and fail if any command fails -set -ex - -- GitLab From 3a3eb30d6388c13d9f2359fb609de7416c6eb801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 17:41:05 +0100 Subject: [PATCH 34/67] WIP --- sign_ipa.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sign_ipa.sh b/sign_ipa.sh index 7e01fd4..b26d857 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -1,9 +1,5 @@ #!/bin/bash -source $(dirname $0)/include/env.sh -source $(dirname $0)/include/funcs.sh - -cd $IOS_CONTAINER cd $CORDOVA_PLATFORM_RELEASE_DIR/ios echo_info "Copy provisioning profiles for $CONFIG" -- GitLab From 05d0f5be532a2592bc21349e85569b64d2a5acd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 17:58:43 +0100 Subject: [PATCH 35/67] WIP --- sign_ipa.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sign_ipa.sh b/sign_ipa.sh index b26d857..35e36ea 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -20,7 +20,7 @@ xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${ cp -r $APP_FOLDER export/ echo_info "Build simulator image" -cd $IOS_CONTAINER +cd $CORDOVA_PLATFORM_RELEASE_DIR/ios xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" -- GitLab From 6f459706c44058a291760aef2acce15f0deadaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 18:12:07 +0100 Subject: [PATCH 36/67] WIP --- build_ipa.sh | 5 +++++ sign_ipa.sh | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build_ipa.sh b/build_ipa.sh index cccecdd..993d9ad 100755 --- a/build_ipa.sh +++ b/build_ipa.sh @@ -25,4 +25,9 @@ mkdir export echo_info "Building IOS archive..." xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -configuration $CONFIGURATION -archivePath $(pwd)/build/${scheme_name}.xcarchive -sdk iphoneos -scheme $scheme_name archive PROVISIONING_PROFILE=$PROVISIONING_PROFILE_ID WIDGET_PROVISIONING_PROFILE=$WIDGET_PROVISIONING_PROFILE_ID CODE_SIGN_IDENTITY="$DISTRIBUTION_CERTIFICATE" CODE_SIGN_STYLE="Manual" || fail "xcodebuild failed." +echo_info "Building simulator image..." +cd $CORDOVA_PLATFORM_RELEASE_DIR/ios +xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ + CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" + echo_ok "Done." diff --git a/sign_ipa.sh b/sign_ipa.sh index 35e36ea..2c2c3d1 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -8,6 +8,7 @@ echo_ok "Done." scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') +echo_info "Copy JS build into app archive..." APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app cp -r ../../www/* $APP_FOLDER/www/ @@ -19,11 +20,11 @@ xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${ # Copy app folder containing Info.plist needed for app distributor to export directory cp -r $APP_FOLDER export/ -echo_info "Build simulator image" -cd $CORDOVA_PLATFORM_RELEASE_DIR/ios -xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ - CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" +echo_info "Copy JS build into app archive..." +SIM_FOLDER="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" +cp -r ../../www/* $SIM_FOLDER/www/ + +SIM_FILE_NAME="$scheme_name.zip" +zip -r "export/$SIM_FILE_NAME" $SIM_FOLDER -simulator_directory="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" -simulator_file_name="$scheme_name.zip" -zip -r "export/$simulator_file_name" $simulator_directory +echo_ok "Done." -- GitLab From cdf9b54c7b80080e18077f5952c9f4c6a9e11a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 18:49:08 +0100 Subject: [PATCH 37/67] fix dir --- build_ipa.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_ipa.sh b/build_ipa.sh index 993d9ad..7e43f54 100755 --- a/build_ipa.sh +++ b/build_ipa.sh @@ -26,7 +26,7 @@ echo_info "Building IOS archive..." xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -configuration $CONFIGURATION -archivePath $(pwd)/build/${scheme_name}.xcarchive -sdk iphoneos -scheme $scheme_name archive PROVISIONING_PROFILE=$PROVISIONING_PROFILE_ID WIDGET_PROVISIONING_PROFILE=$WIDGET_PROVISIONING_PROFILE_ID CODE_SIGN_IDENTITY="$DISTRIBUTION_CERTIFICATE" CODE_SIGN_STYLE="Manual" || fail "xcodebuild failed." echo_info "Building simulator image..." -cd $CORDOVA_PLATFORM_RELEASE_DIR/ios +cd $IOS_CONTAINER xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" -- GitLab From bf2ce68d5d691f421d245796b4bec10deb9105d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Thu, 21 Mar 2019 18:49:26 +0100 Subject: [PATCH 38/67] seperate js and native deploy files --- include/env.sh | 7 +++++-- include/funcs.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/env.sh b/include/env.sh index fc58474..60958d3 100644 --- a/include/env.sh +++ b/include/env.sh @@ -6,6 +6,9 @@ set -ex export SHELLDIR=$(dirname $0) export WORKSPACE=$(pwd) +export DEPLOY_DIR=$WORKSPACE/deploy +export DEPLOY_NATIVE_DIR=$DEPLOY_DIR/native +export DEPLOY_JS_DIR=$DEPLOY_DIR/js export CORDOVA_APP_DIR=$(ls -d -1 $WORKSPACE/cordova/*) export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms export CORDOVA_PLATFORM_RELEASE_DIR=$CORDOVA_APP_DIR/platforms_release @@ -17,8 +20,8 @@ export PATH=$PATH:/opt/local/bin export LANG=de_DE.UTF-8 function loadDeployConfiguration { - [ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" - [ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" + [ -f "$DEPLOY_NATIVE_DIR/base.config" ] && source "$DEPLOY_NATIVE_DIR/base.config" + [ -f "$DEPLOY_NATIVE_DIR/configs/$CONFIG.config" ] && source "$DEPLOY_NATIVE_DIR/configs/$CONFIG.config" # Export deploy config for dependend scripts export CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ diff --git a/include/funcs.sh b/include/funcs.sh index a5a7cc4..843ae3f 100644 --- a/include/funcs.sh +++ b/include/funcs.sh @@ -12,7 +12,7 @@ function replaceConfigXmlVars { # Copy environment specific resource-files to cordova function copyResourceFiles { - local RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" + local RESOURCES_DIR="$DEPLOY_NATIVE_DIR/resource-files/" local RESOURCES_FILES="$RESOURCES_DIR*.$CONFIG" if [ -d "$RESOURCES_DIR" ]; then @@ -37,7 +37,7 @@ function setupIOSProvisioningProfiles { PROVISIONING_PROFILES_DIR=$HOME"/Library/MobileDevice/Provisioning Profiles/" # Copy provisioning profile to provisioning profiles dir [ -d "$PROVISIONING_PROFILES_DIR" ] || mkdir -p "$PROVISIONING_PROFILES_DIR" - provisioning_profiles_source_dir="$WORKSPACE/deploy/ios/profiles/" + provisioning_profiles_source_dir="$DEPLOY_NATIVE_DIR/ios/profiles/" # Copy main profile provisioning_profile_source="$provisioning_profiles_source_dir/$PROVISIONING_PROFILE_FILE_NAME" @@ -58,19 +58,19 @@ function setupIOSProvisioningProfiles { # Configure config for JS project function configureJavascript { cd $WORKSPACE - if [ -f "deploy/configs/$CONFIG.json" ] + if [ -f "$DEPLOY_JS_DIR/$CONFIG.json" ] then # Configure project with JSON configs -- deprecated variant echo_warn "Deprecation warning: App configuration using JSON configs is deprecated." - cp "deploy/configs/$CONFIG.json" src/config/config.json + cp "$DEPLOY_JS_DIR/$CONFIG.json" src/config/config.json sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json - elif [ -f "deploy/configs/$CONFIG.js" ] + elif [ -f "$DEPLOY_JS_DIR/configs/$CONFIG.js" ] then # Configure project with JS configs - cp "deploy/configs/$CONFIG.js" src/conf.js + cp "$DEPLOY_JS_DIR/$CONFIG.js" src/conf.js sed -i '' "s/buildVersion:.*/buildVersion: '${BUILD_NUMBER}.${BRANCH}',/g" src/conf.js else - echo_fail "No valid configuration found for environment $CONFIG in deploy/config/" + echo_fail "No valid configuration found for environment $CONFIG in $DEPLOY_JS_DIR/" exit 1 fi } -- GitLab From 4cda31e3b94b92139eec0aa2a1edb20ad7e1f3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 09:42:28 +0100 Subject: [PATCH 39/67] change cache key --- build.sh | 3 +-- include/cache.sh | 24 +++++++++++++++++++++ include/funcs.sh | 55 ------------------------------------------------ include/index.sh | 7 ++++++ include/util.sh | 31 +++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 57 deletions(-) create mode 100644 include/cache.sh create mode 100644 include/index.sh create mode 100644 include/util.sh diff --git a/build.sh b/build.sh index 47e92f2..7160b0c 100755 --- a/build.sh +++ b/build.sh @@ -14,8 +14,7 @@ # documentation in include/env.sh for further information on environment # variables required for building and publishing -source $(dirname $0)/include/env.sh -source $(dirname $0)/include/funcs.sh +source $(dirname $0)/include/index.sh CACHE_FILE=$(getCacheFilename) if [ -f "$CACHE_FILE" ]; then diff --git a/include/cache.sh b/include/cache.sh new file mode 100644 index 0000000..5f64545 --- /dev/null +++ b/include/cache.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Native build Cache related Functions +function getCacheFilename { + local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) + # Cache key + local DIR_KEY=$APP_NAME-$CONFIG-$DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ + local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz + echo "$CACHE_FILE" +} + +function saveCache { + cd $CORDOVA_APP_DIR/platforms_release + tar -czf $(getCacheFilename) . + cd - +} + +function restoreCache { + mkdir -p $CORDOVA_APP_DIR/platforms_release + cd $CORDOVA_APP_DIR/platforms_release + tar -zxf $(getCacheFilename) + cd - +} diff --git a/include/funcs.sh b/include/funcs.sh index 843ae3f..be7d4d9 100644 --- a/include/funcs.sh +++ b/include/funcs.sh @@ -74,58 +74,3 @@ function configureJavascript { exit 1 fi } - -# Native build Cache related Functions -function getCacheFilename { - local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR | awk '{print $3}') - local DIR_KEY=$CONFIG-$DIR_HASH - local CACHE_DIR=/Users/apfel/buildcache/ - local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz - echo "$CACHE_FILE" -} - -function saveCache { - cd $CORDOVA_APP_DIR/platforms_release - tar -czf $(getCacheFilename) . - cd - -} - -function restoreCache { - mkdir -p $CORDOVA_APP_DIR/platforms_release - cd $CORDOVA_APP_DIR/platforms_release - tar -zxf $(getCacheFilename) - cd - -} - - -# Utility functions -function fail() { - echo_fail "$@" >&2 - exit 1 -} - -# Fancy console coloring -RED="\033[1;31m" -BLUE="\033[1;34m" -GREEN="\033[1;32m" -YELLOW="\033[1;93m" -WHITE="\033[1;97m" -NOCOLOR="\033[0m" - -function echo_ok () { - echo -e "[${GREEN}OK${NOCOLOR}] ${WHITE}$1${NOCOLOR}" -} - -function echo_fail () { - echo -e "[${GREEN}ERROR${NOCOLOR}] ${WHITE}$1${NOCOLOR}" -} - -function echo_warn () { - echo -e "[${YELLOW}WARN${NOCOLOR}] ${WHITE}$1${NOCOLOR}" -} - -function echo_info () { - echo -e "[${BLUE}INFO${NOCOLOR}] ${WHITE}$1${NOCOLOR}" -} - - diff --git a/include/index.sh b/include/index.sh new file mode 100644 index 0000000..bd11c4e --- /dev/null +++ b/include/index.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source $(dirname $0)/env.sh +source $(dirname $0)/util.sh +source $(dirname $0)/cache.sh +source $(dirname $0)/funcs.sh + diff --git a/include/util.sh b/include/util.sh new file mode 100644 index 0000000..20f6e3d --- /dev/null +++ b/include/util.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Utility functions +function fail() { + echo_fail "$@" >&2 + exit 1 +} + +# Fancy console coloring +RED="\033[1;31m" +BLUE="\033[1;34m" +GREEN="\033[1;32m" +YELLOW="\033[1;93m" +WHITE="\033[1;97m" +NOCOLOR="\033[0m" + +function echo_ok () { + echo -e "[${GREEN}OK${NOCOLOR}] ${WHITE}$1${NOCOLOR}" +} + +function echo_fail () { + echo -e "[${GREEN}ERROR${NOCOLOR}] ${WHITE}$1${NOCOLOR}" +} + +function echo_warn () { + echo -e "[${YELLOW}WARN${NOCOLOR}] ${WHITE}$1${NOCOLOR}" +} + +function echo_info () { + echo -e "[${BLUE}INFO${NOCOLOR}] ${WHITE}$1${NOCOLOR}" +} -- GitLab From 90c5bbf483f7b5153277f470001c88b178915bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 09:47:11 +0100 Subject: [PATCH 40/67] fix include path --- include/index.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/index.sh b/include/index.sh index bd11c4e..7ed9a11 100644 --- a/include/index.sh +++ b/include/index.sh @@ -1,7 +1,8 @@ #!/bin/bash -source $(dirname $0)/env.sh -source $(dirname $0)/util.sh -source $(dirname $0)/cache.sh -source $(dirname $0)/funcs.sh +INCLUDE_DIR=$(dirname $0)/include +source $INCLUDE_DIR/env.sh +source $INCLUDE_DIR/util.sh +source $INCLUDE_DIR/cache.sh +source $INCLUDE_DIR/funcs.sh -- GitLab From 28014160a21f3df83b63e2626212c531f871b8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 12:15:30 +0100 Subject: [PATCH 41/67] fix include --- sign.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sign.sh b/sign.sh index fcd6355..37a0790 100755 --- a/sign.sh +++ b/sign.sh @@ -19,8 +19,7 @@ # documentation in ipa.sh for further information on environment # variables required for building and publishing the ipa file. -source $(dirname $0)/include/env.sh -source $(dirname $0)/include/funcs.sh +source $(dirname $0)/include/index.sh CACHE_FILE=$(getCacheFilename) if [ -f "$CACHE_FILE" ]; then -- GitLab From a01cf07d1147534026bd98f2a459c95e6111b130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 12:24:28 +0100 Subject: [PATCH 42/67] loadConfigs first --- build.sh | 3 --- include/env.sh | 3 ++- include/index.sh | 2 +- sign.sh | 3 --- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index 7160b0c..4d44d65 100755 --- a/build.sh +++ b/build.sh @@ -23,9 +23,6 @@ if [ -f "$CACHE_FILE" ]; then fi echo_ok "No native build cache '$CACHE_FILE' found. Building..." -echo_info "Load configuration for current env" -loadDeployConfiguration - echo_info "Copy resource-files" copyResourceFiles diff --git a/include/env.sh b/include/env.sh index 60958d3..1985a34 100644 --- a/include/env.sh +++ b/include/env.sh @@ -31,4 +31,5 @@ function loadDeployConfiguration { KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR } - +echo_info "Load configuration for current env '$CONFIG'..." +loadDeployConfiguration diff --git a/include/index.sh b/include/index.sh index 7ed9a11..ac571a1 100644 --- a/include/index.sh +++ b/include/index.sh @@ -1,8 +1,8 @@ #!/bin/bash INCLUDE_DIR=$(dirname $0)/include -source $INCLUDE_DIR/env.sh source $INCLUDE_DIR/util.sh +source $INCLUDE_DIR/env.sh source $INCLUDE_DIR/cache.sh source $INCLUDE_DIR/funcs.sh diff --git a/sign.sh b/sign.sh index 37a0790..ec73dd6 100755 --- a/sign.sh +++ b/sign.sh @@ -30,9 +30,6 @@ else exit 1 fi -echo_info "Load configuration for current env" -loadDeployConfiguration - echo_info "Set JS config for env '$CONFIG'" configureJavascript -- GitLab From ecaca183b23473e69a7a3bbaa5b893f426e3888e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 13:29:23 +0100 Subject: [PATCH 43/67] call early and store cache file --- include/cache.sh | 14 ++++++++------ include/index.sh | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/cache.sh b/include/cache.sh index 5f64545..f6958df 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -2,12 +2,14 @@ # Native build Cache related Functions function getCacheFilename { - local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) - # Cache key - local DIR_KEY=$APP_NAME-$CONFIG-$DIR_HASH - local CACHE_DIR=/Users/apfel/buildcache/ - local CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz - echo "$CACHE_FILE" + if [ -z "$NATIVE_CACHE_FILE" ]; then + local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) + # Cache key + local DIR_KEY=$APP_NAME-$CONFIG-$DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ + export NATIVE_CACHE_FILE=E$CACHE_DIR/$DIR_KEY.tgz + fi + echo "$NATIVE_CACHE_FILE" } function saveCache { diff --git a/include/index.sh b/include/index.sh index ac571a1..1bb5e6d 100644 --- a/include/index.sh +++ b/include/index.sh @@ -6,3 +6,7 @@ source $INCLUDE_DIR/env.sh source $INCLUDE_DIR/cache.sh source $INCLUDE_DIR/funcs.sh +# Call function early once early to prevent +# changes on the filesystem that may affect the +# cache_key. +getNativeCacheFile -- GitLab From 84cf142a8a9fe3a01c929021308b807283db29bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 13:44:09 +0100 Subject: [PATCH 44/67] add ci-module version number to cache key --- include/cache.sh | 7 ++++++- include/env.sh | 1 + include/index.sh | 5 ----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/cache.sh b/include/cache.sh index f6958df..460cf0b 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -5,7 +5,7 @@ function getCacheFilename { if [ -z "$NATIVE_CACHE_FILE" ]; then local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) # Cache key - local DIR_KEY=$APP_NAME-$CONFIG-$DIR_HASH + local DIR_KEY=$APP_NAME-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH local CACHE_DIR=/Users/apfel/buildcache/ export NATIVE_CACHE_FILE=E$CACHE_DIR/$DIR_KEY.tgz fi @@ -24,3 +24,8 @@ function restoreCache { tar -zxf $(getCacheFilename) cd - } + +# Call function early once early to prevent +# changes on the filesystem that may affect the +# cache_key. +getCacheFilename diff --git a/include/env.sh b/include/env.sh index 1985a34..a6318bb 100644 --- a/include/env.sh +++ b/include/env.sh @@ -18,6 +18,7 @@ export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') export PATH=$PATH:/opt/local/bin export LANG=de_DE.UTF-8 +export CI_MODULE_VERSION=$(node -p "require('./package.json').version") function loadDeployConfiguration { [ -f "$DEPLOY_NATIVE_DIR/base.config" ] && source "$DEPLOY_NATIVE_DIR/base.config" diff --git a/include/index.sh b/include/index.sh index 1bb5e6d..26b42f2 100644 --- a/include/index.sh +++ b/include/index.sh @@ -5,8 +5,3 @@ source $INCLUDE_DIR/util.sh source $INCLUDE_DIR/env.sh source $INCLUDE_DIR/cache.sh source $INCLUDE_DIR/funcs.sh - -# Call function early once early to prevent -# changes on the filesystem that may affect the -# cache_key. -getNativeCacheFile -- GitLab From 629771762b1eb18c135875e58daffc8cb7514cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 13:47:53 +0100 Subject: [PATCH 45/67] fix path --- include/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/env.sh b/include/env.sh index a6318bb..a86ce01 100644 --- a/include/env.sh +++ b/include/env.sh @@ -18,7 +18,7 @@ export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') export PATH=$PATH:/opt/local/bin export LANG=de_DE.UTF-8 -export CI_MODULE_VERSION=$(node -p "require('./package.json').version") +export CI_MODULE_VERSION=$(node -p "require('$SHELL_DIR').version") function loadDeployConfiguration { [ -f "$DEPLOY_NATIVE_DIR/base.config" ] && source "$DEPLOY_NATIVE_DIR/base.config" -- GitLab From 6bd7f2478a6d1225ae4501a4aac93a1663d9c075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 13:53:25 +0100 Subject: [PATCH 46/67] fix --- include/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/env.sh b/include/env.sh index a86ce01..40b438a 100644 --- a/include/env.sh +++ b/include/env.sh @@ -18,7 +18,7 @@ export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') export PATH=$PATH:/opt/local/bin export LANG=de_DE.UTF-8 -export CI_MODULE_VERSION=$(node -p "require('$SHELL_DIR').version") +export CI_MODULE_VERSION=$(node -p "require('$SHELLDIR/package.json').version") function loadDeployConfiguration { [ -f "$DEPLOY_NATIVE_DIR/base.config" ] && source "$DEPLOY_NATIVE_DIR/base.config" -- GitLab From c264817b8edab33ef5a1d3517af7fcad90b6eac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 13:56:09 +0100 Subject: [PATCH 47/67] fix --- include/cache.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cache.sh b/include/cache.sh index 460cf0b..19bf308 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -7,7 +7,7 @@ function getCacheFilename { # Cache key local DIR_KEY=$APP_NAME-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH local CACHE_DIR=/Users/apfel/buildcache/ - export NATIVE_CACHE_FILE=E$CACHE_DIR/$DIR_KEY.tgz + export NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz fi echo "$NATIVE_CACHE_FILE" } -- GitLab From adde45160104b50a7d072d3e8b7405332dba153e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 16:12:53 +0100 Subject: [PATCH 48/67] Scope cache for platform --- build.sh | 17 ++++++------ include/cache.sh | 70 +++++++++++++++++++++++++++++++++++++++--------- sign.sh | 10 +++---- sign_ipa.sh | 4 +-- 4 files changed, 73 insertions(+), 28 deletions(-) diff --git a/build.sh b/build.sh index 4d44d65..72be79f 100755 --- a/build.sh +++ b/build.sh @@ -16,12 +16,12 @@ source $(dirname $0)/include/index.sh -CACHE_FILE=$(getCacheFilename) -if [ -f "$CACHE_FILE" ]; then - echo_ok "Native build cache '$CACHE_FILE' found. Nothing to do. Exiting..." +CACHES_AVAILABLE=$(cacheAvailableForTargets) +if [ "$CACHES_AVAILABLE" == "true" ]; then + echo_ok "Native build caches found. Nothing to do. Exiting..." exit 0 fi -echo_ok "No native build cache '$CACHE_FILE' found. Building..." +echo_ok "Not all native build caches found. Building..." echo_info "Copy resource-files" copyResourceFiles @@ -33,7 +33,7 @@ rm -rf platforms/ios mkdir -p www mkdir -p platforms_release -if [ "$BUILD_IPA" == 'true' ]; then +if [ "$BUILD_IPA" == "true" ] && [ "$IPA_CACHE_AVAILABLE" != "true" ]; then echo_info "Building IOS project" rm -rf plugins/* replaceConfigXmlVars @@ -46,9 +46,10 @@ if [ "$BUILD_IPA" == 'true' ]; then cd $CORDOVA_APP_DIR mv platforms/ios platforms_release/ echo_ok "IOS project build." + $(saveCache "ios") fi -if [ "$BUILD_APK" == 'true' ]; then +if [ "$BUILD_APK" == "true" ] && [ "$APK_CACHE_AVAILABLE" != "true" ]; then echo_info "Building Android project" rm -rf plugins/* git checkout config.xml @@ -62,9 +63,7 @@ if [ "$BUILD_APK" == 'true' ]; then cd $CORDOVA_APP_DIR mv platforms/android platforms_release/ echo_ok "Android project build." + $(saveCache "android") fi -echo_info "Gzip and save intermediate results." -saveCache - echo_ok "Done." diff --git a/include/cache.sh b/include/cache.sh index 19bf308..2f72705 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -1,31 +1,77 @@ #!/bin/bash # Native build Cache related Functions -function getCacheFilename { + +function cacheAvailableForTargets () { + local available="true" + if [ "$BUILD_IPA" == "true" ]; then + if [ ! -f "$IPA_CACHE" ]; then + available="false" + export IPA_CACHE_AVAILABLE="false" + echo_info "No native build cache for IPA: '$IPA_CACHE' found." + else + echo_ok "Native build cache for IPA: '$IPA_CACHE' found." + fi + fi + if [ "$BUILD_APK" == "true" ]; then + if [ ! -f "$APK_CACHE" ]; then + available="false" + export APK_CACHE_AVAILABLE="false" + echo_info "No native build cache for APK: '$APK_CACHE' found." + else + echo_ok "Native build cache for IPA: '$APK_CACHE' found." + fi + fi + echo "$available" +} + +function getCacheFilename () { + if [ -z "$1" ]; then + echo_fail "Platform not given." + exit 1 + fi + local PLATFORM=$1 if [ -z "$NATIVE_CACHE_FILE" ]; then local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) # Cache key - local DIR_KEY=$APP_NAME-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH + local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH local CACHE_DIR=/Users/apfel/buildcache/ - export NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz + local NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz fi echo "$NATIVE_CACHE_FILE" } -function saveCache { - cd $CORDOVA_APP_DIR/platforms_release - tar -czf $(getCacheFilename) . +function saveCache () { + if [ -z "$1" ]; then + echo_fail "Platform not given." + exit 1 + fi + local PLATFORM=$1 + cd $CORDOVA_APP_DIR/platforms_release/$PLATFORM + tar -czf $(getCacheFilename $PLATFORM) . cd - + echo_ok "Saved $PLATFORM cache." } -function restoreCache { - mkdir -p $CORDOVA_APP_DIR/platforms_release - cd $CORDOVA_APP_DIR/platforms_release - tar -zxf $(getCacheFilename) - cd - +function restoreCaches { + if [ -f "$IPA_CACHE"]; then + mkdir -p $CORDOVA_APP_DIR/platforms_release/ios + cd $CORDOVA_APP_DIR/platforms_release/ios + tar -zxf $IPA_CACHE + cd - + echo_ok "Restored IOS cache: '$IPA_CACHE'" + fi + if [ -f "$APK_CACHE"]; then + mkdir -p $CORDOVA_APP_DIR/platforms_release/android + cd $CORDOVA_APP_DIR/platforms_release/android + tar -zxf $APK_CACHE + cd - + echo_ok "Restored Android cache: '$APK_CACHE'" + fi } # Call function early once early to prevent # changes on the filesystem that may affect the # cache_key. -getCacheFilename +export IPA_CACHE=$(getCacheFilename "ios") +export APK_CACHE=$(getCacheFilename "android") diff --git a/sign.sh b/sign.sh index ec73dd6..2ba8e9f 100755 --- a/sign.sh +++ b/sign.sh @@ -21,12 +21,12 @@ source $(dirname $0)/include/index.sh -CACHE_FILE=$(getCacheFilename) -if [ -f "$CACHE_FILE" ]; then - echo_ok "Native build cache '$CACHE_FILE' found. Continue..." - restoreCache +CACHES_AVAILABLE=$(cacheAvailableForTargets) +if [ "$CACHES_AVAILABLE" == "true" ]; then + echo_ok "Native build caches found. Continue..." + restoreCaches else - echo_fail "No native build cache '$CACHE_FILE' found. This should not happen!" + echo_fail "Not all native build caches found. This should not happen!" exit 1 fi diff --git a/sign_ipa.sh b/sign_ipa.sh index 2c2c3d1..13d9f49 100755 --- a/sign_ipa.sh +++ b/sign_ipa.sh @@ -20,11 +20,11 @@ xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${ # Copy app folder containing Info.plist needed for app distributor to export directory cp -r $APP_FOLDER export/ -echo_info "Copy JS build into app archive..." +echo_info "Copy JS build into simulator..." SIM_FOLDER="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" cp -r ../../www/* $SIM_FOLDER/www/ SIM_FILE_NAME="$scheme_name.zip" -zip -r "export/$SIM_FILE_NAME" $SIM_FOLDER +zip -qr "export/$SIM_FILE_NAME" $SIM_FOLDER echo_ok "Done." -- GitLab From 60331de29a24d10f0a5469e2c6637b28011e488c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 16:45:47 +0100 Subject: [PATCH 49/67] fix return values --- build.sh | 4 ++-- include/cache.sh | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index 72be79f..3d098a4 100755 --- a/build.sh +++ b/build.sh @@ -46,7 +46,7 @@ if [ "$BUILD_IPA" == "true" ] && [ "$IPA_CACHE_AVAILABLE" != "true" ]; then cd $CORDOVA_APP_DIR mv platforms/ios platforms_release/ echo_ok "IOS project build." - $(saveCache "ios") + saveCache "ios" fi if [ "$BUILD_APK" == "true" ] && [ "$APK_CACHE_AVAILABLE" != "true" ]; then @@ -63,7 +63,7 @@ if [ "$BUILD_APK" == "true" ] && [ "$APK_CACHE_AVAILABLE" != "true" ]; then cd $CORDOVA_APP_DIR mv platforms/android platforms_release/ echo_ok "Android project build." - $(saveCache "android") + saveCache "android" fi echo_ok "Done." diff --git a/include/cache.sh b/include/cache.sh index 2f72705..2fae20a 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -8,18 +8,12 @@ function cacheAvailableForTargets () { if [ ! -f "$IPA_CACHE" ]; then available="false" export IPA_CACHE_AVAILABLE="false" - echo_info "No native build cache for IPA: '$IPA_CACHE' found." - else - echo_ok "Native build cache for IPA: '$IPA_CACHE' found." fi fi if [ "$BUILD_APK" == "true" ]; then if [ ! -f "$APK_CACHE" ]; then available="false" export APK_CACHE_AVAILABLE="false" - echo_info "No native build cache for APK: '$APK_CACHE' found." - else - echo_ok "Native build cache for IPA: '$APK_CACHE' found." fi fi echo "$available" -- GitLab From 2c0b0ea1d85a79ff0059636744bef47d965e7526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 17:01:35 +0100 Subject: [PATCH 50/67] fix cache key generation --- include/cache.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/cache.sh b/include/cache.sh index 2fae20a..aaecfc3 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -25,13 +25,13 @@ function getCacheFilename () { exit 1 fi local PLATFORM=$1 - if [ -z "$NATIVE_CACHE_FILE" ]; then - local DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) - # Cache key - local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH - local CACHE_DIR=/Users/apfel/buildcache/ - local NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz + if [ -z "$CACHE_DIR_HASH" ]; then + export CACHE_DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) fi + # Cache key + local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ + local NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz echo "$NATIVE_CACHE_FILE" } -- GitLab From 1b40df68bfb73d65fead865bfc1c849fc4d94c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 17:12:11 +0100 Subject: [PATCH 51/67] fix cache key generation --- include/cache.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cache.sh b/include/cache.sh index aaecfc3..00be256 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -30,7 +30,7 @@ function getCacheFilename () { fi # Cache key local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH - local CACHE_DIR=/Users/apfel/buildcache/ + local CACHE_DIR_HASH=/Users/apfel/buildcache/ local NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz echo "$NATIVE_CACHE_FILE" } -- GitLab From 3e96abe04a676902a91ea73c3ceb9cbbbf2f7922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 17:25:49 +0100 Subject: [PATCH 52/67] fix cache key generation --- include/cache.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cache.sh b/include/cache.sh index 00be256..5365587 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -29,8 +29,8 @@ function getCacheFilename () { export CACHE_DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) fi # Cache key - local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$DIR_HASH - local CACHE_DIR_HASH=/Users/apfel/buildcache/ + local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$CACHE_DIR_HASH + local CACHE_DIR=/Users/apfel/buildcache/ local NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz echo "$NATIVE_CACHE_FILE" } -- GitLab From eb664b781856dd16e906ca78f3b038a9f72a3ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 18:01:11 +0100 Subject: [PATCH 53/67] fix hash --- include/cache.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/cache.sh b/include/cache.sh index 5365587..8259d61 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -25,18 +25,19 @@ function getCacheFilename () { exit 1 fi local PLATFORM=$1 - if [ -z "$CACHE_DIR_HASH" ]; then - export CACHE_DIR_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) - fi # Cache key - local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$CACHE_DIR_HASH + local DIR_KEY=$APP_NAME-$PLATFORM-$CONFIG-$CI_MODULE_VERSION-$CACHE_HASH local CACHE_DIR=/Users/apfel/buildcache/ local NATIVE_CACHE_FILE=$CACHE_DIR/$DIR_KEY.tgz echo "$NATIVE_CACHE_FILE" } +function setCacheHash { + export CACHE_HASH=$(git ls-tree HEAD $CORDOVA_APP_DIR $DEPLOY_NATIVE_DIR | git hash-object --stdin) +} + function saveCache () { - if [ -z "$1" ]; then + if [ -z "$1" ]; then echo_fail "Platform not given." exit 1 fi @@ -67,5 +68,7 @@ function restoreCaches { # Call function early once early to prevent # changes on the filesystem that may affect the # cache_key. + +CACHE_HASH=getCacheHash export IPA_CACHE=$(getCacheFilename "ios") export APK_CACHE=$(getCacheFilename "android") -- GitLab From 422e8335a0623d491c3b593694752ceeed4c0202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 18:06:42 +0100 Subject: [PATCH 54/67] fix hash --- include/cache.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cache.sh b/include/cache.sh index 8259d61..fbe1e27 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -69,6 +69,6 @@ function restoreCaches { # changes on the filesystem that may affect the # cache_key. -CACHE_HASH=getCacheHash +setCacheHash export IPA_CACHE=$(getCacheFilename "ios") export APK_CACHE=$(getCacheFilename "android") -- GitLab From 2c539bcc3de1ad2a8420ea568090a31abf3cb8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 18:22:20 +0100 Subject: [PATCH 55/67] fix hash --- include/cache.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cache.sh b/include/cache.sh index fbe1e27..fd411e7 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -49,14 +49,14 @@ function saveCache () { } function restoreCaches { - if [ -f "$IPA_CACHE"]; then + if [ -f "$IPA_CACHE" ]; then mkdir -p $CORDOVA_APP_DIR/platforms_release/ios cd $CORDOVA_APP_DIR/platforms_release/ios tar -zxf $IPA_CACHE cd - echo_ok "Restored IOS cache: '$IPA_CACHE'" fi - if [ -f "$APK_CACHE"]; then + if [ -f "$APK_CACHE" ]; then mkdir -p $CORDOVA_APP_DIR/platforms_release/android cd $CORDOVA_APP_DIR/platforms_release/android tar -zxf $APK_CACHE -- GitLab From 7f2111e083472a3c9827fd7ac3fc7b28bb6a5ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 18:30:57 +0100 Subject: [PATCH 56/67] fix hash --- build.sh | 1 - include/cache.sh | 3 ++- sign.sh | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 3d098a4..4aefad0 100755 --- a/build.sh +++ b/build.sh @@ -16,7 +16,6 @@ source $(dirname $0)/include/index.sh -CACHES_AVAILABLE=$(cacheAvailableForTargets) if [ "$CACHES_AVAILABLE" == "true" ]; then echo_ok "Native build caches found. Nothing to do. Exiting..." exit 0 diff --git a/include/cache.sh b/include/cache.sh index fd411e7..54b8649 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -16,7 +16,7 @@ function cacheAvailableForTargets () { export APK_CACHE_AVAILABLE="false" fi fi - echo "$available" + export CACHES_AVAILABLE=$available } function getCacheFilename () { @@ -72,3 +72,4 @@ function restoreCaches { setCacheHash export IPA_CACHE=$(getCacheFilename "ios") export APK_CACHE=$(getCacheFilename "android") +cacheAvailableForTargets diff --git a/sign.sh b/sign.sh index 2ba8e9f..d882529 100755 --- a/sign.sh +++ b/sign.sh @@ -21,7 +21,6 @@ source $(dirname $0)/include/index.sh -CACHES_AVAILABLE=$(cacheAvailableForTargets) if [ "$CACHES_AVAILABLE" == "true" ]; then echo_ok "Native build caches found. Continue..." restoreCaches -- GitLab From 2a305cd72b0e21ff8e47c8d78b7bba67576230c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Fri, 22 Mar 2019 18:34:48 +0100 Subject: [PATCH 57/67] fix hash --- include/cache.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/cache.sh b/include/cache.sh index 54b8649..98aefc2 100644 --- a/include/cache.sh +++ b/include/cache.sh @@ -4,6 +4,8 @@ function cacheAvailableForTargets () { local available="true" + export IPA_CACHE_AVAILABLE="true" + export APK_CACHE_AVAILABLE="true" if [ "$BUILD_IPA" == "true" ]; then if [ ! -f "$IPA_CACHE" ]; then available="false" -- GitLab From d80789ce3c44e4360c8e69843faac9c14b4fa356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 16:41:19 +0100 Subject: [PATCH 58/67] try not cordova add android --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 4aefad0..6e2a92e 100755 --- a/build.sh +++ b/build.sh @@ -55,7 +55,7 @@ if [ "$BUILD_APK" == "true" ] && [ "$APK_CACHE_AVAILABLE" != "true" ]; then replaceConfigXmlVars setBundleIdentifier "${BUNDLE_IDENTIFIER_ANDROID}" - cordova platform add android +# cordova platform add android cordova prepare android source $SHELLDIR/build_apk.sh -- GitLab From 0f1cf46c6764f52c2183f2a8a1ef0d336a608e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 17:16:20 +0100 Subject: [PATCH 59/67] cleanup --- build_apk.sh | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/build_apk.sh b/build_apk.sh index b4333c5..554cdc5 100755 --- a/build_apk.sh +++ b/build_apk.sh @@ -1,22 +1,5 @@ #!/bin/bash -# WORKSPACE -# BUILD_NUMBER -# APP_NAME -# ANDROID_SIGNING_KEY_FILE_NAME -# ANDROID_SIGNING_KEY_ALIAS -# ANDROID_SIGNING_KEY_STORE_PASSWORD -# ANDROID_SIGNING_KEY_ALIAS_PASSWORD -# ANDROID_REMOTE_PATH -# ANDROID_SDK_PATH -# REMOTE_HOST -# CONFIG - -function fail() { - echo "FAILED: $@" >&2 - exit 1 -} - cd $CORDOVA_APP_DIR ../../node_modules/cordova/bin/cordova build android --release -- GitLab From 562bbb495edc6f8dfa33079eccd1c0676ffe2cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 17:16:59 +0100 Subject: [PATCH 60/67] add sign apk --- sign_apk.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 sign_apk.sh diff --git a/sign_apk.sh b/sign_apk.sh new file mode 100755 index 0000000..ba5fa92 --- /dev/null +++ b/sign_apk.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +cd $CORDOVA_PLATFORM_RELEASE_DIR/android/build/outputs/apk/ || fail "Android build directory does not exist." + +key_file_name="$WORKSPACE/deploy/native/android/keys/$ANDROID_SIGNING_KEY_FILE_NAME" +[ -f "$key_file_name" ] || fail "Could not find signing key '$ANDROID_SIGNING_KEY_FILE_NAME'." + +for tmp_apk_file_name in *.apk; do + arch_suffix=$(echo "${tmp_apk_file_name}" | sed -e 's/-unsigned.apk//' | sed -e 's/android-//') + apk_file_name="$APP_NAME-$BUILD_NUMBER-$CONFIG-$arch_suffix.apk" + + if [ "$CONFIG" == 'production' ]; then + unsigned_apk_file_name="$APP_NAME-$BUILD_NUMBER-$CONFIG-$arch_suffix-unsigned.apk" + cp $tmp_apk_file_name $unsigned_apk_file_name + fi + + jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore $key_file_name \ + -storepass $ANDROID_SIGNING_KEY_STORE_PASSWORD -keypass $ANDROID_SIGNING_KEY_ALIAS_PASSWORD \ + $tmp_apk_file_name $ANDROID_SIGNING_KEY_ALIAS + + jarsigner -verify -certs $tmp_apk_file_name + + zipalign $tmp_apk_file_name $apk_file_name + + if [ -f "$apk_file_name" ] ; then rm $tmp_apk_file_name ; fi +done -- GitLab From a224bd1816e2199b0d7e8fca378bf1334e259918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 17:35:17 +0100 Subject: [PATCH 61/67] add www contents to apks --- sign_apk.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sign_apk.sh b/sign_apk.sh index ba5fa92..04dacb5 100755 --- a/sign_apk.sh +++ b/sign_apk.sh @@ -5,7 +5,17 @@ cd $CORDOVA_PLATFORM_RELEASE_DIR/android/build/outputs/apk/ || fail "Android bui key_file_name="$WORKSPACE/deploy/native/android/keys/$ANDROID_SIGNING_KEY_FILE_NAME" [ -f "$key_file_name" ] || fail "Could not find signing key '$ANDROID_SIGNING_KEY_FILE_NAME'." +echo_info "Copy JS build into apk(s)..." +APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app +mkdir -p tmp/assets/www/ +cp -r $CORDOVA_PLATFORM_RELEASE_DIR/www/* tmp/assets/www/ + + for tmp_apk_file_name in *.apk; do + + echo_info "Add www contents to $tmp_apk_file_name..." + zip -ur $tmp_apk_file_name tmp/assets + arch_suffix=$(echo "${tmp_apk_file_name}" | sed -e 's/-unsigned.apk//' | sed -e 's/android-//') apk_file_name="$APP_NAME-$BUILD_NUMBER-$CONFIG-$arch_suffix.apk" @@ -14,12 +24,15 @@ for tmp_apk_file_name in *.apk; do cp $tmp_apk_file_name $unsigned_apk_file_name fi + echo_info "Sign $tmp_apk_file_name..." jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore $key_file_name \ -storepass $ANDROID_SIGNING_KEY_STORE_PASSWORD -keypass $ANDROID_SIGNING_KEY_ALIAS_PASSWORD \ $tmp_apk_file_name $ANDROID_SIGNING_KEY_ALIAS + echo_info "Verify $tmp_apk_file_name..." jarsigner -verify -certs $tmp_apk_file_name + echo_info "Align $tmp_apk_file_name..." zipalign $tmp_apk_file_name $apk_file_name if [ -f "$apk_file_name" ] ; then rm $tmp_apk_file_name ; fi -- GitLab From 83178ef1d0d2e477be9e6361019d85af67134847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 17:39:47 +0100 Subject: [PATCH 62/67] fix path --- sign_apk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sign_apk.sh b/sign_apk.sh index 04dacb5..bd4c45d 100755 --- a/sign_apk.sh +++ b/sign_apk.sh @@ -8,7 +8,7 @@ key_file_name="$WORKSPACE/deploy/native/android/keys/$ANDROID_SIGNING_KEY_FILE_N echo_info "Copy JS build into apk(s)..." APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app mkdir -p tmp/assets/www/ -cp -r $CORDOVA_PLATFORM_RELEASE_DIR/www/* tmp/assets/www/ +cp -r $CORDOVA_APP_DIR/www/* tmp/assets/www/ for tmp_apk_file_name in *.apk; do -- GitLab From c86be26f90b34a0de16271f1748b73127d43db72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 17:44:53 +0100 Subject: [PATCH 63/67] fix zipalign params --- sign_apk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sign_apk.sh b/sign_apk.sh index bd4c45d..3b50ee5 100755 --- a/sign_apk.sh +++ b/sign_apk.sh @@ -33,7 +33,7 @@ for tmp_apk_file_name in *.apk; do jarsigner -verify -certs $tmp_apk_file_name echo_info "Align $tmp_apk_file_name..." - zipalign $tmp_apk_file_name $apk_file_name + zipalign 4 $tmp_apk_file_name $apk_file_name if [ -f "$apk_file_name" ] ; then rm $tmp_apk_file_name ; fi done -- GitLab From b0cf611afa803a6c72f968548d8e6b943ea4969c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 17:53:03 +0100 Subject: [PATCH 64/67] fix www assets path in zip --- sign_apk.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sign_apk.sh b/sign_apk.sh index 3b50ee5..fc002ec 100755 --- a/sign_apk.sh +++ b/sign_apk.sh @@ -7,14 +7,14 @@ key_file_name="$WORKSPACE/deploy/native/android/keys/$ANDROID_SIGNING_KEY_FILE_N echo_info "Copy JS build into apk(s)..." APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app -mkdir -p tmp/assets/www/ -cp -r $CORDOVA_APP_DIR/www/* tmp/assets/www/ +mkdir -p assets/www/ +cp -r $CORDOVA_APP_DIR/www/* assets/www/ for tmp_apk_file_name in *.apk; do echo_info "Add www contents to $tmp_apk_file_name..." - zip -ur $tmp_apk_file_name tmp/assets + zip -ur $tmp_apk_file_name assets arch_suffix=$(echo "${tmp_apk_file_name}" | sed -e 's/-unsigned.apk//' | sed -e 's/android-//') apk_file_name="$APP_NAME-$BUILD_NUMBER-$CONFIG-$arch_suffix.apk" -- GitLab From 87e9567c8504e5ac392ab0a6299fbe4f2b625aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 18:18:15 +0100 Subject: [PATCH 65/67] use build.sh --- sign.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sign.sh b/sign.sh index d882529..5e92a39 100755 --- a/sign.sh +++ b/sign.sh @@ -33,7 +33,8 @@ echo_info "Set JS config for env '$CONFIG'" configureJavascript echo_info "Build JS project" -node_modules/.bin/webpack --config webpack.prod.config.js +#node_modules/.bin/webpack --config webpack.prod.config.js +source $WORKSPACE/build.sh echo_info "Copy JS build to native projects and sign" cd $CORDOVA_APP_DIR -- GitLab From 8b5747080922124c7b2cb4deb2405863402eb730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Sat, 23 Mar 2019 19:31:53 +0100 Subject: [PATCH 66/67] fix config path --- include/funcs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/funcs.sh b/include/funcs.sh index be7d4d9..35d9b9f 100644 --- a/include/funcs.sh +++ b/include/funcs.sh @@ -64,7 +64,7 @@ function configureJavascript { echo_warn "Deprecation warning: App configuration using JSON configs is deprecated." cp "$DEPLOY_JS_DIR/$CONFIG.json" src/config/config.json sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json - elif [ -f "$DEPLOY_JS_DIR/configs/$CONFIG.js" ] + elif [ -f "$DEPLOY_JS_DIR/$CONFIG.js" ] then # Configure project with JS configs cp "$DEPLOY_JS_DIR/$CONFIG.js" src/conf.js -- GitLab From d04abdc75155f3761c9ed115610b0843f6aa8221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Runkel?= Date: Mon, 25 Mar 2019 10:49:29 +0100 Subject: [PATCH 67/67] Update docs and cleanup --- README.md | 97 ++++++++++++++++++++++++---------- apk.sh | 46 ----------------- build.sh | 2 +- cordova.sh | 149 ----------------------------------------------------- index.js | 4 +- ipa.sh | 68 ------------------------ sign.sh | 2 +- 7 files changed, 75 insertions(+), 293 deletions(-) delete mode 100755 apk.sh delete mode 100755 cordova.sh delete mode 100755 ipa.sh diff --git a/README.md b/README.md index f77de53..95a0285 100644 --- a/README.md +++ b/README.md @@ -26,40 +26,52 @@ the cordova CLI handles. So this tools handle the complete workflow: Add a directory structure containing configuration for Javascript and signing: ``` -deploy/ - ├── android - │   └── keys - │   └── my_app-release-key.keystore - ├── base.config - ├── configs - │   ├── development.config - │   ├── development.json - │   ├── production.config - │   ├── production.json - │   ├── test.config - │   └── test.json - └── ios - └── profiles - ├── my_App_In_House.mobileprovision - └── my_App_Store.mobileprovision +deploy +├── js +│   ├── development.json (or .js) +│   ├── production.json (or.js) +└── native + ├── android + │   └── keys + │   └── sportschau_app-release-key.keystore + ├── base.config + ├── configs + │   ├── development.config + │   ├── production.config + ├── ios + │   └── profiles + │   ├── development-export-options.plist + │   ├── production-export-options.plist + │   ├── Sportschau_App_In_House.mobileprovision + │   ├── Sportschau_AppStore_App.mobileprovision + │   ├── Sportschau_AppStore_Widget.mobileprovision + │   ├── Sportschau_App_Widget.mobileprovision + └── resource-files + ├── google-services.json.development + ├── google-services.json.production ``` ### Configuration Files -#### base.config +#### native/base.config Define environment variables for your build here. The following variables are mandatory: ``` +SDK='iphoneos' +PRODUCT_NAME='sportschau_app' +APP_NAME='sportschau_app' + +BUNDLE_LOCALIZATION='German' ANDROID_SIGNING_KEY_FILE_NAME='my_app-release-key.keystore' ANDROID_SIGNING_KEY_ALIAS='my_app' ANDROID_SIGNING_KEY_STORE_PASSWORD='password' ANDROID_SIGNING_KEY_ALIAS_PASSWORD='password' ``` -### configs/.config +### native/configs/.config Define environment variables for the build of an specific environment. @@ -75,7 +87,7 @@ BUNDLE_IDENTIFIER_IOS='de.codevise.my.app' BUNDLE_IDENTIFIER_ANDROID='de.codevise.my.app.android' ``` -### configs/.json +### js/.json / js/.js Define a configuration to be copied into the Javascript app for an specific environment. Content is completely up to your app except for one key `buildVersion` which will be replaced @@ -86,22 +98,55 @@ with `BUILD_NUMBER`.`GIT_BRANCH` environment variables, which should be set in C "buildVersion": "dev", } ``` +### Build script for JS + +The module expects th find a `build.sh`in the root folder of your project. It will call this +script to build the JS project during the `--sign` build step. + +Important: It is assumed that the build artifacts (e.g. app.js etc.) are located in the + `cordova//www/ +folder after the `build.sh` call. So either configure webpack to use that build folder or copy artifacts +in the `build.sh`script there. + + + ## Run +Native build and JS bild/signing is divided in two steps. The native build artifacts are cached +on the build machine to speed up subsequent builds. +Every change on giles below the `deploy` or `cordova` folders will trigger new native builds. + +### Build native containers + Build `ipa` and `apk` using `production` configuration. - $ cordova-build --ipa --apk production + $ cordova-build --build --ipa --apk production + +### Build JS, sign apps and upload to AppDistributor -Get help - $ cordova-build --help + $ cordova-build --sign --ipa --apk production Expamle configuration for Gitlab (`.gitlab-ci.yml`) ```yml -build_production: + +build_native: + stage: production + variables: + CONFIG: production + script: + - echo "Building Native My App" + - source $HOME/.bashrc + - rvm use 2.2.1 + - nvm use 9.2.0 + - npm ci + - cordova-build --build --ipa --apk ${CONFIG} +` + +build_js: stage: production variables: CONFIG: production @@ -112,10 +157,10 @@ build_production: - echo "Building My App" - source $HOME/.bashrc - rvm use 2.2.1 - - nvm use 6.2.2 + - nvm use 9.2.0 - bundle install - - npm install - - cordova-build --ipa --apk ${CONFIG} + - npm ci + - cordova-build --sign --ipa --apk ${CONFIG} ``` ## Dependencies diff --git a/apk.sh b/apk.sh deleted file mode 100755 index e511dde..0000000 --- a/apk.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# WORKSPACE -# BUILD_NUMBER -# APP_NAME -# ANDROID_SIGNING_KEY_FILE_NAME -# ANDROID_SIGNING_KEY_ALIAS -# ANDROID_SIGNING_KEY_STORE_PASSWORD -# ANDROID_SIGNING_KEY_ALIAS_PASSWORD -# ANDROID_REMOTE_PATH -# ANDROID_SDK_PATH -# REMOTE_HOST -# CONFIG - -function fail() { - echo "FAILED: $@" >&2 - exit 1 -} - -cd $CORDOVA_APP_DIR -../../node_modules/cordova/bin/cordova build android --release - -cd $ANDROID_CONTAINER/build/outputs/apk/ || fail "Build directory does not exist." - -key_file_name="$WORKSPACE/deploy/android/keys/$ANDROID_SIGNING_KEY_FILE_NAME" -[ -f "$key_file_name" ] || fail "Could not find signing key '$ANDROID_SIGNING_KEY_FILE_NAME'." - -for tmp_apk_file_name in *.apk; do - arch_suffix=$(echo "${tmp_apk_file_name}" | sed -e 's/-unsigned.apk//' | sed -e 's/android-//') - apk_file_name="$APP_NAME-$BUILD_NUMBER-$CONFIG-$arch_suffix.apk" - - if [ "$CONFIG" == 'production' ]; then - unsigned_apk_file_name="$APP_NAME-$BUILD_NUMBER-$CONFIG-$arch_suffix-unsigned.apk" - cp $tmp_apk_file_name $unsigned_apk_file_name - fi - - jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $key_file_name \ - -storepass $ANDROID_SIGNING_KEY_STORE_PASSWORD -keypass $ANDROID_SIGNING_KEY_ALIAS_PASSWORD \ - $tmp_apk_file_name $ANDROID_SIGNING_KEY_ALIAS - - jarsigner -verify -verbose -certs $tmp_apk_file_name - - zipalign -v 4 $tmp_apk_file_name $apk_file_name - - if [ -f "$apk_file_name" ] ; then rm $tmp_apk_file_name ; fi -done diff --git a/build.sh b/build.sh index 6e2a92e..3f6a25b 100755 --- a/build.sh +++ b/build.sh @@ -10,7 +10,7 @@ # BUILD_APK # # Config specific variables are loaded from the core project's files -# `deploy/base.config` and `deploy/configs/$CONFIG.config`. See +# `deploy/native/base.config` and `deploy/native/configs/$CONFIG.config`. See # documentation in include/env.sh for further information on environment # variables required for building and publishing diff --git a/cordova.sh b/cordova.sh deleted file mode 100755 index aed5f2c..0000000 --- a/cordova.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/bash - -# This task builds ipas and apks for Cordova projects with associated -# ios/android container projects. -# -# ENVIRONMENT VARIABLES: -# -# Defined via Gitlab Job: -# -# CONFIG Name of deploy configuration. Determines which -# *.config and *.yml files are used in -# project's `deploy/ios/configs` directory. -# BUILD_NUMBER Unique Build number to identify the build. I.e. pipline no. -# BUILD_IPA -# BUILD_APK -# -# Config specific variables are loaded from the core project's files -# `deploy/base.config` and `deploy/configs/$CONFIG.config`. See -# documentation in ipa.sh for further information on environment -# variables required for building and publishing the ipa file. - - -# Output every command and fail if any command fails -set -ex -export SHELLDIR=$(dirname $0) -export WORKSPACE=$(pwd) -export CORDOVA_APP_DIR=$WORKSPACE/cordova/$(ls -1 cordova) -export CORDOVA_PLATFORM_DIR=$CORDOVA_APP_DIR/platforms -export ANDROID_CONTAINER=$CORDOVA_PLATFORM_DIR/android -export IOS_CONTAINER=$CORDOVA_PLATFORM_DIR/ios -export PATH=$PATH:$WORKSPACE/node_modules/cordova/bin/ -export BRANCH=$(echo "${GIT_BRANCH}" | sed -e 's/origin\///') - -function replaceConfigXmlVars { - cd $CORDOVA_APP_DIR - for cvar in ${!CONFIGXML_VAR_*}; do - echo "Replacing variable ${cvar} in config.xml with ${!cvar}" - sed -i '' "s/$cvar/${!cvar}/g" config.xml - done -} - -# Load configurations -[ -f "$WORKSPACE/deploy/base.config" ] && source "$WORKSPACE/deploy/base.config" -[ -f "$WORKSPACE/deploy/configs/$CONFIG.config" ] && source "$WORKSPACE/deploy/configs/$CONFIG.config" - -cd $WORKSPACE -if [ -f "deploy/configs/$CONFIG.json" ] -then - # Configure project with JSON configs -- deprecated variant - echo "Deprecation warning: App configuration using JSON configs is deprecated." - cp "deploy/configs/$CONFIG.json" src/config/config.json - sed -i '' "s/\"buildVersion\":.*/\"buildVersion\": \"${BUILD_NUMBER}.${BRANCH}\",/g" src/config/config.json -elif [ -f "deploy/configs/$CONFIG.js" ] -then - # Configure project with JS configs - cp "deploy/configs/$CONFIG.js" src/conf.js - sed -i '' "s/buildVersion:.*/buildVersion: '${BUILD_NUMBER}.${BRANCH}',/g" src/conf.js -else - echo "No valid configuration found for environment $CONFIG in deploy/config/" - exit 1 -fi - -# Copy resource-files -RESOURCES_DIR="$WORKSPACE/deploy/resource-files/" -RESOURCES_FILES="$RESOURCES_DIR*.$CONFIG" - -if [ -d "$RESOURCES_DIR" ]; then - if compgen -G "$RESOURCES_FILES" > /dev/null; then - echo "Copying resource files from $RESOURCES_FILES to cordova root dir..." - for f in ${RESOURCES_FILES}; do - [ -e "$f" ] || continue - target_filename="$(basename "$f" .$CONFIG)" - echo "... copy ${f##*/} to $CORDOVA_APP_DIR/$target_filename" - cp "$f" "$CORDOVA_APP_DIR/$target_filename" - done - fi -fi - -export PATH=$PATH:/opt/local/bin -export LANG=de_DE.UTF-8 - -# Export deploy config for ipa script -export SDK CONFIGURATION CONFIG DISTRIBUTION_CERTIFICATE \ - PROVISIONING_PROFILE_FILE_NAME PROVISIONING_PROFILE_ID \ - WIDGET_PROVISIONING_PROFILE_FILE_NAME WIDGET_PROVISIONING_PROFILE_ID \ - BUNDLE_IDENTIFIER PRODUCT_NAME APP_NAME \ - KEYCHAIN_PASSWORD PROVISIONING_PROFILES_DIR ANDROID_SDK_PATH CORDOVA_APP_DIR - -# prepare cordova projects - -# Cordova fetch is totally broken for git urls comming not from known hosters. It uses this module, which has been patched to know codevise gitlab. -npm install https://github.com/jrunkel/hosted-git-info.git#latest -npm install xml2js - -cd $CORDOVA_APP_DIR - -# Set CONFIGXML_VAR placeholders in Cordova config.xml -replaceConfigXmlVars - -npm install cordova-custom-config - -if [ "$BUILD_IPA" == 'true' ]; then - - cd $CORDOVA_APP_DIR - rm -rf www - mkdir www - rm -rf plugins/* - rm -rf platforms/android - rm -rf platforms/ios - sed -i '' "s/&2 - exit 1 -} - -set -ex - -cd $IOS_CONTAINER -security unlock-keychain -p $KEYCHAIN_PASSWORD -agvtool new-version -all $BUILD_NUMBER - -if [ -n "$BUNDLE_VERSION" ]; then - agvtool new-marketing-version $BUNDLE_VERSION -fi - -PROVISIONING_PROFILES_DIR=$HOME"/Library/MobileDevice/Provisioning Profiles/" -# Copy provisioning profile to provisioning profiles dir -[ -d "$PROVISIONING_PROFILES_DIR" ] || mkdir -p "$PROVISIONING_PROFILES_DIR" -provisioning_profiles_source_dir="$WORKSPACE/deploy/ios/profiles/" - -# Copy main profile -provisioning_profile_source="$provisioning_profiles_source_dir/$PROVISIONING_PROFILE_FILE_NAME" -[ -f "$provisioning_profile_source" ] || fail "Profile '$PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" -provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$PROVISIONING_PROFILE_ID.mobileprovision" -[ -f "$provisioning_profile_file_name" ] || cp "$provisioning_profile_source" "$provisioning_profile_file_name" - - -#Optional copy widget profile -if [ -n "$WIDGET_PROVISIONING_PROFILE_FILE_NAME" ]; then - echo "WIDGET: $WIDGET_PROVISIONING_PROFILE_FILE_NAME" - widget_provisioning_profile_source="$provisioning_profiles_source_dir/$WIDGET_PROVISIONING_PROFILE_FILE_NAME" - [ -f "$widget_provisioning_profile_source" ] || fail "Widget Profile '$WIDGET_PROVISIONING_PROFILE_FILE_NAME' not found in '$provisioning_profiles_source_dir'" - widget_provisioning_profile_file_name="$PROVISIONING_PROFILES_DIR/$WIDGET_PROVISIONING_PROFILE_ID.mobileprovision" - [ -f "$widget_provisioning_profile_file_name" ] || cp "$widget_provisioning_profile_source" "$widget_provisioning_profile_file_name" -fi - -# Build app file -#xcodebuild -configuration $CONFIGURATION -sdk $SDK clean build \ -# CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphoneos" \ -# PROVISIONING_PROFILE=$PROVISIONING_PROFILE_ID \ -# WIDGET_PROVISIONING_PROFILE=$WIDGET_PROVISIONING_PROFILE_ID \ -# CODE_SIGN_IDENTITY="$DISTRIBUTION_CERTIFICATE" CODE_SIGN_STYLE="Manual" || fail "xcodebuild failed." - -scheme_name=$(ls | grep .xcworkspace | sed -e 's/.xcworkspace//') - -# Install pods if any -if [ -f "Podfile" ]; then - echo "Installing Pods" - pod install -fi - -mkdir export -xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -configuration $CONFIGURATION -archivePath $(pwd)/build/${scheme_name}.xcarchive -sdk iphoneos -scheme $scheme_name archive PROVISIONING_PROFILE=$PROVISIONING_PROFILE_ID WIDGET_PROVISIONING_PROFILE=$WIDGET_PROVISIONING_PROFILE_ID CODE_SIGN_IDENTITY="$DISTRIBUTION_CERTIFICATE" CODE_SIGN_STYLE="Manual" || fail "xcodebuild failed." - -xcodebuild -UseModernBuildSystem=NO -exportArchive -archivePath $(pwd)/build/${scheme_name}.xcarchive -exportOptionsPlist "${provisioning_profiles_source_dir}/${CONFIG}-export-options.plist" -exportPath "export/" -# Copy app folder containing Info.plist needed for app distributor to export directory -cp -r $(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app export/ - -# Build simulator image -cd $IOS_CONTAINER -xcodebuild -UseModernBuildSystem=NO -workspace *.xcworkspace -scheme $scheme_name -configuration $CONFIGURATION -sdk iphonesimulator build \ - CONFIGURATION_BUILD_DIR="$(pwd)/build/${CONFIGURATION}-iphonesimulator" - -simulator_directory="$(pwd)/build/${CONFIGURATION}-iphonesimulator/*.app" -simulator_file_name="$scheme_name.zip" -zip -r "export/$simulator_file_name" $simulator_directory diff --git a/sign.sh b/sign.sh index 5e92a39..065f5dc 100755 --- a/sign.sh +++ b/sign.sh @@ -15,7 +15,7 @@ # BUILD_APK # # Config specific variables are loaded from the core project's files -# `deploy/base.config` and `deploy/configs/$CONFIG.config`. See +# `deploy/native/base.config` and `deploy/native/configs/$CONFIG.config`. See # documentation in ipa.sh for further information on environment # variables required for building and publishing the ipa file. -- GitLab