From be95e1fb98958ffde569815d78bb8045297d9a43 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Fri, 31 May 2024 13:50:56 -0300 Subject: [PATCH 01/11] feat: adding basic setup for fastlane --- Gemfile | 3 + Gemfile.lock | 219 +++++++++++++++++++++++++++++++++++++++++++++ fastlane/Appfile | 2 + fastlane/Fastfile | 38 ++++++++ fastlane/README.md | 48 ++++++++++ 5 files changed, 310 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 fastlane/Appfile create mode 100644 fastlane/Fastfile create mode 100644 fastlane/README.md diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..adc90d9 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem "fastlane" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..2e965f0 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,219 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (3.0.7) + base64 + nkf + rexml + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + artifactory (3.0.17) + atomos (0.1.3) + aws-eventstream (1.3.0) + aws-partitions (1.937.0) + aws-sdk-core (3.196.1) + aws-eventstream (~> 1, >= 1.3.0) + aws-partitions (~> 1, >= 1.651.0) + aws-sigv4 (~> 1.8) + jmespath (~> 1, >= 1.6.1) + aws-sdk-kms (1.82.0) + aws-sdk-core (~> 3, >= 3.193.0) + aws-sigv4 (~> 1.1) + aws-sdk-s3 (1.151.0) + aws-sdk-core (~> 3, >= 3.194.0) + aws-sdk-kms (~> 1) + aws-sigv4 (~> 1.8) + aws-sigv4 (1.8.0) + aws-eventstream (~> 1, >= 1.0.2) + babosa (1.0.4) + base64 (0.2.0) + claide (1.1.0) + colored (1.2) + colored2 (3.1.2) + commander (4.6.0) + highline (~> 2.0.0) + declarative (0.0.20) + digest-crc (0.6.5) + rake (>= 12.0.0, < 14.0.0) + domain_name (0.6.20240107) + dotenv (2.8.1) + emoji_regex (3.2.3) + excon (0.110.0) + faraday (1.10.3) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-cookie_jar (0.0.7) + faraday (>= 0.8.0) + http-cookie (~> 1.0.0) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + faraday_middleware (1.2.0) + faraday (~> 1.0) + fastimage (2.3.1) + fastlane (2.220.0) + CFPropertyList (>= 2.3, < 4.0.0) + addressable (>= 2.8, < 3.0.0) + artifactory (~> 3.0) + aws-sdk-s3 (~> 1.0) + babosa (>= 1.0.3, < 2.0.0) + bundler (>= 1.12.0, < 3.0.0) + colored (~> 1.2) + commander (~> 4.6) + dotenv (>= 2.1.1, < 3.0.0) + emoji_regex (>= 0.1, < 4.0) + excon (>= 0.71.0, < 1.0.0) + faraday (~> 1.0) + faraday-cookie_jar (~> 0.0.6) + faraday_middleware (~> 1.0) + fastimage (>= 2.1.0, < 3.0.0) + gh_inspector (>= 1.1.2, < 2.0.0) + google-apis-androidpublisher_v3 (~> 0.3) + google-apis-playcustomapp_v1 (~> 0.1) + google-cloud-env (>= 1.6.0, < 2.0.0) + google-cloud-storage (~> 1.31) + highline (~> 2.0) + http-cookie (~> 1.0.5) + json (< 3.0.0) + jwt (>= 2.1.0, < 3) + mini_magick (>= 4.9.4, < 5.0.0) + multipart-post (>= 2.0.0, < 3.0.0) + naturally (~> 2.2) + optparse (>= 0.1.1, < 1.0.0) + plist (>= 3.1.0, < 4.0.0) + rubyzip (>= 2.0.0, < 3.0.0) + security (= 0.1.5) + simctl (~> 1.6.3) + terminal-notifier (>= 2.0.0, < 3.0.0) + terminal-table (~> 3) + tty-screen (>= 0.6.3, < 1.0.0) + tty-spinner (>= 0.8.0, < 1.0.0) + word_wrap (~> 1.0.0) + xcodeproj (>= 1.13.0, < 2.0.0) + xcpretty (~> 0.3.0) + xcpretty-travis-formatter (>= 0.0.3, < 2.0.0) + gh_inspector (1.1.3) + google-apis-androidpublisher_v3 (0.54.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-core (0.11.3) + addressable (~> 2.5, >= 2.5.1) + googleauth (>= 0.16.2, < 2.a) + httpclient (>= 2.8.1, < 3.a) + mini_mime (~> 1.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.a) + rexml + google-apis-iamcredentials_v1 (0.17.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-playcustomapp_v1 (0.13.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-storage_v1 (0.31.0) + google-apis-core (>= 0.11.0, < 2.a) + google-cloud-core (1.7.0) + google-cloud-env (>= 1.0, < 3.a) + google-cloud-errors (~> 1.0) + google-cloud-env (1.6.0) + faraday (>= 0.17.3, < 3.0) + google-cloud-errors (1.4.0) + google-cloud-storage (1.47.0) + addressable (~> 2.8) + digest-crc (~> 0.4) + google-apis-iamcredentials_v1 (~> 0.1) + google-apis-storage_v1 (~> 0.31.0) + google-cloud-core (~> 1.6) + googleauth (>= 0.16.2, < 2.a) + mini_mime (~> 1.0) + googleauth (1.8.1) + faraday (>= 0.17.3, < 3.a) + jwt (>= 1.4, < 3.0) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (>= 0.16, < 2.a) + highline (2.0.3) + http-cookie (1.0.5) + domain_name (~> 0.5) + httpclient (2.8.3) + jmespath (1.6.2) + json (2.7.2) + jwt (2.8.1) + base64 + mini_magick (4.12.0) + mini_mime (1.1.5) + multi_json (1.15.0) + multipart-post (2.4.1) + nanaimo (0.3.0) + naturally (2.2.1) + nkf (0.2.0) + optparse (0.5.0) + os (1.1.4) + plist (3.7.1) + public_suffix (5.0.5) + rake (13.2.1) + representable (3.2.0) + declarative (< 0.1.0) + trailblazer-option (>= 0.1.1, < 0.2.0) + uber (< 0.2.0) + retriable (3.1.2) + rexml (3.2.8) + strscan (>= 3.0.9) + rouge (2.0.7) + ruby2_keywords (0.0.5) + rubyzip (2.3.2) + security (0.1.5) + signet (0.19.0) + addressable (~> 2.8) + faraday (>= 0.17.5, < 3.a) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) + simctl (1.6.10) + CFPropertyList + naturally + strscan (3.1.0) + terminal-notifier (2.0.0) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) + trailblazer-option (0.1.2) + tty-cursor (0.7.1) + tty-screen (0.8.2) + tty-spinner (0.9.3) + tty-cursor (~> 0.7) + uber (0.1.0) + unicode-display_width (2.5.0) + word_wrap (1.0.0) + xcodeproj (1.24.0) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.3) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.3.0) + rexml (~> 3.2.4) + xcpretty (0.3.0) + rouge (~> 2.0.7) + xcpretty-travis-formatter (1.0.1) + xcpretty (~> 0.2, >= 0.0.7) + +PLATFORMS + x64-mingw-ucrt + +DEPENDENCIES + fastlane + +BUNDLED WITH + 2.5.11 diff --git a/fastlane/Appfile b/fastlane/Appfile new file mode 100644 index 0000000..51a64cc --- /dev/null +++ b/fastlane/Appfile @@ -0,0 +1,2 @@ +json_key_file("play-store-credentials.json") # Path to the json secret file - Follow https://docs.fastlane.tools/actions/supply/#setup to get one +package_name("com.routinely.routinely") # e.g. com.krausefx.app diff --git a/fastlane/Fastfile b/fastlane/Fastfile new file mode 100644 index 0000000..19c557c --- /dev/null +++ b/fastlane/Fastfile @@ -0,0 +1,38 @@ +# 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 + +default_platform(:android) + +platform :android do + desc "Runs all the tests" + lane :test do + gradle(task: "test") + end + + desc "Submit a new Beta Build to Crashlytics Beta" + lane :beta do + gradle(task: "clean assembleRelease") + crashlytics + + # sh "your_script.sh" + # You can also use other beta testing services here + end + + desc "Deploy a new version to the Google Play" + lane :deploy do + gradle(task: "clean assembleRelease") + upload_to_play_store + end +end diff --git a/fastlane/README.md b/fastlane/README.md new file mode 100644 index 0000000..7ec1207 --- /dev/null +++ b/fastlane/README.md @@ -0,0 +1,48 @@ +fastlane documentation +---- + +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +```sh +xcode-select --install +``` + +For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane) + +# Available Actions + +## Android + +### android test + +```sh +[bundle exec] fastlane android test +``` + +Runs all the tests + +### android beta + +```sh +[bundle exec] fastlane android beta +``` + +Submit a new Beta Build to Crashlytics Beta + +### android deploy + +```sh +[bundle exec] fastlane android deploy +``` + +Deploy a new version to the Google Play + +---- + +This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. + +More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools). + +The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools). From 575bbabccceec8dd5fa67a5f30bfa218f5693aa4 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Sun, 2 Jun 2024 22:29:19 -0300 Subject: [PATCH 02/11] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 347e252..2d52bf2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ misc.xml deploymentTargetDropDown.xml render.experimental.xml + # Keystore files *.jks *.keystore From 0a2b03a5239acbfe44704543f5e8f23375eb028e Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Fri, 31 May 2024 14:51:23 -0300 Subject: [PATCH 03/11] feat: new QA pipeline --- .github/workflows/build-and-test.yml | 6 +- .github/workflows/deploy-qa.yml | 39 +++--- Gemfile | 4 +- Gemfile.lock | 10 ++ fastlane/Fastfile | 177 +++++++++++++++++++++++++-- fastlane/Pluginfile | 6 + fastlane/README.md | 12 +- 7 files changed, 212 insertions(+), 42 deletions(-) create mode 100644 fastlane/Pluginfile diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b8303a4..132186f 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -14,8 +14,10 @@ jobs: BASE_SCHEME: ${{ secrets.BASE_URL_DEBUG }} steps: - - name: Check out code - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v3 diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 88ae397..891b1ab 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -15,7 +15,6 @@ jobs: env: isCI: "true" - BASE_SCHEME: ${{ secrets.BASE_URL_DEBUG }} steps: - name: Checkout repository @@ -29,29 +28,25 @@ jobs: distribution: adopt java-version: "17" - - name: Increment version - id: increment-version - uses: RichardInnocent/semantic-versioning-git@v0.0.1 + - name: Adding Firebase Credentials Json File + run: echo "${{ secrets.CREDENTIAL_FILE_CONTENT }}" > credential_file_content.json - - name: Create local.properties - run: | - echo "BASE_URL=${BASE_SCHEME}" >> local.properties - echo "CI_VERSION_NAME=${{ env.new_version }}" >> local.properties - echo "CI_VERSION_CODE=${{ github.run_number }}" >> local.properties - env: - new_version: ${{ steps.increment-version.outputs.new-version }} + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.3 - - name: Build android - run: ./gradlew clean assembleDebug --stacktrace + - name: Add current platform to Bundler lockfile + run: | + bundle lock --add-platform ruby + bundle lock --add-platform x86_64-linux + - name: Install Gems + run: bundle install - - name: Upload Apk to Firebase App Distribution QA - uses: wzieba/Firebase-Distribution-Github-Action@v1 - with: - appId: ${{secrets.FIREBASE_APP_ID}} - serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} - file: app/build/outputs/apk/debug/app-debug.apk - groups: routinely---qa - releaseNotes: "Versão QA ${{ env.new_version }}" + - name: Build and Deploy QA + run: bundle exec fastlane qa env: - new_version: ${{ steps.increment-version.outputs.new-version }} + BASE_URL: ${{ secrets.BASE_URL_DEBUG }} + GITHUB_RUNNER_NUMBER: ${{ github.run_number }} + FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID }} diff --git a/Gemfile b/Gemfile index adc90d9..2ccf2ec 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source "https://rubygems.org" -gem "fastlane" \ No newline at end of file +gem "fastlane" +plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') +eval_gemfile(plugins_path) if File.exist?(plugins_path) diff --git a/Gemfile.lock b/Gemfile.lock index 2e965f0..b23d380 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,6 +109,10 @@ GEM xcodeproj (>= 1.13.0, < 2.0.0) xcpretty (~> 0.3.0) xcpretty-travis-formatter (>= 0.0.3, < 2.0.0) + fastlane-plugin-firebase_app_distribution (0.9.1) + google-apis-firebaseappdistribution_v1 (~> 0.3.0) + google-apis-firebaseappdistribution_v1alpha (~> 0.2.0) + fastlane-plugin-semantic_release (1.18.2) gh_inspector (1.1.3) google-apis-androidpublisher_v3 (0.54.0) google-apis-core (>= 0.11.0, < 2.a) @@ -120,6 +124,10 @@ GEM representable (~> 3.0) retriable (>= 2.0, < 4.a) rexml + google-apis-firebaseappdistribution_v1 (0.3.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-firebaseappdistribution_v1alpha (0.2.0) + google-apis-core (>= 0.11.0, < 2.a) google-apis-iamcredentials_v1 (0.17.0) google-apis-core (>= 0.11.0, < 2.a) google-apis-playcustomapp_v1 (0.13.0) @@ -214,6 +222,8 @@ PLATFORMS DEPENDENCIES fastlane + fastlane-plugin-firebase_app_distribution + fastlane-plugin-semantic_release BUNDLED WITH 2.5.11 diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 19c557c..da5f2ec 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -15,24 +15,179 @@ default_platform(:android) +QA = "QA" + platform :android do desc "Runs all the tests" lane :test do gradle(task: "test") end - desc "Submit a new Beta Build to Crashlytics Beta" - lane :beta do - gradle(task: "clean assembleRelease") - crashlytics - - # sh "your_script.sh" - # You can also use other beta testing services here + desc "Build and Deploy QA version on Firebase App Distribution" + lane :qa do + # Function: + # This lane builds the QA version of the app and deploys it to Firebase App Distribution. + + environment = QA + version_code = ENV['GITHUB_RUNNER_NUMBER'] + base_api = ENV['BASE_URL'] + + version_name, changelog = generate_changelog( + tag_match: "#{environment}/*", + ) + + build( + environment: environment, + version_name: version_name, + version_code: version_code, + base_api: base_api + ) + + publish_on_firebase( + environment: environment, + changelog: changelog + ) + + pos_deploy(tag: "qa/#{next_version}") + end + + desc "Create local properties and return it" + private_lane :create_local_properties do |options| + # Parameters: + # :version_name (String): The version name of the app. + # :version_code (String): The version code of the app. + # :base_api (String): The base API URL. + # Function: + # This lane creates the local properties based on the provided options. + + version_name = options[:version_name] + version_code = options[:version_code] + base_api = options[:base_api] + + local_properties = { + 'BASE_URL' => base_api, + 'CI_VERSION_NAME' => version_name, + 'CI_VERSION_CODE' => version_code, + } + end + + desc "Build android project" + private_lane :build do |options| + # Parameters: + # :environment (String): The build environment (e.g., QA). + # :version_name (String): The version name of the app. + # :version_code (String): The version code of the app. + # :base_api (String): The base API URL. + # Function: + # This lane builds the Android project using the provided options. + + environment = options[:environment] + version_name = options[:version_name] + version_code = options[:version_code] + base_api = options[:base_api] + + local_properties = create_local_properties( + version_name: version_name, + version_code: version_code, + base_api: base_api + ) + + case environment + when QA + gradle_task = 'clean assemble' + gradle_build_type = 'Debug' + end + + gradle( + task: gradle_task, + build_type: gradle_build_type, + print_command: false, + properties: local_properties + ) + end + + desc "Publish version on Firebase App Distribution" + private_lane :publish_on_firebase do |options| + # Parameters: + # :environment (String): The build environment (e.g., QA). + # :changelog (String): The changelog for this release. + # Function: + # This lane publishes the built app version on Firebase App Distribution using the provided options. + + environment = options[:environment] + changelog = options[:changelog] + + case environment + when QA + groups = "routinely---qa" + end + + firebase_app_distribution( + app: ENV['FIREBASE_APP_ID'], + groups: groups, + release_notes: changelog, + service_credentials_file: "credential_file_content.json" + ) + end + + desc "Generate tag and changelog by semantic versioning 2.0.0" + private_lane :generate_changelog do |options| + # Parameters: + # :tag_match (String): The pattern to match tags. + # Output: + # [String, String]: The next version and the changelog. + # Function: + # This lane generates the next version and changelog based on semantic versioning. + + match = options[:tag_match] + git_pull(only_tags: true) + + analyze_commits( + match: match, + ) + + next_version = lane_context[SharedValues::RELEASE_NEXT_VERSION] + + changelog = conventional_changelog( + format: 'slack', + title: 'Android Alpha', + display_author: false, + display_links: false, + debug: false + ) + + return next_version, changelog end - desc "Deploy a new version to the Google Play" - lane :deploy do - gradle(task: "clean assembleRelease") - upload_to_play_store + desc "Lane to be executed after each deploy lane" + private_lane :pos_deploy do |options| + # Parameters: + # :tag (String): The tag to be created. + # :changelog (String): The changelog for the tag. + # Function: + # This lane is executed after each deploy lane, creating and pushing a git tag. + + tag = options[:tag] + changelog = options[:changelog] + + add_git_tag(tag: tag, message: changelog) + push_git_tags end end + +desc "Create and push a git tag" +lane :create_and_push_tag do |options| + # Parameters: + # :tag (String): The tag to be created. + # Function: + # This lane creates a git tag and pushes it to the remote repository. + + tag = options[:tag] + + if tag.nil? || tag.empty? + UI.user_error!("You must provide a tag name.") + end + + sh("git tag #{tag}") + sh("git push origin #{tag}") +end diff --git a/fastlane/Pluginfile b/fastlane/Pluginfile new file mode 100644 index 0000000..32a23fc --- /dev/null +++ b/fastlane/Pluginfile @@ -0,0 +1,6 @@ +# Autogenerated by fastlane +# +# Ensure this file is checked in to source control! + +gem 'fastlane-plugin-firebase_app_distribution' +gem 'fastlane-plugin-semantic_release' diff --git a/fastlane/README.md b/fastlane/README.md index 7ec1207..3abb457 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -23,21 +23,21 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do Runs all the tests -### android beta +### android qa ```sh -[bundle exec] fastlane android beta +[bundle exec] fastlane android qa ``` -Submit a new Beta Build to Crashlytics Beta +Build and Deploy QA version on Firebase App Distribution -### android deploy +### android generate_changelog ```sh -[bundle exec] fastlane android deploy +[bundle exec] fastlane android generate_changelog ``` -Deploy a new version to the Google Play +Generate tag and changelog by semantic versioning 2.0.0 ---- From 2b650ea5e70c1778afe3c8e6088440a27cbaa2c6 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:19:21 -0300 Subject: [PATCH 04/11] feat: updating test lane to use fastlane --- .github/workflows/android-tests.yml | 43 ++++++++++++++++++++++++++++ .github/workflows/build-and-test.yml | 32 --------------------- fastlane/Fastfile | 10 ++++++- 3 files changed, 52 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/android-tests.yml delete mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/workflows/android-tests.yml b/.github/workflows/android-tests.yml new file mode 100644 index 0000000..65cc848 --- /dev/null +++ b/.github/workflows/android-tests.yml @@ -0,0 +1,43 @@ +name: Tests + +on: + pull_request: + branches: + - '*' + +jobs: + android_build_and_test: + name: Android - run tests + runs-on: ubuntu-22.04 + env: + isCI: "true" + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: adopt + java-version: "17" + + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.3 + + - name: Add current platform to Bundler lockfile + run: | + bundle lock --add-platform ruby + bundle lock --add-platform x86_64-linux + + - name: Install Gems + run: bundle install + + - name: Run Tests + run: bundle exec fastlane test + env: + BASE_URL: ${{ secrets.BASE_URL_DEBUG }} diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index 132186f..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Build and test - -on: - pull_request: - branches: - - '*' - -jobs: - android_build_and_test: - name: Android - build and test - runs-on: ubuntu-22.04 - env: - isCI: "true" - BASE_SCHEME: ${{ secrets.BASE_URL_DEBUG }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: adopt - java-version: "17" - - - name: Create local.properties - run: echo "BASE_URL=${BASE_SCHEME}" >> local.properties - - - name: Build android - run: ./gradlew assembleDebug --stacktrace diff --git a/fastlane/Fastfile b/fastlane/Fastfile index da5f2ec..9bb8f5d 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -20,7 +20,15 @@ QA = "QA" platform :android do desc "Runs all the tests" lane :test do - gradle(task: "test") + # Function: + # This lane run tests with properties BASE_URL + gradle( + task: "test", + print_command: false, + properties: { + "BASE_URL" => ENV['BASE_URL'] + } + ) end desc "Build and Deploy QA version on Firebase App Distribution" From 5e4b81d5a2f1b971b4ffcd4a0bf0ebed094924bb Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:23:32 -0300 Subject: [PATCH 05/11] fix: Creating local properties file --- fastlane/Fastfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 9bb8f5d..c16130c 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -21,13 +21,16 @@ platform :android do desc "Runs all the tests" lane :test do # Function: - # This lane run tests with properties BASE_URL + # This lane creates local properties and run the tests + + properties = create_local_properties( + base_url: ENV['BASE_URL'] + ) + gradle( task: "test", print_command: false, - properties: { - "BASE_URL" => ENV['BASE_URL'] - } + properties: properties ) end From 2de5e0dee67e8d056e9868a401c611353883d626 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:30:36 -0300 Subject: [PATCH 06/11] fix: Create error handler and setting local properties at create local properties lane --- fastlane/Fastfile | 256 ++++++++++++++++++++++++---------------------- 1 file changed, 136 insertions(+), 120 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index c16130c..b444813 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -22,44 +22,49 @@ platform :android do lane :test do # Function: # This lane creates local properties and run the tests - - properties = create_local_properties( - base_url: ENV['BASE_URL'] - ) - - gradle( - task: "test", - print_command: false, - properties: properties - ) + begin + create_local_properties( + base_url: ENV['BASE_URL'] + ) + + gradle( + task: "test", + print_command: false, + ) + rescue => e + error_handler('test', e) + end end desc "Build and Deploy QA version on Firebase App Distribution" lane :qa do # Function: # This lane builds the QA version of the app and deploys it to Firebase App Distribution. - - environment = QA - version_code = ENV['GITHUB_RUNNER_NUMBER'] - base_api = ENV['BASE_URL'] - - version_name, changelog = generate_changelog( - tag_match: "#{environment}/*", - ) - - build( - environment: environment, - version_name: version_name, - version_code: version_code, - base_api: base_api - ) - - publish_on_firebase( - environment: environment, - changelog: changelog - ) - - pos_deploy(tag: "qa/#{next_version}") + begin + environment = QA + version_code = ENV['GITHUB_RUNNER_NUMBER'] + base_api = ENV['BASE_URL'] + + version_name, changelog = generate_changelog( + tag_match: "#{environment}/*", + ) + + build( + environment: environment, + version_name: version_name, + version_code: version_code, + base_api: base_api + ) + + publish_on_firebase( + environment: environment, + changelog: changelog + ) + + pos_deploy(tag: "qa/#{next_version}") + rescue => e + error_handler('qa', e) + end end desc "Create local properties and return it" @@ -69,17 +74,28 @@ platform :android do # :version_code (String): The version code of the app. # :base_api (String): The base API URL. # Function: - # This lane creates the local properties based on the provided options. - - version_name = options[:version_name] - version_code = options[:version_code] - base_api = options[:base_api] - - local_properties = { - 'BASE_URL' => base_api, - 'CI_VERSION_NAME' => version_name, - 'CI_VERSION_CODE' => version_code, - } + # This lane creates the local properties based on the provided options and writes them to local.properties. + begin + version_name = options[:version_name] + version_code = options[:version_code] + base_api = options[:base_api] + + local_properties = { + 'BASE_URL' => base_api, + 'CI_VERSION_NAME' => version_name, + 'CI_VERSION_CODE' => version_code, + } + + File.open("local.properties", "w") do |file| + local_properties.each do |key, value| + file.puts("#{key}=#{value}") + end + end + + return local_properties + rescue => e + error_handler('create_local_properties', e) + end end desc "Build android project" @@ -91,30 +107,32 @@ platform :android do # :base_api (String): The base API URL. # Function: # This lane builds the Android project using the provided options. - - environment = options[:environment] - version_name = options[:version_name] - version_code = options[:version_code] - base_api = options[:base_api] - - local_properties = create_local_properties( - version_name: version_name, - version_code: version_code, - base_api: base_api - ) - - case environment - when QA - gradle_task = 'clean assemble' - gradle_build_type = 'Debug' + begin + environment = options[:environment] + version_name = options[:version_name] + version_code = options[:version_code] + base_api = options[:base_api] + + create_local_properties( + version_name: version_name, + version_code: version_code, + base_api: base_api + ) + + case environment + when QA + gradle_task = 'clean assemble' + gradle_build_type = 'Debug' + end + + gradle( + task: gradle_task, + build_type: gradle_build_type, + print_command: false + ) + rescue => e + error_handler('build', e) end - - gradle( - task: gradle_task, - build_type: gradle_build_type, - print_command: false, - properties: local_properties - ) end desc "Publish version on Firebase App Distribution" @@ -124,21 +142,24 @@ platform :android do # :changelog (String): The changelog for this release. # Function: # This lane publishes the built app version on Firebase App Distribution using the provided options. - - environment = options[:environment] - changelog = options[:changelog] - - case environment - when QA - groups = "routinely---qa" + begin + environment = options[:environment] + changelog = options[:changelog] + + case environment + when QA + groups = "routinely---qa" + end + + firebase_app_distribution( + app: ENV['FIREBASE_APP_ID'], + groups: groups, + release_notes: changelog, + service_credentials_file: "credential_file_content.json" + ) + rescue => e + error_handler('publish_on_firebase', e) end - - firebase_app_distribution( - app: ENV['FIREBASE_APP_ID'], - groups: groups, - release_notes: changelog, - service_credentials_file: "credential_file_content.json" - ) end desc "Generate tag and changelog by semantic versioning 2.0.0" @@ -149,25 +170,28 @@ platform :android do # [String, String]: The next version and the changelog. # Function: # This lane generates the next version and changelog based on semantic versioning. - - match = options[:tag_match] - git_pull(only_tags: true) - - analyze_commits( - match: match, - ) - - next_version = lane_context[SharedValues::RELEASE_NEXT_VERSION] - - changelog = conventional_changelog( - format: 'slack', - title: 'Android Alpha', - display_author: false, - display_links: false, - debug: false - ) - - return next_version, changelog + begin + match = options[:tag_match] + git_pull(only_tags: true) + + analyze_commits( + match: match, + ) + + next_version = lane_context[SharedValues::RELEASE_NEXT_VERSION] + + changelog = conventional_changelog( + format: 'slack', + title: 'Android Alpha', + display_author: false, + display_links: false, + debug: false + ) + + return next_version, changelog + rescue => e + error_handler('generate_changelog', e) + end end desc "Lane to be executed after each deploy lane" @@ -177,28 +201,20 @@ platform :android do # :changelog (String): The changelog for the tag. # Function: # This lane is executed after each deploy lane, creating and pushing a git tag. - - tag = options[:tag] - changelog = options[:changelog] - - add_git_tag(tag: tag, message: changelog) - push_git_tags + begin + tag = options[:tag] + changelog = options[:changelog] + + add_git_tag(tag: tag, message: changelog) + push_git_tags + rescue => e + error_handler('pos_deploy', e) + end end end -desc "Create and push a git tag" -lane :create_and_push_tag do |options| - # Parameters: - # :tag (String): The tag to be created. - # Function: - # This lane creates a git tag and pushes it to the remote repository. - - tag = options[:tag] - - if tag.nil? || tag.empty? - UI.user_error!("You must provide a tag name.") - end - - sh("git tag #{tag}") - sh("git push origin #{tag}") +# Define an error handler method to capture and log errors +def error_handler(lane_name, exception) + UI.error("Lane '#{lane_name}' failed with error: #{exception.message}") + UI.error(exception.backtrace.join("\n")) end From 5f8af21d43f7923d6e90f5136b7794214d096b91 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:35:57 -0300 Subject: [PATCH 07/11] fix: Raising exception --- fastlane/Fastfile | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index b444813..d31ad7e 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -67,36 +67,34 @@ platform :android do end end - desc "Create local properties and return it" - private_lane :create_local_properties do |options| - # Parameters: - # :version_name (String): The version name of the app. - # :version_code (String): The version code of the app. - # :base_api (String): The base API URL. - # Function: - # This lane creates the local properties based on the provided options and writes them to local.properties. - begin - version_name = options[:version_name] - version_code = options[:version_code] - base_api = options[:base_api] - - local_properties = { - 'BASE_URL' => base_api, - 'CI_VERSION_NAME' => version_name, - 'CI_VERSION_CODE' => version_code, - } - - File.open("local.properties", "w") do |file| - local_properties.each do |key, value| - file.puts("#{key}=#{value}") + desc "Create local properties" + private_lane :create_local_properties do |options| + # Parameters: + # :version_name (String): The version name of the app. + # :version_code (String): The version code of the app. + # :base_api (String): The base API URL. + # Function: + # This lane creates the local properties based on the provided options and writes them to local.properties. + begin + version_name = options[:version_name] + version_code = options[:version_code] + base_api = options[:base_api] + + local_properties = { + 'BASE_URL' => base_api, + 'CI_VERSION_NAME' => version_name, + 'CI_VERSION_CODE' => version_code, + } + + File.open("local.properties", "w") do |file| + local_properties.each do |key, value| + file.puts("#{key}=#{value}") + end end + rescue => e + error_handler('create_local_properties', e) end - - return local_properties - rescue => e - error_handler('create_local_properties', e) end - end desc "Build android project" private_lane :build do |options| @@ -217,4 +215,5 @@ end def error_handler(lane_name, exception) UI.error("Lane '#{lane_name}' failed with error: #{exception.message}") UI.error(exception.backtrace.join("\n")) + raise exception end From 7b31e4959de4cef7350508c85d7166d68497acad Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:41:03 -0300 Subject: [PATCH 08/11] fix: Adding version name and version code to test local properties --- fastlane/Fastfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index d31ad7e..ca12946 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -24,7 +24,9 @@ platform :android do # This lane creates local properties and run the tests begin create_local_properties( - base_url: ENV['BASE_URL'] + base_url: ENV['BASE_URL'], + version_name: "1.0.0", + version_code: 1 ) gradle( From 82ec19231fdddf4cfc8a695569fc4549e9045397 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:55:33 -0300 Subject: [PATCH 09/11] fix: Creating local properties at correctly path --- fastlane/Fastfile | 50 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index ca12946..f8206ce 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -70,33 +70,35 @@ platform :android do end desc "Create local properties" - private_lane :create_local_properties do |options| - # Parameters: - # :version_name (String): The version name of the app. - # :version_code (String): The version code of the app. - # :base_api (String): The base API URL. - # Function: - # This lane creates the local properties based on the provided options and writes them to local.properties. - begin - version_name = options[:version_name] - version_code = options[:version_code] - base_api = options[:base_api] - - local_properties = { - 'BASE_URL' => base_api, - 'CI_VERSION_NAME' => version_name, - 'CI_VERSION_CODE' => version_code, - } - - File.open("local.properties", "w") do |file| - local_properties.each do |key, value| - file.puts("#{key}=#{value}") + private_lane :create_local_properties do |options| + # Parameters: + # :version_name (String): The version name of the app. + # :version_code (String): The version code of the app. + # :base_api (String): The base API URL. + # Function: + # This lane creates the local properties based on the provided options and writes them to local.properties. + begin + version_name = options[:version_name] + version_code = options[:version_code] + base_api = options[:base_api] + + local_properties = { + 'BASE_URL' => base_api, + 'CI_VERSION_NAME' => version_name, + 'CI_VERSION_CODE' => version_code, + } + + Dir.chdir("..") do + File.open("local.properties", "w") do |file| + local_properties.each do |key, value| + file.puts("#{key}=#{value}") + end end - end - rescue => e - error_handler('create_local_properties', e) end + rescue => e + error_handler('create_local_properties', e) end + end desc "Build android project" private_lane :build do |options| From c7617849c58ebc3321302a521e75fbefeed0c92f Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 09:59:27 -0300 Subject: [PATCH 10/11] fix: local properties property name --- fastlane/Fastfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index f8206ce..7172768 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -24,9 +24,7 @@ platform :android do # This lane creates local properties and run the tests begin create_local_properties( - base_url: ENV['BASE_URL'], - version_name: "1.0.0", - version_code: 1 + base_api: ENV['BASE_URL'] ) gradle( From 36e6d55af58d90eebc451329a3bf69a47d48b815 Mon Sep 17 00:00:00 2001 From: Ruliam dos Santos de Oliveira Date: Mon, 3 Jun 2024 10:02:50 -0300 Subject: [PATCH 11/11] fix: adding version name and version code to tests lane --- fastlane/Fastfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 7172768..6b58807 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -24,7 +24,9 @@ platform :android do # This lane creates local properties and run the tests begin create_local_properties( - base_api: ENV['BASE_URL'] + base_api: ENV['BASE_URL'], + version_name: "1.0.0", + version_code: 1 ) gradle(