diff --git a/README.md b/README.md index ed63434a28af24516aa3e6ef761567b48faba44d..95a02850b3439813da01858d2bcd6ee6a7c5c4e7 100644 --- a/README.md +++ b/README.md @@ -26,44 +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: ``` -PRODUCT_NAME='my_app' # iOS: used in resulting app filename - -APP_NAME='my_app' # Android: used in resulting app filename +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. @@ -79,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 @@ -90,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 @@ -116,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 e511dde59389852edfa235339187be1958dd237c..0000000000000000000000000000000000000000 --- 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 new file mode 100755 index 0000000000000000000000000000000000000000..3f6a25be529493b0e23d9c4514590637226ef3f3 --- /dev/null +++ b/build.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# This task builds ipas and apks for Cordova projects with associated +# ios/android container projects. +# +# ENVIRONMENT VARIABLES: +# +# 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/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 + +source $(dirname $0)/include/index.sh + +if [ "$CACHES_AVAILABLE" == "true" ]; then + echo_ok "Native build caches found. Nothing to do. Exiting..." + exit 0 +fi +echo_ok "Not all native build caches found. Building..." + +echo_info "Copy resource-files" +copyResourceFiles + +echo_info "Prepare cordova projects" +cd $CORDOVA_APP_DIR +rm -rf platforms/android +rm -rf platforms/ios +mkdir -p www +mkdir -p platforms_release + +if [ "$BUILD_IPA" == "true" ] && [ "$IPA_CACHE_AVAILABLE" != "true" ]; then + echo_info "Building IOS project" + rm -rf plugins/* + replaceConfigXmlVars + setBundleIdentifier "${BUNDLE_IDENTIFIER_IOS}" + + cordova platform add ios + cordova prepare ios + + source $SHELLDIR/build_ipa.sh + cd $CORDOVA_APP_DIR + mv platforms/ios platforms_release/ + echo_ok "IOS project build." + saveCache "ios" +fi + +if [ "$BUILD_APK" == "true" ] && [ "$APK_CACHE_AVAILABLE" != "true" ]; then + echo_info "Building Android project" + rm -rf plugins/* + git checkout config.xml + replaceConfigXmlVars + setBundleIdentifier "${BUNDLE_IDENTIFIER_ANDROID}" + +# cordova platform add android + cordova prepare android + + source $SHELLDIR/build_apk.sh + cd $CORDOVA_APP_DIR + mv platforms/android platforms_release/ + echo_ok "Android project build." + saveCache "android" +fi + +echo_ok "Done." diff --git a/build_apk.sh b/build_apk.sh new file mode 100755 index 0000000000000000000000000000000000000000..554cdc5ee3c552169d1ff5b6242600a9bef71f16 --- /dev/null +++ b/build_apk.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd $CORDOVA_APP_DIR +../../node_modules/cordova/bin/cordova build android --release + +cd $ANDROID_CONTAINER/build/outputs/apk/ || fail "Build directory does not exist." diff --git a/build_ipa.sh b/build_ipa.sh new file mode 100755 index 0000000000000000000000000000000000000000..7e43f54eca436781c50d617bdf2168512d934b3d --- /dev/null +++ b/build_ipa.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +cd $IOS_CONTAINER +security unlock-keychain -p $KEYCHAIN_PASSWORD + +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 + +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_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_info "Building 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_ok "Done." diff --git a/cordova.sh b/cordova.sh deleted file mode 100755 index aed5f2c1f88acb8bd5e72ea3b2d3c4c5c17f956e..0000000000000000000000000000000000000000 --- 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/ /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" +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/index.js b/index.js index 3cfcd41e469f675e8fcea74d852854ba512293df..43c319c139a52e37e39277dd0328dbd6ffa908b0 100755 --- a/index.js +++ b/index.js @@ -12,6 +12,8 @@ program .arguments('') .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; }) @@ -27,6 +29,14 @@ 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 if (program.sign){ + var child = shspawn(path + '/sign.sh'); + process.exit(child.status); + } else { + console.log('Please either specify --build or --sign option'); + process.exit(1); + } } diff --git a/ipa.sh b/ipa.sh deleted file mode 100755 index e57949c2dd778912da942f49d753ecee104de4f7..0000000000000000000000000000000000000000 --- a/ipa.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash - -# ENVIRONMENT VARIABLES: -# -# 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: -# -# 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 - -[ -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 - -# 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/package.json b/package.json index dca125bab9a9206b9880234770bbdbdb3f24dabb..0ed9d276d363f8ffcdc9f674a8d00ed6f2f4d94e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-ci-module", - "version": "0.4.0", + "version": "0.6.1", "description": "Command line utilities to configure, build and sign cordova apps", "main": "index.js", "scripts": { @@ -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" } } diff --git a/sign.sh b/sign.sh new file mode 100755 index 0000000000000000000000000000000000000000..065f5dc7b48e0af804f180bd3ad25d2f097424d1 --- /dev/null +++ b/sign.sh @@ -0,0 +1,58 @@ +#!/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/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. + +source $(dirname $0)/include/index.sh + +if [ "$CACHES_AVAILABLE" == "true" ]; then + echo_ok "Native build caches found. Continue..." + restoreCaches +else + echo_fail "Not all native build caches found. This should not happen!" + exit 1 +fi + +echo_info "Set JS config for env '$CONFIG'" +configureJavascript + +echo_info "Build JS project" +#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 +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 + +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_apk.sh b/sign_apk.sh new file mode 100755 index 0000000000000000000000000000000000000000..fc002ec14cbf7cd5504e1674e9376f6ab43d9965 --- /dev/null +++ b/sign_apk.sh @@ -0,0 +1,39 @@ +#!/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'." + +echo_info "Copy JS build into apk(s)..." +APP_FOLDER=$(pwd)/build/${scheme_name}.xcarchive/Products/Applications/${scheme_name}.app +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 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" + + 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 + + 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 4 $tmp_apk_file_name $apk_file_name + + if [ -f "$apk_file_name" ] ; then rm $tmp_apk_file_name ; fi +done diff --git a/sign_ipa.sh b/sign_ipa.sh new file mode 100755 index 0000000000000000000000000000000000000000..13d9f492c15acc27e3ef9472c3463a4386214578 --- /dev/null +++ b/sign_ipa.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +cd $CORDOVA_PLATFORM_RELEASE_DIR/ios + +echo_info "Copy provisioning profiles for $CONFIG" +setupIOSProvisioningProfiles +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/ + +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/ + +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 -qr "export/$SIM_FILE_NAME" $SIM_FOLDER + +echo_ok "Done."