diff --git a/Jenkinsfile b/Jenkinsfile index 8678bf2..b91703c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,11 +58,8 @@ def workingBranch = 'master' def deployBranches = [ 'acceptance', 'production', ] -// Define the directory where the package (bundle) will be build -def buildDir = 'app/build/outputs/bundle' -// Define the directory where the package (apk) will be build. -// Fabric Crashlytics / Firebase App Distribution only support APKs as of June 2020 -def buildDirApk = 'app/build/outputs/apk' +// Define the parent directory where the apk or bundle will be build +def buildDir = 'app/build/outputs' // Initialize lazyConfig for this pipeline lazyConfig( @@ -73,6 +70,7 @@ ANDROID_HOME: '/opt/android/sdk', GRADLE_USER_HOME: '/opt/android/gradle', GRADLE_OPTS: '-XX:MaxMetaspaceSize=256m -Xmx1792m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -Dme.jenkins -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process', + ANDROID_BUNDLE: 'true', ANDROID_KEYALIAS: 'upload', ANDROID_KEYSTORE_CID: 'dummy-android', GOOGLE_API_CID: 'dappre-google-api', @@ -136,11 +134,7 @@ currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion.string}-${currentVersion.number}" }, run: { - // Fabric Crashlytics / Firebase App Distribution only support APKs as of June 2020 - if (env.ANDROID_KEYALIAS != 'upload') - fastLane('android', 'build_apk') - else - fastLane('android', 'build') + fastLane('android', 'build') }, args: "-v /opt/android:/opt/android" + " -v /opt/certificates:/opt/certificates" @@ -149,13 +143,10 @@ in: [ 'centos7' ], on: 'android', post: { + // Process Unitest reports junit(testResults: 'fastlane/report.xml,**/build/test-results/*/*.xml', allowEmptyResults: true) - - // Fabric Crashlytics / Firebase App Distribution only support APKs as of June 2020 - if (env.ANDROID_KEYALIAS != 'upload') - archiveArtifacts(artifacts: "${buildDirApk}/**", allowEmptyArchive: false) - else - archiveArtifacts(artifacts: "${buildDir}/**", allowEmptyArchive: false) + // Archive apk/aab and mapping to publish in later stage + archiveArtifacts(artifacts: "${buildDir}/**/*.apk,${buildDir}/**/*.aab,${buildDir}/**/mapping.txt", allowEmptyArchive: false) }, ] } @@ -165,10 +156,7 @@ onlyif = (! deployBranches.contains(lazyConfig['branch']) && lazyConfig['branch'] != workingBranch && lazyConfig.env.RELEASE ) tasks = [ pre: { - if (env.ANDROID_KEYALIAS != 'upload') - unarchive(mapping:["${buildDirApk}/" : '.']) - else - unarchive(mapping:["${buildDir}/" : '.']) + unarchive(mapping:["${buildDir}/" : '.']) }, run: { if ( !lazyConfig.env.DRYRUN ) { @@ -240,10 +228,7 @@ input = 'Deploy to internal testers?' tasks = [ pre: { - if (env.ANDROID_KEYALIAS != 'upload') - unarchive(mapping:["${buildDirApk}/" : '.']) - else - unarchive(mapping:["${buildDir}/" : '.']) + unarchive(mapping:["${buildDir}/" : '.']) }, run: { if ( !lazyConfig.env.DRYRUN ) { @@ -267,10 +252,7 @@ input = 'Deploy to alpha users?' tasks = [ pre: { - if (env.ANDROID_KEYALIAS != 'upload') - unarchive(mapping:["${buildDirApk}/" : '.']) - else - unarchive(mapping:["${buildDir}/" : '.']) + unarchive(mapping:["${buildDir}/" : '.']) }, run: { if ( !lazyConfig.env.DRYRUN ) { @@ -297,10 +279,7 @@ input = 'Promote to beta users?' tasks = [ pre: { - if (env.ANDROID_KEYALIAS != 'upload') - unarchive(mapping:["${buildDirApk}/" : '.']) - else - unarchive(mapping:["${buildDir}/" : '.']) + unarchive(mapping:["${buildDir}/" : '.']) }, run: { if ( !lazyConfig.env.DRYRUN ) { diff --git a/README.md b/README.md index 5ea3ee2..8c0e221 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,32 @@ ### Configuration By default, Android SDK is expected under `~/android/sdk`. -It is possible to adapt this path in `docker-compose.yml`. -But it may also be specified in your `local.properties`! +It is possible to adapt this path in `local.properties` (not to be committed). + +### Setup + +If the current user id and group id are not 1000, it is required to define them using environment variables: + +``` +export _UID="$(id -u)" +export _GID="$(id -g)" +``` + +Build the container image: + +``` +docker-compose --compatibility build $OS_LABEL +``` + +Where OS_LABEL can take any supported value: + - centos7 ### Usage -The following command should build (if required) and start a shell session inside the container: +The following command should start a shell session inside the container: ``` -docker-compose --compatibility run --rm default +docker-compose --compatibility run --rm $OS_LABEL ``` From there, Gradle and Fastlane should work as expected: diff --git a/app/build.gradle b/app/build.gradle index 756ac48..100f411 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -163,28 +163,7 @@ } applicationVariants.all { variant -> - if (variant.buildType.name == "release") { - variant.outputs.all { output -> - // Avoid to rename, so Fastlane default will work for now - //output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace("app-release.apk", "dappre_${versionName}.${versionCode}.apk")) - - if (variant.getBuildType().isMinifyEnabled()) { - variant.getAssembleProvider().configure() { - it.doLast { - copy { - from variant.mappingFile - into output.outputFile.parent - // Avoid to rename, so Fastlane default will work for now - //rename { - // String fileName -> - // "mapping_${versionName}.${versionCode}.txt" - //} - } - } - } - } - } - } + // Do something about all variants - previously used to copy/move some file around } } diff --git a/docker-compose.yml b/docker-compose.yml index 95e5caa..f8d3063 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' services: - default: + centos7: build: context: lazyDir dockerfile: centos7.Dockerfile diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 97815be..226c6ad 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -127,10 +127,10 @@ desc "Display infos about the app" lane :info do |options| - UI.message("App version name = #{getVersionName()}") - UI.message("App version number = #{getVersionCode()}") + UI.message("App version name = #{getVersionName()}") + UI.message("App version number = #{getVersionCode()}") UI.message("App Flavor = #{getFlavorName(options)}") - UI.message("App ID = #{getPackageName(options)}") + UI.message("App ID = #{getPackageName(options)}") end desc "Validate the current setup" @@ -171,86 +171,21 @@ ) end - desc "Build the apk" - lane :build_apk do |options| - gradle( - task: "clean assemble", - build_type: 'Release', - flavor: "#{getFlavorName(options)}", - ) - end - - desc "Build the bundle" + desc "Build the apk or the bundle depending of the environment" lane :build do |options| + build_task = ENV['ANDROID_BUNDLE'] == 'true' ? 'bundle' : 'assemble' gradle( - task: "clean bundle", + task: "clean #{build_task}", build_type: 'Release', flavor: "#{getFlavorName(options)}", ) end - desc "Bump version code/build number" - private_lane :bump do |options| - increment_version_code( - var_name: "versionCode|versionBuild", - verbose: true, - ) - end - - desc "Tag as a new version" - private_lane :tag do |options| - git_commit( - path: "app/build.gradle", - message: "Increment version code to #{lane_context[SharedValues::VERSION_CODE]} for next release", - ) - add_git_tag( - tag: "#{ENV['VERSION']}-#{lane_context[SharedValues::VERSION_CODE]}", - message: "Create new tag for version #{ENV['VERSION']}-#{lane_context[SharedValues::VERSION_CODE]}", - ) - push_to_git_remote( - local_branch: "HEAD", - remote_branch: "master", - ) - end - - desc "Build and deploy the bundle for Alpha testing in Google Play store" - lane :deploy_alpha do |options| - bump - gradle( - task: "clean bundle", - build_type: 'Release', - ) - sh("cp -vf metadata/android/en-US/changelogs/latest.txt metadata/android/en-US/changelogs/#{lane_context[SharedValues::VERSION_CODE]}.txt") - sh("git add metadata/android/en-US/changelogs/#{lane_context[SharedValues::VERSION_CODE]}.txt") - sh("git add metadata/android/en-US/changelogs/latest.txt") - sh("cp -vf metadata/android/nl-NL/changelogs/latest.txt metadata/android/nl-NL/changelogs/#{lane_context[SharedValues::VERSION_CODE]}.txt") - sh("git add metadata/android/nl-NL/changelogs/#{lane_context[SharedValues::VERSION_CODE]}.txt") - sh("git add metadata/android/nl-NL/changelogs/latest.txt") - git_commit( - path: [ - "fastlane/metadata/android/en-US/changelogs/latest.txt", - "fastlane/metadata/android/en-US/changelogs/#{lane_context[SharedValues::VERSION_CODE]}.txt", - "fastlane/metadata/android/nl-NL/changelogs/latest.txt", - "fastlane/metadata/android/nl-NL/changelogs/#{lane_context[SharedValues::VERSION_CODE]}.txt", - ], - message: "Provide changelogs for this version", - ) - supply( - aab: "app/build/outputs/bundle/#{getFlavorName(options)}Release/app-#{getFlavorName(options)}-release.aab", - mapping: "app/build/outputs/mapping/#{getFlavorName(options)}/release/mapping.txt", - track: 'internal', - skip_upload_aab: false, - skip_upload_metadata: false, - skip_upload_images: true, - skip_upload_screenshots: true, - ) - tag - end - desc "Update metadata only, including images and screenshots" lane :deploy_metadata do |options| supply( skip_upload_aab: true, + skip_upload_apk: true, skip_upload_metadata: false, skip_upload_images: false, skip_upload_screenshots: false, @@ -265,31 +200,42 @@ if ! firebase_api_token UI.user_error!("No Firebase API token found in environment (FIREBASE_API_TOKEN)") else - find_firebase_app_id( - app_identifier: get_application_id(getFlavorName(options)), - ) - firebase_app_distribution( - app: lane_context[SharedValues::GOOGLE_APP_ID], - apk_path: "app/build/outputs/apk/#{getFlavorName(options)}/release/app-#{getFlavorName(options)}-release.apk", - firebase_cli_token: firebase_api_token, - release_notes_file: 'fastlane/metadata/android/en-US/changelogs/latest.txt', - groups: firebase_groups, - ) + find_firebase_app_id( + app_identifier: get_application_id(getFlavorName(options)), + ) + firebase_app_distribution( + app: lane_context[SharedValues::GOOGLE_APP_ID], + apk_path: "app/build/outputs/apk/#{getFlavorName(options)}/release/app-#{getFlavorName(options)}-release.apk", + firebase_cli_token: firebase_api_token, + release_notes_file: 'fastlane/metadata/android/en-US/changelogs/latest.txt', + groups: firebase_groups, + ) end end desc "Deploy a new internal version to the Google Play" lane :internal do |options| - supply( - aab: "app/build/outputs/bundle/#{getFlavorName(options)}Release/app-#{getFlavorName(options)}-release.aab", - mapping: "app/build/outputs/mapping/#{getFlavorName(options)}/release/mapping.txt", - track: 'internal', - skip_upload_aab: false, - skip_upload_metadata: false, - skip_upload_images: false, - skip_upload_screenshots: false, - package_name: "#{getPackageName(options)}", - ) + # Define general options + options = { + :track => 'internal', + :mapping => "app/build/outputs/mapping/#{getFlavorName(options)}Release/mapping.txt", + :skip_upload_metadata => false, + :skip_upload_images => false, + :skip_upload_screenshots => false, + :package_name => "#{getPackageName(options)}", + } + + # Add specific options for bundle or apk + if ENV['ANDROID_BUNDLE'] == 'true' + options[:aab] = "app/build/outputs/bundle/#{getFlavorName(options)}Release/app-#{getFlavorName(options)}-release.aab" + options[:skip_upload_aab] = false + else + options[:apk] = "app/build/outputs/apk/#{getFlavorName(options)}/release/app-#{getFlavorName(options)}-release.apk" + options[:skip_upload_apk] = false + end + + # Call supply with the final options + supply(options) end desc "Deploy a new alpha version to the Google Play" @@ -298,6 +244,7 @@ track: 'internal', track_promote_to: 'alpha', skip_upload_aab: true, + skip_upload_apk: true, skip_upload_metadata: true, skip_upload_images: true, skip_upload_screenshots: true, @@ -312,6 +259,7 @@ track: 'alpha', track_promote_to: 'beta', skip_upload_aab: true, + skip_upload_apk: true, skip_upload_metadata: true, skip_upload_images: true, skip_upload_screenshots: true, @@ -326,6 +274,7 @@ track: 'beta', track_promote_to: 'production', skip_upload_aab: true, + skip_upload_apk: true, skip_upload_metadata: true, skip_upload_images: true, skip_upload_screenshots: true, diff --git a/lazyDir/centos7.Dockerfile b/lazyDir/centos7.Dockerfile index 75d1e0d..0580b9d 100644 --- a/lazyDir/centos7.Dockerfile +++ b/lazyDir/centos7.Dockerfile @@ -127,9 +127,10 @@ ARG gid=1000 ARG group=android -# Add user to build -RUN groupadd -g "${gid}" "${group}" && \ - useradd -ms /bin/bash -g "${group}" -u "${uid}" "${user}" +# Add or modify user and group for build and runtime (convenient) +RUN id ${user} > /dev/null 2>&1 && \ + { groupmod -g "${gid}" "${group}" && usermod -md /home/${user} -s /bin/bash -g "${group}" -u "${uid}" "${user}"; } || \ + { groupadd -g "${gid}" "${group}" && useradd -md /home/${user} -s /bin/bash -g "${group}" -u "${uid}" "${user}"; } # Copy requirements in non-root user home directory COPY Gemfile Gemfile.lock "/home/${user}/" @@ -160,5 +161,9 @@ ENV LC_ALL "${locale}" ENV USER ${user} +ENV SKIP_SLOW_FASTLANE_WARNING="YES" \ + FASTLANE_SKIP_UPDATE_CHECK="YES" \ + FASTLANE_OPT_OUT_USAGE="YES" + # Get script directory from lazyLib at last to avoid warning w/o invalidating the cache ARG dir=.