Skip to content

Commit

Permalink
Merge pull request #388 from verdigado/191-cicd-android-delivery
Browse files Browse the repository at this point in the history
191: Android signing and delivery
  • Loading branch information
steffenkleinle authored Dec 20, 2024
2 parents 6ef2435 + b6ea508 commit c1a33db
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 76 deletions.
22 changes: 22 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ jobs:
- install_fastlane:
directory: android
- install_gradle_dependencies
- run:
command: bundle exec fastlane keystore
name: '[FL] Prepare Android Keystore'
working_directory: android
- run:
command: bundle exec fastlane android build version_name:${NEW_VERSION_NAME} version_code:${NEW_VERSION_CODE}
name: '[FL] Build'
Expand Down Expand Up @@ -344,6 +348,10 @@ jobs:
- install_node_modules
- install_fastlane:
directory: android
- run:
command: bundle exec fastlane android upload aab_path:attached_workspace/app-release.aab production_delivery:"<< parameters.production_delivery >>" version_name:${NEW_VERSION_NAME} version_code:${NEW_VERSION_CODE}
name: '[FL] Play Store Upload'
working_directory: android
- run:
command: echo "export ANDROID_RELEASE_ID='$(yarn --silent github-release create android ${NEW_VERSION_NAME} ${NEW_VERSION_CODE} --production-delivery << parameters.production_delivery >> --github-private-key ${GITHUB_PRIVATE_KEY} --owner ${CIRCLE_PROJECT_USERNAME} --repo ${CIRCLE_PROJECT_REPONAME} --release-notes "Release v${NEW_VERSION_NAME}+${NEW_VERSION_CODE}")'" >> ${BASH_ENV}
name: Create Github Release
Expand All @@ -368,6 +376,13 @@ jobs:
- install_node_modules
- install_fastlane:
directory: ios
- when:
condition: << parameters.production_delivery >>
steps:
- run:
command: bundle exec fastlane ios production_upload ipa_path:attached_workspace/app-release.ipa version_name:${NEW_VERSION_NAME}
name: '[FL] Production Upload'
working_directory: ios
- unless:
condition: << parameters.production_delivery >>
steps:
Expand Down Expand Up @@ -401,11 +416,14 @@ workflows:
- github
prepare_delivery: true
- build_android:
context:
- app_signing_android
requires:
- bump_version
- deliver_android:
context:
- github
- gruene_google_playstore
production_delivery: false
requires:
- build_android
Expand All @@ -432,6 +450,8 @@ workflows:
- check
- bump_version
- build_android:
context:
- app_signing_android
requires:
- check
- bump_version
Expand All @@ -445,6 +465,8 @@ workflows:
jobs:
- bump_version
- build_android:
context:
- app_signing_android
requires:
- bump_version
when:
Expand Down
8 changes: 4 additions & 4 deletions .circleci/src/jobs/build_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ steps:
- install_fastlane:
directory: android
- install_gradle_dependencies
# - run:
# name: '[FL] Prepare Android Keystore'
# command: bundle exec fastlane keystore
# working_directory: android
- run:
name: '[FL] Prepare Android Keystore'
command: bundle exec fastlane keystore
working_directory: android
- run:
name: '[FL] Build'
command: bundle exec fastlane android build version_name:${NEW_VERSION_NAME} version_code:${NEW_VERSION_CODE}
Expand Down
8 changes: 4 additions & 4 deletions .circleci/src/jobs/deliver_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ steps:
- install_node_modules
- install_fastlane:
directory: android
# - run:
# name: '[FL] Play Store Upload'
# command: bundle exec fastlane android playstore_upload aab_path:attached_workspace/app-release.aab production_delivery:"<< parameters.production_delivery >>" version_name:${NEW_VERSION_NAME} version_code:${NEW_VERSION_CODE}
# working_directory: native
- run:
name: '[FL] Play Store Upload'
command: bundle exec fastlane android upload aab_path:attached_workspace/app-release.aab production_delivery:"<< parameters.production_delivery >>" version_name:${NEW_VERSION_NAME} version_code:${NEW_VERSION_CODE}
working_directory: android
- run:
name: Create Github Release
command: echo "export ANDROID_RELEASE_ID='$(yarn --silent github-release create android ${NEW_VERSION_NAME} ${NEW_VERSION_CODE} --production-delivery << parameters.production_delivery >> --github-private-key ${GITHUB_PRIVATE_KEY} --owner ${CIRCLE_PROJECT_USERNAME} --repo ${CIRCLE_PROJECT_REPONAME} --release-notes "Release v${NEW_VERSION_NAME}+${NEW_VERSION_CODE}")'" >> ${BASH_ENV}
Expand Down
14 changes: 7 additions & 7 deletions .circleci/src/jobs/deliver_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ steps:
- install_node_modules
- install_fastlane:
directory: ios
# - when:
# condition: << parameters.production_delivery >>
# steps:
# - run:
# name: '[FL] Production Upload'
# command: bundle exec fastlane ios production_upload ipa_path:attached_workspace/app-release.ipa version_name:${NEW_VERSION_NAME}
# working_directory: ios
- when:
condition: << parameters.production_delivery >>
steps:
- run:
name: '[FL] Production Upload'
command: bundle exec fastlane ios production_upload ipa_path:attached_workspace/app-release.ipa version_name:${NEW_VERSION_NAME}
working_directory: ios
- unless:
condition: << parameters.production_delivery >>
steps:
Expand Down
6 changes: 3 additions & 3 deletions .circleci/src/workflows/beta_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
prepare_delivery: true

- build_android:
# context:
# - app_signing_android
context:
- app_signing_android
requires:
- bump_version
- deliver_android:
production_delivery: false
context:
- github
# - gruene_google_playstore
- gruene_google_playstore
requires:
- build_android

Expand Down
2 changes: 2 additions & 0 deletions .circleci/src/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
- check
- bump_version
- build_android:
context:
- app_signing_android
requires:
- check
- bump_version
2 changes: 2 additions & 0 deletions .circleci/src/workflows/commit_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ when:
jobs:
- bump_version
- build_android:
context:
- app_signing_android
requires:
- bump_version
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
if (project.hasProperty("KEYSTORE_PATH")) { // Signing with env variables (CI)
println "Signing using env variables"
release {
storeFile file("file://" + project.HOME + project.KEYSTORE_PATH)
storeFile file("file://" + project.KEYSTORE_PATH)
storePassword project.KEYSTORE_PASSWORD
keyAlias project.KEYSTORE_KEY_ALIAS
keyPassword project.KEYSTORE_KEY_PASSWORD
Expand Down
92 changes: 37 additions & 55 deletions android/fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,32 @@
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

APPLICATION_ID = 'de.gruene.wkapp'

CREDENTIALS_GIT_REPOSITORY_URL = ENV['CREDENTIALS_GIT_REPOSITORY_URL']
CREDENTIALS_DIRECTORY_PATH = ENV['CREDENTIALS_DIRECTORY_PATH']
CREDENTIALS_KEYSTORE_PATH = ENV['CREDENTIALS_KEYSTORE_PATH']
CREDENTIALS_KEYSTORE_PASSWORD = ENV['CREDENTIALS_KEYSTORE_PASSWORD']

KEYSTORE_PATH = ENV['KEYSTORE_PATH']
KEYSTORE_PASSWORD = ENV['KEYSTORE_PASSWORD']
KEYSTORE_KEY_ALIAS = ENV['KEYSTORE_KEY_ALIAS']
KEYSTORE_KEY_PASSWORD = ENV['KEYSTORE_KEY_PASSWORD']
APPLICATION_ID = "de.gruene.wkapp"

SIGNING_REPOSITORY_URL = ENV["SIGNING_REPOSITORY_URL"]
SIGNING_REPOSITORY_KEYSTORE_PASSWORD = ENV["SIGNING_REPOSITORY_KEYSTORE_PASSWORD"]

KEYSTORE_ALIAS = ENV["KEYSTORE_ALIAS"]
KEYSTORE_PASSWORD = ENV["KEYSTORE_PASSWORD"]

SIGNING_REPOSITORY_KEYSTORE_PATH = "signing/android/gruene-app.jks.gpg"
LOCAL_KEYSTORE_PATH = "#{ENV['HOME']}/keystore.jks"

default_platform(:android)

platform :android do
desc "Download and decrypt the JKS"
lane :keystore do
ensure_env_vars(
env_vars: ['CREDENTIALS_GIT_REPOSITORY_URL', 'CREDENTIALS_KEYSTORE_PATH', 'CREDENTIALS_DIRECTORY_PATH', 'CREDENTIALS_KEYSTORE_PASSWORD']
env_vars: ["SIGNING_REPOSITORY_URL", "SIGNING_REPOSITORY_KEYSTORE_PASSWORD"]
)

puts("Cloning repository with keystore")

unless File.exists? File.expand_path(CREDENTIALS_DIRECTORY_PATH)
sh("git clone #{CREDENTIALS_GIT_REPOSITORY_URL} #{CREDENTIALS_DIRECTORY_PATH}")
end
sh("git clone #{SIGNING_REPOSITORY_URL} signing")

puts("Decrypting keystore")

sh("gpg --verbose --passphrase #{CREDENTIALS_KEYSTORE_PASSWORD} --pinentry-mode loopback \\
-o ~/#{KEYSTORE_PATH} -d #{CREDENTIALS_KEYSTORE_PATH}")
sh("gpg --verbose --passphrase #{SIGNING_REPOSITORY_KEYSTORE_PASSWORD} --pinentry-mode loopback -o #{LOCAL_KEYSTORE_PATH} -d #{SIGNING_REPOSITORY_KEYSTORE_PATH}")
end

desc "Validate Play Store Key"
lane :validate_play_store_key do
validate_play_store_json_key(
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
end

desc "Build Android App"
desc "Create an android release build"
lane :build do |options|
version_code = options[:version_code]
version_name = options[:version_name]
Expand All @@ -62,15 +35,19 @@ platform :android do
raise "'nil' passed as parameter! Aborting..."
end

ensure_env_vars(
env_vars: ["KEYSTORE_ALIAS", "KEYSTORE_PASSWORD"]
)

gradle_system_properties = {
# 2GB Gradle + 1GB dex + 2-2.5GB RN < 6GB of circleci resource class medium+
:"org.gradle.jvmargs" => "-Xms512m -Xmx2024m",
:"org.gradle.daemon" => false
}

if ENV['TOTAL_CPUS']
if ENV["TOTAL_CPUS"]
# Gradle uses the wrong cpu count from the host (e.g. 36)
gradle_system_properties["org.gradle.workers.max"] = ENV['TOTAL_CPUS']
gradle_system_properties["org.gradle.workers.max"] = ENV["TOTAL_CPUS"]
end

env_prod = sh("echo -n environment=production | base64")
Expand All @@ -84,50 +61,55 @@ platform :android do
properties: {
:VERSION_CODE => version_code,
:VERSION_NAME => version_name,
:KEYSTORE_PATH => KEYSTORE_PATH,
:KEYSTORE_KEY_ALIAS => KEYSTORE_KEY_ALIAS,
:KEYSTORE_PATH => LOCAL_KEYSTORE_PATH,
:KEYSTORE_KEY_ALIAS => KEYSTORE_ALIAS,
:KEYSTORE_PASSWORD => KEYSTORE_PASSWORD,
:KEYSTORE_KEY_PASSWORD => KEYSTORE_KEY_PASSWORD,
:KEYSTORE_KEY_PASSWORD => KEYSTORE_PASSWORD,
}.compact,
system_properties: gradle_system_properties,
print_command: false
)
end
end

desc "Upload Android App to Google Play"
lane :upload_to_playstore do |options|
# The following parameters have to be passed:
# version_name: The version name the build should use
# version_code: The version code the build should use
# production_delivery: Whether to deliver to beta or production
# aab_path: The path to the .aab to upload
desc "Deliver android app to beta or production"
lane :upload do |options|
ensure_env_vars(
env_vars: ["GOOGLE_SERVICE_ACCOUNT_JSON"]
)

version_code = options[:version_code]
version_name = options[:version_name]
production_delivery = options[:production_delivery]
aab_path = options[:aab_path]

if [version_name, version_code, production_delivery].include?(nil)
if [version_name, version_code, production_delivery, aab_path].include?(nil)
raise "'nil' passed as parameter! Aborting..."
end

upload_to_play_store(
version_code: version_code,
version_name: version_name,
package_name: APPLICATION_ID,
metadata_path: ".android/fastlane/metadata",
track: production_delivery === true ? "production" : "beta",
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true,
skip_upload_metadata: true,
release_status: "completed",
skip_upload_apk: true,
aab: "#{ENV['HOME']}/attached_workspace/release.aab",
aab: "#{ENV['HOME']}/#{aab_path}",
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
end

desc "Promote the most recent version in the beta track to the production track in the Play Store."
lane :playstore_promote do |options|
desc "Promote the android app from beta to production"
lane :promote do |options|
ensure_env_vars(
env_vars: ["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
Expand All @@ -138,7 +120,7 @@ platform :android do
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
beta_version_codes = google_play_track_version_codes(
track: beta_track,
track: "beta",
package_name: APPLICATION_ID,
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
Expand All @@ -154,7 +136,7 @@ platform :android do
upload_to_play_store(
version_code: beta_version_codes[0],
package_name: APPLICATION_ID,
track: beta_track,
track: "beta",
track_promote_to: "production",
skip_upload_changelogs: true,
skip_upload_images: true,
Expand Down
4 changes: 2 additions & 2 deletions ios/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ platform :ios do
# The following parameters have to be passed:
# version_name: The version name the build should use
# version_code: The version code the build should use
desc "Create a release build"
desc "Create an ios release build"
lane :build do |options|
version_code = options[:version_code]
version_name = options[:version_name]
Expand Down Expand Up @@ -112,7 +112,7 @@ platform :ios do
)
end

desc "Promote the app from beta (testflight) to production"
desc "Promote the ios app from beta (testflight) to production"
lane :promote do |options|
apple_auth()

Expand Down

0 comments on commit c1a33db

Please sign in to comment.