From a7052e57b569ec8a971e2639bcccb10105743a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 24 Apr 2023 12:50:36 +0200 Subject: [PATCH] feat: implement first version of android cd pipeline (#1) --- .../android_cd/actions/android_cd_action.rb | 47 ------------- .../android_cd/actions/build_and_deploy.rb | 67 +++++++++++++++++++ .../android_cd/helper/android_cd_helper.rb | 26 ++++--- 3 files changed, 85 insertions(+), 55 deletions(-) delete mode 100644 plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/android_cd_action.rb create mode 100644 plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy.rb diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/android_cd_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/android_cd_action.rb deleted file mode 100644 index 71f4c8f..0000000 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/android_cd_action.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'fastlane/action' -require_relative '../helper/android_cd_helper' - -module Fastlane - module Actions - class AndroidCdAction < Action - def self.run(params) - UI.message("The android_cd plugin is working!") - end - - def self.description - "Google Play Store deployment plugin for Fastlane, simplifying the build and deployment process to internal, beta, alpha, and production channels, and promoting builds for testing." - end - - def self.authors - ["Malo Léon"] - end - - def self.return_value - # If your method provides a return value, you can describe here what it does - end - - def self.details - # Optional: - "The Fastlane Google Play Store deployment plugin streamlines the build and deployment process to internal, beta, alpha, and production channels, simplifying the process of distributing builds for testing. With its advanced promotion functionality, it also enables easy promotion of builds to higher beta testing phases, helping you get your app to market faster." - end - - def self.available_options - [ - # FastlaneCore::ConfigItem.new(key: :your_option, - # env_name: "ANDROID_CD_YOUR_OPTION", - # description: "A description of your option", - # optional: false, - # type: String) - ] - end - - def self.is_supported?(platform) - # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) - # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform - # - # [:ios, :mac, :android].include?(platform) - true - end - end - end -end diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy.rb new file mode 100644 index 0000000..cd0b48d --- /dev/null +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy.rb @@ -0,0 +1,67 @@ +require 'fastlane/action' +require_relative '../helper/android_cd_helper' + +module Fastlane + module Actions + class AndroidCdAction < Action + def self.run(params) + + # Decrypt the keys archive and Extract the keys archive + Helper::AppcenterHelper.decrypt_android_keys('../') + + # Clean the project before building + gradle(task: "clean") + + # Set the build number based on the number of commits + build_number = number_of_commits() + + # Build the Android App Bundle + gradle( + task: "bundle", + build_type: "Release", + print_command: true, + properties: { + "android.injected.version.code" => build_number, + } + ) + + # Upload the Android App Bundle to the Play Store + upload_to_play_store( + track: 'internal', + json_key: './service_account_key.json', + aab: '../build/app/outputs/bundle/release/app-release.aab', + skip_upload_metadata: true, + skip_upload_images: true, + skip_upload_screenshots: true, + release_status: "draft", + version_code: build_number, + package_name: 'com.jaggerlewis.jl_2022' + ) + end + + def self.description + "Google Play Store deployment plugin for Fastlane, simplifying the build and deployment process to internal, beta, alpha, and production channels, and promoting builds for testing." + end + + def self.authors + ["SAS Wyatt Studio"] + end + + def self.return_value + end + + def self.details + "The Fastlane Google Play Store deployment plugin streamlines the build and deployment process to internal, beta, alpha, and production channels, simplifying the process of distributing builds for testing. With its advanced promotion functionality, it also enables easy promotion of builds to higher beta testing phases, helping you get your app to market faster." + end + + def self.available_options + [ + ] + end + + def self.is_supported?(platform) + [:android].include?(platform) + end + end + end +end diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb index 72f8fb1..5563430 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb @@ -1,15 +1,25 @@ require 'fastlane_core/ui/ui' module Fastlane - UI = FastlaneCore::UI unless Fastlane.const_defined?("UI") - - module Helper + module Helper class AndroidCdHelper - # class methods that you define here become available in your action - # as `Helper::AndroidCdHelper.your_method` - # - def self.show_message - UI.message("Hello from the android_cd plugin helper!") + def self.decrypt_android_keys(android_directory) + + # Define the GPG command with options + gpg_command = "gpg --quiet --batch --yes --decrypt --passphrase=#{ENV['ANDROID_KEYS_SECRET_PASSPHRASE']} \ + --output #{android_directory}/android_keys.zip #{android_directory}/android_keys.zip.gpg" + + # Execute the GPG command using system + system(gpg_command) + + # Check if the command executed successfully + if $?.success? + + # Move the extracted files to the current directory + `jar xvf #{android_directory} && mv #{android_directory}/android_keys/* #{android_directory}` + else + puts "Erreur lors de la décompression du fichier GPG" + end end end end