From e6e6f0397b33e3a589a1e17c36b8e681b6d0c5b2 Mon Sep 17 00:00:00 2001
From: Rehan <mrehan.official@gmail.com>
Date: Tue, 13 Aug 2024 15:54:51 +0500
Subject: [PATCH] attempt 12 fcm fix

---
 .github/workflows/build-sample-apps.yml |   2 +-
 Apps/APN/fastlane/Appfile               |   2 +
 Apps/FCM/Gemfile.lock                   |  14 +++
 Apps/FCM/{ios => }/fastlane/Appfile     |   9 +-
 Apps/FCM/fastlane/Fastfile              |   2 +
 Apps/FCM/fastlane/Gymfile               |   8 ++
 Apps/FCM/fastlane/Matchfile             |   6 ++
 Apps/FCM/fastlane/Pluginfile            |   6 ++
 Apps/FCM/ios/fastlane/Fastfile          |   1 -
 Apps/FCM/ios/fastlane/README.md         | 131 ------------------------
 Apps/fastlane/helpers/build_helper.rb   |   1 +
 11 files changed, 48 insertions(+), 134 deletions(-)
 rename Apps/FCM/{ios => }/fastlane/Appfile (54%)
 create mode 100644 Apps/FCM/fastlane/Fastfile
 create mode 100644 Apps/FCM/fastlane/Gymfile
 create mode 100644 Apps/FCM/fastlane/Matchfile
 create mode 100644 Apps/FCM/fastlane/Pluginfile
 delete mode 100644 Apps/FCM/ios/fastlane/Fastfile
 delete mode 100644 Apps/FCM/ios/fastlane/README.md

diff --git a/.github/workflows/build-sample-apps.yml b/.github/workflows/build-sample-apps.yml
index 79873ef6..27aec434 100644
--- a/.github/workflows/build-sample-apps.yml
+++ b/.github/workflows/build-sample-apps.yml
@@ -164,7 +164,7 @@ jobs:
       - name: Build and upload Android app via Fastlane
         uses: maierj/fastlane-action@v3.1.0
         with:
-          subdirectory: Apps/${{ matrix.sample-app }}/android
+          subdirectory: Apps/${{ matrix.sample-app }}
           lane: 'android build'
         env:
           FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }}
diff --git a/Apps/APN/fastlane/Appfile b/Apps/APN/fastlane/Appfile
index de84e2e5..a2355557 100644
--- a/Apps/APN/fastlane/Appfile
+++ b/Apps/APN/fastlane/Appfile
@@ -1,5 +1,7 @@
 team_id "2YC97BQN3N"
 
+# Include all of the bundle identifiers for your iOS app and for your rich push target. 
+# You find the bundle identifier of each app inside of Xcode - https://stackoverflow.com/a/59131511
 app_identifier([
   "io.customer.ami",
   "io.customer.ami.richpush",
diff --git a/Apps/FCM/Gemfile.lock b/Apps/FCM/Gemfile.lock
index 880508cc..6fd85c80 100644
--- a/Apps/FCM/Gemfile.lock
+++ b/Apps/FCM/Gemfile.lock
@@ -166,6 +166,12 @@ GEM
       xcodeproj (>= 1.13.0, < 2.0.0)
       xcpretty (~> 0.3.0)
       xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
+    fastlane-plugin-find_firebase_app_id (0.1.2)
+    fastlane-plugin-firebase_app_distribution (0.9.1)
+      google-apis-firebaseappdistribution_v1 (~> 0.3.0)
+      google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
+    fastlane-plugin-versioning_android (0.1.1)
+    fastlane-plugin-versioning_ios (0.1.0)
     ffi (1.17.0)
     fourflusher (2.3.1)
     fuzzy_match (2.0.4)
@@ -180,6 +186,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)
@@ -287,6 +297,10 @@ PLATFORMS
 DEPENDENCIES
   cocoapods
   fastlane
+  fastlane-plugin-find_firebase_app_id
+  fastlane-plugin-firebase_app_distribution
+  fastlane-plugin-versioning_android
+  fastlane-plugin-versioning_ios
 
 BUNDLED WITH
    2.4.22
diff --git a/Apps/FCM/ios/fastlane/Appfile b/Apps/FCM/fastlane/Appfile
similarity index 54%
rename from Apps/FCM/ios/fastlane/Appfile
rename to Apps/FCM/fastlane/Appfile
index c0cb9748..fc8713f7 100644
--- a/Apps/FCM/ios/fastlane/Appfile
+++ b/Apps/FCM/fastlane/Appfile
@@ -1,3 +1,10 @@
+team_id "2YC97BQN3N"
+
 # Include all of the bundle identifiers for your iOS app and for your rich push target. 
 # You find the bundle identifier of each app inside of Xcode - https://stackoverflow.com/a/59131511
-app_identifier(["io.customer.rn-sample.fcm", "io.customer.rn-sample.fcm.richpush"])
\ No newline at end of file
+app_identifier([
+  "io.customer.rn-sample.fcm",
+  "io.customer.rn-sample.fcm.richpush",
+])
+
+package_name("io.customer.rn_sample.fcm")
diff --git a/Apps/FCM/fastlane/Fastfile b/Apps/FCM/fastlane/Fastfile
new file mode 100644
index 00000000..f9b6b22b
--- /dev/null
+++ b/Apps/FCM/fastlane/Fastfile
@@ -0,0 +1,2 @@
+# imports shared Fastfile from "Apps/fastlane/Fastfile"
+import "../../fastlane/Fastfile"
diff --git a/Apps/FCM/fastlane/Gymfile b/Apps/FCM/fastlane/Gymfile
new file mode 100644
index 00000000..d4dfb042
--- /dev/null
+++ b/Apps/FCM/fastlane/Gymfile
@@ -0,0 +1,8 @@
+# For more information about this configuration run `fastlane gym --help` or check
+# out the documentation at https://docs.fastlane.tools/actions/gym/#gymfile
+
+configuration("Release")
+export_method("ad-hoc")
+# scheme in XCode workspace of Flutter generated iOS app
+scheme("FCMSampleApp")
+workspace("ios/FCMSampleApp.xcworkspace")
diff --git a/Apps/FCM/fastlane/Matchfile b/Apps/FCM/fastlane/Matchfile
new file mode 100644
index 00000000..d6d38f59
--- /dev/null
+++ b/Apps/FCM/fastlane/Matchfile
@@ -0,0 +1,6 @@
+storage_mode "google_cloud"
+type "development"
+readonly true
+# IMPORTANT: use the same gcloud bucket name for *all* iOS apps we use in the company. 
+# fastlane is smart enough to share certificates while creating separate provisioning profiles for each app. 
+google_cloud_bucket_name "remote-habits-ios-signing"
diff --git a/Apps/FCM/fastlane/Pluginfile b/Apps/FCM/fastlane/Pluginfile
new file mode 100644
index 00000000..3b6a9154
--- /dev/null
+++ b/Apps/FCM/fastlane/Pluginfile
@@ -0,0 +1,6 @@
+# Gemfile containing all the necessary plugins used by fastlane in the project
+
+gem 'fastlane-plugin-firebase_app_distribution'
+gem 'fastlane-plugin-versioning_android'
+gem 'fastlane-plugin-versioning_ios'
+gem 'fastlane-plugin-find_firebase_app_id'
diff --git a/Apps/FCM/ios/fastlane/Fastfile b/Apps/FCM/ios/fastlane/Fastfile
deleted file mode 100644
index 1de6a7e0..00000000
--- a/Apps/FCM/ios/fastlane/Fastfile
+++ /dev/null
@@ -1 +0,0 @@
-import "../../../fastlane/Fastfile" # imports shared Fastfile from "Apps/fastlane/Fastfile"
\ No newline at end of file
diff --git a/Apps/FCM/ios/fastlane/README.md b/Apps/FCM/ios/fastlane/README.md
deleted file mode 100644
index adacb226..00000000
--- a/Apps/FCM/ios/fastlane/README.md
+++ /dev/null
@@ -1,131 +0,0 @@
-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
-
-### delete_all_code_signing_files
-
-```sh
-[bundle exec] fastlane delete_all_code_signing_files
-```
-
-
-
-### create_all_code_signing_files
-
-```sh
-[bundle exec] fastlane create_all_code_signing_files
-```
-
-
-
-### register_new_ios_device
-
-```sh
-[bundle exec] fastlane register_new_ios_device
-```
-
-
-
-### download_development_code_signing
-
-```sh
-[bundle exec] fastlane download_development_code_signing
-```
-
-
-
-### download_ci_code_signing_files
-
-```sh
-[bundle exec] fastlane download_ci_code_signing_files
-```
-
-
-
-### setup_apple_account_write_access
-
-```sh
-[bundle exec] fastlane setup_apple_account_write_access
-```
-
-
-
-### setup_google_bucket_access
-
-```sh
-[bundle exec] fastlane setup_google_bucket_access
-```
-
-
-
-### get_new_app_version
-
-```sh
-[bundle exec] fastlane get_new_app_version
-```
-
-
-
-### get_new_build_version
-
-```sh
-[bundle exec] fastlane get_new_build_version
-```
-
-
-
-### get_build_notes
-
-```sh
-[bundle exec] fastlane get_build_notes
-```
-
-
-
-### get_build_test_groups
-
-```sh
-[bundle exec] fastlane get_build_test_groups
-```
-
-
-
-----
-
-
-## iOS
-
-### ios build
-
-```sh
-[bundle exec] fastlane ios build
-```
-
-
-
-### ios update_ios_app_versions
-
-```sh
-[bundle exec] fastlane ios update_ios_app_versions
-```
-
-
-
-----
-
-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).
diff --git a/Apps/fastlane/helpers/build_helper.rb b/Apps/fastlane/helpers/build_helper.rb
index cacc8285..22aa810b 100644
--- a/Apps/fastlane/helpers/build_helper.rb
+++ b/Apps/fastlane/helpers/build_helper.rb
@@ -12,6 +12,7 @@
 
     # Build release APK using Fastlane's Gradle tool
     gradle(
+      project_dir: "./android",
       task: "assemble",
       build_type: "Release"
     )