digitalfabrik/integreat-app

View on GitHub
native/android/fastlane/Fastfile

Summary

Maintainability
Test Coverage
fastlane_version "2.220.0"

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

KEYSTORE_PATH = ENV['KEYSTORE_PATH']
KEYSTORE_KEY_ALIAS = ENV['KEYSTORE_KEY_ALIAS']
KEYSTORE_PASSWORD = ENV['KEYSTORE_PASSWORD']
KEYSTORE_KEY_PASSWORD = ENV['KEYSTORE_KEY_PASSWORD']

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']
  )

  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

  puts("Decrypting keystore")

  sh("openssl enc -d -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt \\
          -in #{CREDENTIALS_KEYSTORE_PATH} -out #{KEYSTORE_PATH} \\
          -pass pass:$CREDENTIALS_KEYSTORE_PASSWORD")
end

desc "Download Gradle dependencies"
lane :dependencies do
  gradle(task: "androidDependencies")
end

# The following parameters have to be passed:
# version_code: The version code of the app
# version_name: The version name of the app
# build_config_name: The name of the build config
desc "Create an Android build in release mode. Set the environment variable E2E_TEST_IDS if you want a build usable for E2E tests. Set the environment variable TOTAL_CPUS if you run this in a Docker container."
lane :build do |options|
  version_code = options[:version_code]
  version_name = options[:version_name]
  build_config_name = options[:build_config_name]

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

  # DO NOT OVERWRITE THE BUNDLE_CONFIG ENV VARIABLE! It is used by ruby bundle.
  ENV["EXTRA_PACKAGER_ARGS"] = "--config ./metro.config.ci.js"
  # DO NOT REMOVE THIS! It is necessary for the javascript build config logic.
  ENV["BUILD_CONFIG_NAME"] = build_config_name

  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,
    # react-native is currently only guaranteed to work with JDK 17
    # See https://stackoverflow.com/questions/69619829/could-not-resolve-all-files-for-configuration-appandroidjdkimage
    # https://reactnative.dev/docs/environment-setup?guide=native&platform=android#installing-dependencies
    :"org.gradle.java.home" => "/usr/lib/jvm/java-17-openjdk-amd64"
  }

  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']
  end

  gradle(
      tasks: ["assembleRelease", "bundleRelease"],
      properties: {
          :BUILD_CONFIG_NAME => build_config_name,
          :VERSION_CODE => version_code,
          :VERSION_NAME => version_name,
          :KEYSTORE_PATH => KEYSTORE_PATH,
          :KEYSTORE_KEY_ALIAS => KEYSTORE_KEY_ALIAS,
          :KEYSTORE_PASSWORD => KEYSTORE_PASSWORD,
          :KEYSTORE_KEY_PASSWORD => KEYSTORE_KEY_PASSWORD
      }.compact,
      system_properties: gradle_system_properties,
      print_command: false
  )
end