From d475395b9a0603ed019cc35dccc6c1af894b5379 Mon Sep 17 00:00:00 2001 From: seanirby Date: Wed, 30 Oct 2024 13:28:03 -0700 Subject: [PATCH 1/7] ENG-5771: Add firebase app distribution support --- .../content/docs/packages/plugin-fastlane.mdx | 54 ++++++++++- packages/plugin-fastlane/__tests__/index.ts | 91 +++++++++++++++++++ packages/plugin-fastlane/src/index.ts | 24 +++++ packages/plugin-fastlane/src/types.ts | 32 +++++++ .../template/android/fastlane/Fastfile | 62 ++++++++++++- .../template/android/fastlane/Pluginfile | 6 ++ .../template/ios/fastlane/Fastfile | 44 ++++++++- .../template/ios/fastlane/Pluginfile | 6 ++ 8 files changed, 310 insertions(+), 9 deletions(-) diff --git a/apps/docs/src/content/docs/packages/plugin-fastlane.mdx b/apps/docs/src/content/docs/packages/plugin-fastlane.mdx index 351255e9c5..fbafb5c62a 100644 --- a/apps/docs/src/content/docs/packages/plugin-fastlane.mdx +++ b/apps/docs/src/content/docs/packages/plugin-fastlane.mdx @@ -82,9 +82,9 @@ For more detailed guidance and information, please refer to the [Flagship Code C ### Build Configuration -Depending on the plugin, there might be additional configuration required. Regarding the `plugin-fastlane`, there's an optional additional build configuration feature available to extend your Fastlane setup. Presently, the only extension supported is for AppCenter uploads. Providing the AppCenter configuration will prompt the plugin to update your Fastlane setup accordingly. +Depending on the plugin, there might be additional configuration required. Regarding the `plugin-fastlane`, there's an optional additional build configuration feature available to extend your Fastlane setup. Presently, the only extensions supported are for uploads to AppCenter and/or Firebase App Distribution. Providing configuration for either services will prompt the plugin to update your Fastlane setup accordingly. -For the purpose of illustration, the `build.internal.ts` configuration shall be presented as follows if you want to include AppCenter uploads: +For the purpose of illustration, the `build.internal.ts` configuration shall be presented as follows if you want to include both AppCenter and Firebase App Distribution uploads: ```ts title="build.internal.ts" import { defineBuild } from "@brandingbrand/code-cli-kit"; @@ -108,6 +108,10 @@ export default defineBuild({ destinationType: "group", destinations: ["iat"], }, + firebase: { + appId: '1234', + groups: ['iat'], + }, }, android: { appCenter: { @@ -116,6 +120,10 @@ export default defineBuild({ destinationType: "group", destinations: ["iat"], }, + firebase: { + appId: '4321', + groups: ['iat'], + }, }, }, }, @@ -164,6 +172,26 @@ _required_ Array of distribution destinations. +##### `codePluginFastlane.plugin.ios.firebase` + +#### `FirebaseIOS` + +###### `appId` + +**type:** `"string" + +_required_ + +The Firebase app id. + +###### `groups` + +**type:** `string[]` + +_required_ + +Array of distribution groups. + ##### `codePluginFastlane.plugin.android.appCenter` **type:** [AppCenterAndroid](#appcenterandroid) @@ -204,6 +232,26 @@ _required_ Array of distribution destinations. +##### `codePluginFastlane.plugin.android.firebase` + +#### `FirebaseAndroid` + +###### `appId` + +**type:** `"string" + +_required_ + +The Firebase app id. + +###### `groups` + +**type:** `string[]` + +_required_ + +Array of distribution groups. + :::note -If you don't need AppCenter then do not include the `codePluginFastlane` configuration. +If you don't need AppCenter or Firebase App Distribution then do not include the `codePluginFastlane` configuration. ::: diff --git a/packages/plugin-fastlane/__tests__/index.ts b/packages/plugin-fastlane/__tests__/index.ts index dfda95f509..149ba4e623 100644 --- a/packages/plugin-fastlane/__tests__/index.ts +++ b/packages/plugin-fastlane/__tests__/index.ts @@ -52,6 +52,26 @@ describe('plugin-fastlane', () => { }, }; + const configWithFirebase = { + ...config, + codePluginFastlane: { + plugin: { + ios: { + firebase: { + appId: '1234', + groups: ['IAT'], + }, + }, + android: { + firebase: { + appId: '4321', + groups: ['IAT'], + }, + }, + }, + }, + }; + const options = { release: false, }; @@ -79,6 +99,11 @@ describe('plugin-fastlane', () => { 'utf-8', ); + const pluginfileContent = await fs.readFile( + path.project.resolve('ios', 'fastlane', 'Pluginfile'), + 'utf-8', + ); + expect(fastfileContent).toContain( `@profiles = ['${path.project.resolve('coderc', 'signing', 'enterprise.mobileprovision')}']`, ); @@ -97,6 +122,39 @@ describe('plugin-fastlane', () => { plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)`); + + expect(fastfileContent).toContain('lane :increment_build_appcenter'); + expect(fastfileContent).not.toContain('firebase'); + expect(pluginfileContent).not.toContain('firebase'); + }); + + it('ios with firebase config', async () => { + await plugin.ios?.(configWithFirebase, options as any); + + expect( + await fs.doesPathExist( + path.project.resolve('ios', 'fastlane', 'Fastfile'), + ), + ).toBeTruthy(); + expect( + await fs.doesPathExist( + path.project.resolve('ios', 'fastlane', 'Pluginfile'), + ), + ).toBeTruthy(); + + const fastfileContent = await fs.readFile( + path.project.resolve('ios', 'fastlane', 'Fastfile'), + 'utf-8', + ); + const pluginfileContent = await fs.readFile( + path.project.resolve('ios', 'fastlane', 'Pluginfile'), + 'utf-8', + ); + + expect(fastfileContent).toContain('lane :increment_build_firebase'); + expect(fastfileContent).toContain('firebase'); + expect(fastfileContent).not.toContain('appcenter'); + expect(pluginfileContent).not.toContain('appcenter'); }); it('android', async () => { @@ -111,14 +169,28 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); 'utf-8', ); + const pluginfileContent = await fs.readFile( + path.project.resolve('android', 'fastlane', 'Pluginfile'), + 'utf-8', + ); + expect(fastfileContent).toContain(`lane :appcenter_bundle do increment_build`); expect(fastfileContent).not.toContain('<%='); expect(fastfileContent).not.toContain('%>'); + + expect(fastfileContent).toContain('lane :increment_build_appcenter'); + expect(fastfileContent).not.toContain('firebase'); + expect(pluginfileContent).not.toContain('firebase'); + expect(gemfileContent).toContain(`gem 'fastlane' plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)`); + + expect(fastfileContent).toContain('lane :increment_build_appcenter'); + expect(fastfileContent).not.toContain('firebase'); + expect(pluginfileContent).not.toContain('firebase'); }); it('android bundle without increment build', async () => { @@ -151,4 +223,23 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)`); }); + + it('android with firebase config', async () => { + await plugin.android?.(configWithFirebase, options as any); + + const fastfileContent = await fs.readFile( + path.project.resolve('android', 'fastlane', 'Fastfile'), + 'utf-8', + ); + const pluginfileContent = await fs.readFile( + path.project.resolve('android', 'fastlane', 'Pluginfile'), + 'utf-8', + ); + + expect(fastfileContent).toContain('lane :increment_build_firebase'); + expect(fastfileContent).toContain('lane :firebase_assemble'); + expect(fastfileContent).toContain('lane :firebase_bundle'); + expect(fastfileContent).not.toContain('appcenter'); + expect(pluginfileContent).not.toContain('appcenter'); + }); }); diff --git a/packages/plugin-fastlane/src/index.ts b/packages/plugin-fastlane/src/index.ts index 2219567040..dd1cfc3893 100644 --- a/packages/plugin-fastlane/src/index.ts +++ b/packages/plugin-fastlane/src/index.ts @@ -78,6 +78,18 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`, }, ); + // Render Pluginfile template for iOS + await withUTF8( + path.project.resolve('ios', 'fastlane', 'Pluginfile'), + content => { + return ejs.render(content, { + ...build, + ...options, + ...(!build.codePluginFastlane ? {codePluginFastlane: {}} : {}), + }); + }, + ); + // Get list of provisioning profiles files const files = await fs.readdir( path.project.resolve(build.ios.signing.profilesDir), @@ -188,6 +200,18 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`, }); }, ); + + // Render PluginFile template for Android + await withUTF8( + path.project.resolve('android', 'fastlane', 'Pluginfile'), + content => { + return ejs.render(content, { + ...build, + ...options, + ...(!build.codePluginFastlane ? {codePluginFastlane: {}} : {}), + }); + }, + ); }, }); diff --git a/packages/plugin-fastlane/src/types.ts b/packages/plugin-fastlane/src/types.ts index a70f12bdfd..30ea12e618 100644 --- a/packages/plugin-fastlane/src/types.ts +++ b/packages/plugin-fastlane/src/types.ts @@ -36,6 +36,21 @@ type AppCenterIOS = { destinations: string[]; }; +/** + * Represents the configuration for Firebase App Distribution for iOS. + */ +type FirebaseIOS = { + /** + * The application id in firebase. + */ + appId: string; + + /** + * Array of testing groups + */ + groups: string[]; +}; + /** * Represents the configuration for Fastlane specific to iOS. */ @@ -44,6 +59,7 @@ type FastlaneIOS = { * Configuration for App Center for iOS. */ appCenter?: AppCenterIOS; + firebase?: FirebaseIOS; }; /** @@ -71,6 +87,21 @@ type AppCenterAndroid = { destinations: string[]; }; +/** + * Represents the configuration for Firebase App Distribution for Android. + */ +type FirebaseAndroid = { + /** + * The application id in firebase. + */ + appId: string; + + /** + * Array of testing groups + */ + groups: string[]; +}; + /** * Represents the configuration for Fastlane specific to Android. */ @@ -79,4 +110,5 @@ type FastlaneAndroid = { * Configuration for App Center for Android. */ appCenter?: AppCenterAndroid; + firebase?: FirebaseAndroid; }; diff --git a/packages/plugin-fastlane/template/android/fastlane/Fastfile b/packages/plugin-fastlane/template/android/fastlane/Fastfile index 596599aa23..82828339d3 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/android/fastlane/Fastfile @@ -11,7 +11,7 @@ lane :bundle do end <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> -lane :increment_build do +lane :increment_build_appcenter do begin version = appcenter_fetch_version_number( owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", @@ -33,7 +33,7 @@ end <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> lane :appcenter_assemble do - increment_build + increment_build_appcenter assemble @@ -47,7 +47,7 @@ end lane :appcenter_bundle do <% if(!android.versioning || android.versioning.build === undefined) { -%> - increment_build + increment_build_appcenter <% } -%> bundle @@ -60,3 +60,59 @@ lane :appcenter_bundle do ) end <% } -%> + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> + +lane :increment_build_firebase do + begin + version = firebase_app_distribution_get_latest_release( + app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"] + ) + + if version[:buildVersion] + build_number = version[:buildVersion].to_i + 1 + sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} + puts "Fastlane: updated build number to #{build_number}" + end + rescue StandardError => e + puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" + puts "Fastlane: #{e.message}" + end + +end + +<% } -%> + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> + +lane :firebase_assemble do + increment_build_firebase + + assemble + + firebase_app_distribution( + app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], + groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>" + ) +end + +lane :firebase_bundle do + bundle + +<% if(!android.versioning || android.versioning.build === undefined) { -%> + increment_build_firebase +<% } -%> + + firebase_app_distribution( + app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], + android_artifact_type: "AAB", + groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>" + ) +end + +<% } -%> diff --git a/packages/plugin-fastlane/template/android/fastlane/Pluginfile b/packages/plugin-fastlane/template/android/fastlane/Pluginfile index 756bff8e13..d74c9b575d 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Pluginfile +++ b/packages/plugin-fastlane/template/android/fastlane/Pluginfile @@ -2,4 +2,10 @@ # # Ensure this file is checked in to source control! +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> gem 'fastlane-plugin-appcenter' +<% } -%> + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> +gem 'fastlane-plugin-firebase_app_distribution' +<% } -%> diff --git a/packages/plugin-fastlane/template/ios/fastlane/Fastfile b/packages/plugin-fastlane/template/ios/fastlane/Fastfile index c0399b3bb7..484fdd94be 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Fastfile @@ -1,6 +1,6 @@ default_platform :ios -# make a provisioned build and upload to appcenter +# make a provisioned build lane :build do keychain_password = SecureRandom.uuid keychain_name = 'ios-build.keychain' @@ -57,7 +57,7 @@ lane :compile do end <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> -lane :increment_build do +lane :increment_build_appcenter do begin version = appcenter_fetch_version_number( owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", @@ -78,7 +78,7 @@ end <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> lane :appcenter do - increment_build + increment_build_appcenter build @@ -90,3 +90,41 @@ lane :appcenter do ) end <% } -%> + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> +lane :increment_build_firebase do + begin + version = firebase_app_distribution_get_latest_release( + app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + ) + + if version[:buildVersion] + build_number = increment_build_number( + build_number: version[:buildVersion].to_i + 1 + ) + puts "Fastlane: updated build number to #{build_number}" + end + rescue StandardError => e + puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" + puts "Fastlane: #{e.message}" + end +end +<% } -%> + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> + +lane :firebase do + increment_build_firebase + + build + + firebase_app_distribution( + app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], + groups: "<%= codePluginFastlane.plugin.ios.firebase.groups %>" + ) +end + +<% } -%> diff --git a/packages/plugin-fastlane/template/ios/fastlane/Pluginfile b/packages/plugin-fastlane/template/ios/fastlane/Pluginfile index 756bff8e13..03ac4bcd17 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Pluginfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Pluginfile @@ -2,4 +2,10 @@ # # Ensure this file is checked in to source control! +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> gem 'fastlane-plugin-appcenter' +<% } -%> + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> +gem 'fastlane-plugin-firebase_app_distribution' +<% } -%> From 84167ea5f2983131bf537bb2d49d9665a0d1f813 Mon Sep 17 00:00:00 2001 From: seanirby Date: Fri, 1 Nov 2024 08:27:55 -0700 Subject: [PATCH 2/7] ENG-5771: Update templates so only one build will be made in CI/CD --- packages/plugin-fastlane/__tests__/index.ts | 75 ++--------- .../template/android/fastlane/Fastfile | 125 ++++++++---------- .../template/android/fastlane/Pluginfile | 5 - .../template/ios/fastlane/Fastfile | 111 ++++++++-------- .../template/ios/fastlane/Pluginfile | 5 - 5 files changed, 116 insertions(+), 205 deletions(-) diff --git a/packages/plugin-fastlane/__tests__/index.ts b/packages/plugin-fastlane/__tests__/index.ts index 149ba4e623..3cde97a51f 100644 --- a/packages/plugin-fastlane/__tests__/index.ts +++ b/packages/plugin-fastlane/__tests__/index.ts @@ -99,11 +99,6 @@ describe('plugin-fastlane', () => { 'utf-8', ); - const pluginfileContent = await fs.readFile( - path.project.resolve('ios', 'fastlane', 'Pluginfile'), - 'utf-8', - ); - expect(fastfileContent).toContain( `@profiles = ['${path.project.resolve('coderc', 'signing', 'enterprise.mobileprovision')}']`, ); @@ -123,9 +118,8 @@ describe('plugin-fastlane', () => { plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)`); - expect(fastfileContent).toContain('lane :increment_build_appcenter'); - expect(fastfileContent).not.toContain('firebase'); - expect(pluginfileContent).not.toContain('firebase'); + expect(fastfileContent).toContain('appcenter_upload'); + expect(fastfileContent).not.toContain('firebase_app_distribution'); }); it('ios with firebase config', async () => { @@ -146,15 +140,8 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); path.project.resolve('ios', 'fastlane', 'Fastfile'), 'utf-8', ); - const pluginfileContent = await fs.readFile( - path.project.resolve('ios', 'fastlane', 'Pluginfile'), - 'utf-8', - ); - - expect(fastfileContent).toContain('lane :increment_build_firebase'); - expect(fastfileContent).toContain('firebase'); - expect(fastfileContent).not.toContain('appcenter'); - expect(pluginfileContent).not.toContain('appcenter'); + expect(fastfileContent).toContain('firebase_app_distribution'); + expect(fastfileContent).not.toContain('appcenter_upload'); }); it('android', async () => { @@ -174,54 +161,19 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); 'utf-8', ); - expect(fastfileContent).toContain(`lane :appcenter_bundle do - increment_build`); expect(fastfileContent).not.toContain('<%='); expect(fastfileContent).not.toContain('%>'); - expect(fastfileContent).toContain('lane :increment_build_appcenter'); - expect(fastfileContent).not.toContain('firebase'); - expect(pluginfileContent).not.toContain('firebase'); + expect(fastfileContent).toContain('appcenter_upload'); + expect(fastfileContent).not.toContain('firebase_app_distribution'); expect(gemfileContent).toContain(`gem 'fastlane' plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)`); - expect(fastfileContent).toContain('lane :increment_build_appcenter'); - expect(fastfileContent).not.toContain('firebase'); - expect(pluginfileContent).not.toContain('firebase'); - }); - - it('android bundle without increment build', async () => { - await plugin.android?.( - { - ...config, - android: { - ...config.android, - versioning: {version: '1.0.0', build: 5}, - }, - }, - options as any, - ); - - const fastfileContent = await fs.readFile( - path.project.resolve('android', 'fastlane', 'Fastfile'), - 'utf-8', - ); - const gemfileContent = await fs.readFile( - path.project.resolve('android', 'Gemfile'), - 'utf-8', - ); - - expect(fastfileContent).not.toContain(`lane :appcenter_bundle do - increment_build`); - expect(fastfileContent).not.toContain('<%='); - expect(fastfileContent).not.toContain('%>'); - expect(gemfileContent).toContain(`gem 'fastlane' - -plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') -eval_gemfile(plugins_path) if File.exist?(plugins_path)`); + expect(fastfileContent).toContain('appcenter_upload'); + expect(fastfileContent).not.toContain('firebase_app_distribution'); }); it('android with firebase config', async () => { @@ -231,15 +183,8 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); path.project.resolve('android', 'fastlane', 'Fastfile'), 'utf-8', ); - const pluginfileContent = await fs.readFile( - path.project.resolve('android', 'fastlane', 'Pluginfile'), - 'utf-8', - ); - expect(fastfileContent).toContain('lane :increment_build_firebase'); - expect(fastfileContent).toContain('lane :firebase_assemble'); - expect(fastfileContent).toContain('lane :firebase_bundle'); - expect(fastfileContent).not.toContain('appcenter'); - expect(pluginfileContent).not.toContain('appcenter'); + expect(fastfileContent).toContain('firebase_app_distribution'); + expect(fastfileContent).not.toContain('appcenter_upload'); }); }); diff --git a/packages/plugin-fastlane/template/android/fastlane/Fastfile b/packages/plugin-fastlane/template/android/fastlane/Fastfile index 82828339d3..0542df0221 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/android/fastlane/Fastfile @@ -10,102 +10,84 @@ lane :bundle do gradle(task: "app:bundleRelease") end -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> lane :increment_build_appcenter do - begin - version = appcenter_fetch_version_number( - owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", - version: "<%- android.versioning?.version || "1.0.0" %>" - ) - - if version["build_number"] - build_number = version["build_number"].to_i + 1 - sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} - - puts "Fastlane: updated build number to #{build_number}" + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> + begin + version = appcenter_fetch_version_number( + owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", + version: "<%- android.versioning?.version || "1.0.0" %>" + ) + + if version["build_number"] + build_number = version["build_number"].to_i + 1 + sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} + + puts "Fastlane: updated build number to #{build_number}" + end + rescue + puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" end - rescue - puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" - end + <% } else { -%> + UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") + <% } -%> end -<% } -%> -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> -lane :appcenter_assemble do - increment_build_appcenter - - assemble - - appcenter_upload( - owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", - destination_type: "<%= codePluginFastlane.plugin.android.appCenter.destinationType %>", - destinations: "<%= codePluginFastlane.plugin.android.appCenter.destinations %>" - ) +lane :increment_build_firebase do + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> + begin + version = firebase_app_distribution_get_latest_release( + app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"] + ) + + if version[:buildVersion] + build_number = version[:buildVersion].to_i + 1 + sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} + puts "Fastlane: updated build number to #{build_number}" + end + rescue StandardError => e + puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" + puts "Fastlane: #{e.message}" + end + <% } else { -%> + UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") + <% } -%> end -lane :appcenter_bundle do -<% if(!android.versioning || android.versioning.build === undefined) { -%> - increment_build_appcenter -<% } -%> - - bundle +lane :distribute_internal do + assemble +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> appcenter_upload( owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", destination_type: "<%= codePluginFastlane.plugin.android.appCenter.destinationType %>", destinations: "<%= codePluginFastlane.plugin.android.appCenter.destinations %>" ) -end <% } -%> - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> - -lane :increment_build_firebase do - begin - version = firebase_app_distribution_get_latest_release( - app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", - service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"] - ) - - if version[:buildVersion] - build_number = version[:buildVersion].to_i + 1 - sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} - puts "Fastlane: updated build number to #{build_number}" - end - rescue StandardError => e - puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" - puts "Fastlane: #{e.message}" - end - -end - -<% } -%> - -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> - -lane :firebase_assemble do - increment_build_firebase - - assemble - firebase_app_distribution( app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>" ) +<% } -%> end -lane :firebase_bundle do +lane :distribute_store do bundle -<% if(!android.versioning || android.versioning.build === undefined) { -%> - increment_build_firebase +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> + appcenter_upload( + owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", + destination_type: "<%= codePluginFastlane.plugin.android.appCenter.destinationType %>", + destinations: "<%= codePluginFastlane.plugin.android.appCenter.destinations %>" + ) <% } -%> - +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> firebase_app_distribution( app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], @@ -113,6 +95,5 @@ lane :firebase_bundle do android_artifact_type: "AAB", groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>" ) -end - <% } -%> +end \ No newline at end of file diff --git a/packages/plugin-fastlane/template/android/fastlane/Pluginfile b/packages/plugin-fastlane/template/android/fastlane/Pluginfile index d74c9b575d..ed527591a5 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Pluginfile +++ b/packages/plugin-fastlane/template/android/fastlane/Pluginfile @@ -2,10 +2,5 @@ # # Ensure this file is checked in to source control! -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> gem 'fastlane-plugin-appcenter' -<% } -%> - -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> gem 'fastlane-plugin-firebase_app_distribution' -<% } -%> diff --git a/packages/plugin-fastlane/template/ios/fastlane/Fastfile b/packages/plugin-fastlane/template/ios/fastlane/Fastfile index 484fdd94be..11d7b280be 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Fastfile @@ -56,75 +56,70 @@ lane :compile do ) end -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> lane :increment_build_appcenter do - begin - version = appcenter_fetch_version_number( - owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", - version: "<%= ios.versioning?.version || "1.0.0" %>" - ) - if version["build_number"] - build_number = increment_build_number( - build_number: version["build_number"].to_i + 1 + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> + begin + version = appcenter_fetch_version_number( + owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", + version: "<%= ios.versioning?.version || "1.0.0" %>" ) - puts "Fastlane: updated build number to #{build_number}" + if version["build_number"] + build_number = increment_build_number( + build_number: version["build_number"].to_i + 1 + ) + puts "Fastlane: updated build number to #{build_number}" + end + rescue + puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" end - rescue - puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" - end -end -<% } -%> - -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> -lane :appcenter do - increment_build_appcenter - - build - - appcenter_upload( - owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", - destination_type: "<%= codePluginFastlane.plugin.ios.appCenter.destinationType %>", - destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>" - ) + <% } else { -%> + UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") + <% } -%> end -<% } -%> -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> lane :increment_build_firebase do - begin - version = firebase_app_distribution_get_latest_release( - app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", - service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], - ) - - if version[:buildVersion] - build_number = increment_build_number( - build_number: version[:buildVersion].to_i + 1 + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> + begin + version = firebase_app_distribution_get_latest_release( + app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], ) - puts "Fastlane: updated build number to #{build_number}" + + if version[:buildVersion] + build_number = increment_build_number( + build_number: version[:buildVersion].to_i + 1 + ) + puts "Fastlane: updated build number to #{build_number}" + end + rescue StandardError => e + puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" + puts "Fastlane: #{e.message}" end - rescue StandardError => e - puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" - puts "Fastlane: #{e.message}" - end + <% } else { -%> + UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") + <% } -%> end -<% } -%> - -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> - -lane :firebase do - increment_build_firebase +lane :distribute do build - firebase_app_distribution( - app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", - service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], - release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], - groups: "<%= codePluginFastlane.plugin.ios.firebase.groups %>" - ) + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> + appcenter_upload( + owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", + destination_type: "<%= codePluginFastlane.plugin.ios.appCenter.destinationType %>", + destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>" + ) + <% } -%> + + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> + firebase_app_distribution( + app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], + groups: "<%= codePluginFastlane.plugin.ios.firebase.groups %>" + ) + <% } -%> end -<% } -%> diff --git a/packages/plugin-fastlane/template/ios/fastlane/Pluginfile b/packages/plugin-fastlane/template/ios/fastlane/Pluginfile index 03ac4bcd17..ed527591a5 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Pluginfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Pluginfile @@ -2,10 +2,5 @@ # # Ensure this file is checked in to source control! -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> gem 'fastlane-plugin-appcenter' -<% } -%> - -<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> gem 'fastlane-plugin-firebase_app_distribution' -<% } -%> From 049bd09c70758aa897d0f9118c7bf6dd82fdce79 Mon Sep 17 00:00:00 2001 From: seanirby Date: Tue, 5 Nov 2024 13:12:11 -0800 Subject: [PATCH 3/7] ENG-5771: Keep existing lanes so update is non-breaking --- packages/plugin-fastlane/src/index.ts | 24 ------- .../template/android/fastlane/Fastfile | 69 ++++++++++++++----- .../template/ios/fastlane/Fastfile | 52 ++++++++++---- 3 files changed, 88 insertions(+), 57 deletions(-) diff --git a/packages/plugin-fastlane/src/index.ts b/packages/plugin-fastlane/src/index.ts index dd1cfc3893..2219567040 100644 --- a/packages/plugin-fastlane/src/index.ts +++ b/packages/plugin-fastlane/src/index.ts @@ -78,18 +78,6 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`, }, ); - // Render Pluginfile template for iOS - await withUTF8( - path.project.resolve('ios', 'fastlane', 'Pluginfile'), - content => { - return ejs.render(content, { - ...build, - ...options, - ...(!build.codePluginFastlane ? {codePluginFastlane: {}} : {}), - }); - }, - ); - // Get list of provisioning profiles files const files = await fs.readdir( path.project.resolve(build.ios.signing.profilesDir), @@ -200,18 +188,6 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`, }); }, ); - - // Render PluginFile template for Android - await withUTF8( - path.project.resolve('android', 'fastlane', 'Pluginfile'), - content => { - return ejs.render(content, { - ...build, - ...options, - ...(!build.codePluginFastlane ? {codePluginFastlane: {}} : {}), - }); - }, - ); }, }); diff --git a/packages/plugin-fastlane/template/android/fastlane/Fastfile b/packages/plugin-fastlane/template/android/fastlane/Fastfile index 0542df0221..2bb322aad1 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/android/fastlane/Fastfile @@ -10,24 +10,29 @@ lane :bundle do gradle(task: "app:bundleRelease") end -lane :increment_build_appcenter do - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> - begin - version = appcenter_fetch_version_number( - owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", - version: "<%- android.versioning?.version || "1.0.0" %>" - ) - - if version["build_number"] - build_number = version["build_number"].to_i + 1 - sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> +lane :increment_build do + begin + version = appcenter_fetch_version_number( + owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", + version: "<%- android.versioning?.version || "1.0.0" %>" + ) + if version["build_number"] + build_number = version["build_number"].to_i + 1 + sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} - puts "Fastlane: updated build number to #{build_number}" - end - rescue - puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" + puts "Fastlane: updated build number to #{build_number}" end + rescue + puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" + end +end +<% } -%> + +lane :increment_build_appcenter do + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> + increment_build <% } else { -%> UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") <% } -%> @@ -55,7 +60,35 @@ lane :increment_build_firebase do <% } -%> end -lane :distribute_internal do + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> +lane :appcenter_assemble do + increment_build + assemble + + appcenter_upload( + owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", + destination_type: "<%= codePluginFastlane.plugin.android.appCenter.destinationType %>", + destinations: "<%= codePluginFastlane.plugin.android.appCenter.destinations %>" + ) +end + +lane :appcenter_bundle do +<% if(!android.versioning || android.versioning.build === undefined) { -%> + increment_build +<% } -%> + bundle + appcenter_upload( + owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", + destination_type: "<%= codePluginFastlane.plugin.android.appCenter.destinationType %>", + destinations: "<%= codePluginFastlane.plugin.android.appCenter.destinations %>" + ) +end +<% } -%> + +lane :distribute_package do assemble <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> @@ -76,7 +109,7 @@ lane :distribute_internal do <% } -%> end -lane :distribute_store do +lane :distribute_bundle do bundle <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> diff --git a/packages/plugin-fastlane/template/ios/fastlane/Fastfile b/packages/plugin-fastlane/template/ios/fastlane/Fastfile index 11d7b280be..c58396880b 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Fastfile @@ -56,28 +56,50 @@ lane :compile do ) end -lane :increment_build_appcenter do - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> - begin - version = appcenter_fetch_version_number( - owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", - version: "<%= ios.versioning?.version || "1.0.0" %>" +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> +lane :increment_build do + begin + version = appcenter_fetch_version_number( + owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", + version: "<%= ios.versioning?.version || "1.0.0" %>" + ) + if version["build_number"] + build_number = increment_build_number( + build_number: version["build_number"].to_i + 1 ) - if version["build_number"] - build_number = increment_build_number( - build_number: version["build_number"].to_i + 1 - ) - puts "Fastlane: updated build number to #{build_number}" - end - rescue - puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" + puts "Fastlane: updated build number to #{build_number}" end + rescue + puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number" + end +end +<% } -%> + +lane :increment_build_appcenter do + <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> + increment_build <% } else { -%> UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") <% } -%> end + +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> +lane :appcenter do + increment_build + + build + + appcenter_upload( + owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", + destination_type: "<%= codePluginFastlane.plugin.ios.appCenter.destinationType %>", + destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>" + ) +end +<% } -%> + lane :increment_build_firebase do <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> begin From 507babba2d6df9e05da1070d1cd9756f910aa5df Mon Sep 17 00:00:00 2001 From: seanirby Date: Tue, 5 Nov 2024 13:45:48 -0800 Subject: [PATCH 4/7] ENG-5771: Update tests, fix whitespace/newline discrepancies --- packages/plugin-fastlane/__tests__/index.ts | 36 ++++++++++++++++--- .../template/android/fastlane/Fastfile | 5 ++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/plugin-fastlane/__tests__/index.ts b/packages/plugin-fastlane/__tests__/index.ts index 3cde97a51f..2389a0e0f4 100644 --- a/packages/plugin-fastlane/__tests__/index.ts +++ b/packages/plugin-fastlane/__tests__/index.ts @@ -156,11 +156,6 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); 'utf-8', ); - const pluginfileContent = await fs.readFile( - path.project.resolve('android', 'fastlane', 'Pluginfile'), - 'utf-8', - ); - expect(fastfileContent).not.toContain('<%='); expect(fastfileContent).not.toContain('%>'); @@ -176,6 +171,37 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)`); expect(fastfileContent).not.toContain('firebase_app_distribution'); }); + it('android bundle without increment build', async () => { + await plugin.android?.( + { + ...config, + android: { + ...config.android, + versioning: {version: '1.0.0', build: 5}, + }, + }, + options as any, + ); + + const fastfileContent = await fs.readFile( + path.project.resolve('android', 'fastlane', 'Fastfile'), + 'utf-8', + ); + const gemfileContent = await fs.readFile( + path.project.resolve('android', 'Gemfile'), + 'utf-8', + ); + + expect(fastfileContent).not.toContain(`lane :appcenter_bundle do + increment_build`); + expect(fastfileContent).not.toContain('<%='); + expect(fastfileContent).not.toContain('%>'); + expect(gemfileContent).toContain(`gem 'fastlane' + +plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') +eval_gemfile(plugins_path) if File.exist?(plugins_path)`); + }); + it('android with firebase config', async () => { await plugin.android?.(configWithFirebase, options as any); diff --git a/packages/plugin-fastlane/template/android/fastlane/Fastfile b/packages/plugin-fastlane/template/android/fastlane/Fastfile index 2bb322aad1..d08f888714 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/android/fastlane/Fastfile @@ -18,6 +18,7 @@ lane :increment_build do app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>", version: "<%- android.versioning?.version || "1.0.0" %>" ) + if version["build_number"] build_number = version["build_number"].to_i + 1 sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} @@ -64,6 +65,7 @@ end <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> lane :appcenter_assemble do increment_build + assemble appcenter_upload( @@ -78,6 +80,7 @@ lane :appcenter_bundle do <% if(!android.versioning || android.versioning.build === undefined) { -%> increment_build <% } -%> + bundle appcenter_upload( owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>", @@ -129,4 +132,4 @@ lane :distribute_bundle do groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>" ) <% } -%> -end \ No newline at end of file +end From cc3406a7d08e5b3ebeeedc814d453bc6aafee4b1 Mon Sep 17 00:00:00 2001 From: seanirby Date: Wed, 6 Nov 2024 10:59:29 -0800 Subject: [PATCH 5/7] ENG-5771: Fix indents after EJS conditionals --- .../template/android/fastlane/Fastfile | 34 +++++------ .../template/ios/fastlane/Fastfile | 58 +++++++++---------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/packages/plugin-fastlane/template/android/fastlane/Fastfile b/packages/plugin-fastlane/template/android/fastlane/Fastfile index d08f888714..f124dcbcaf 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/android/fastlane/Fastfile @@ -33,31 +33,31 @@ end lane :increment_build_appcenter do <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> - increment_build + increment_build <% } else { -%> - UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") + UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") <% } -%> end lane :increment_build_firebase do <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> - begin - version = firebase_app_distribution_get_latest_release( - app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", - service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"] - ) - - if version[:buildVersion] - build_number = version[:buildVersion].to_i + 1 - sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} - puts "Fastlane: updated build number to #{build_number}" - end - rescue StandardError => e - puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" - puts "Fastlane: #{e.message}" + begin + version = firebase_app_distribution_get_latest_release( + app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"] + ) + + if version[:buildVersion] + build_number = version[:buildVersion].to_i + 1 + sh %Q{cd .. && echo "$(awk '{sub(/versionCode [[:digit:]]+$/,"versionCode "#{build_number})}1' app/build.gradle)" > app/build.gradle && cd -} + puts "Fastlane: updated build number to #{build_number}" end + rescue StandardError => e + puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" + puts "Fastlane: #{e.message}" + end <% } else { -%> - UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") + UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") <% } -%> end diff --git a/packages/plugin-fastlane/template/ios/fastlane/Fastfile b/packages/plugin-fastlane/template/ios/fastlane/Fastfile index c58396880b..223a13b831 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Fastfile @@ -78,9 +78,9 @@ end lane :increment_build_appcenter do <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> - increment_build + increment_build <% } else { -%> - UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") + UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") <% } -%> end @@ -102,24 +102,24 @@ end lane :increment_build_firebase do <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> - begin - version = firebase_app_distribution_get_latest_release( - app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", - service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], - ) + begin + version = firebase_app_distribution_get_latest_release( + app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + ) - if version[:buildVersion] - build_number = increment_build_number( - build_number: version[:buildVersion].to_i + 1 - ) - puts "Fastlane: updated build number to #{build_number}" - end - rescue StandardError => e - puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" - puts "Fastlane: #{e.message}" + if version[:buildVersion] + build_number = increment_build_number( + build_number: version[:buildVersion].to_i + 1 + ) + puts "Fastlane: updated build number to #{build_number}" end + rescue StandardError => e + puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" + puts "Fastlane: #{e.message}" + end <% } else { -%> - UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") + UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") <% } -%> end @@ -127,21 +127,21 @@ lane :distribute do build <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> - appcenter_upload( - owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", - app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", - destination_type: "<%= codePluginFastlane.plugin.ios.appCenter.destinationType %>", - destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>" - ) + appcenter_upload( + owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", + app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", + destination_type: "<%= codePluginFastlane.plugin.ios.appCenter.destinationType %>", + destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>" + ) <% } -%> <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> - firebase_app_distribution( - app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", - service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], - release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], - groups: "<%= codePluginFastlane.plugin.ios.firebase.groups %>" - ) + firebase_app_distribution( + app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", + service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], + release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], + groups: "<%= codePluginFastlane.plugin.ios.firebase.groups %>" + ) <% } -%> end From cfcba6303a804a986b01fce416e154cf3aa0fb0f Mon Sep 17 00:00:00 2001 From: seanirby Date: Wed, 6 Nov 2024 12:47:33 -0800 Subject: [PATCH 6/7] ENG-5771: Fix indents before EJS conditionals --- .../template/android/fastlane/Fastfile | 12 +++++------ .../template/ios/fastlane/Fastfile | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/plugin-fastlane/template/android/fastlane/Fastfile b/packages/plugin-fastlane/template/android/fastlane/Fastfile index f124dcbcaf..563403a830 100644 --- a/packages/plugin-fastlane/template/android/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/android/fastlane/Fastfile @@ -32,15 +32,15 @@ end <% } -%> lane :increment_build_appcenter do - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%> increment_build - <% } else { -%> +<% } else { -%> UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") - <% } -%> +<% } -%> end lane :increment_build_firebase do - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.firebase) { -%> begin version = firebase_app_distribution_get_latest_release( app: "<%= codePluginFastlane.plugin.android.firebase.appId %>", @@ -56,9 +56,9 @@ lane :increment_build_firebase do puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" puts "Fastlane: #{e.message}" end - <% } else { -%> +<% } else { -%> UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") - <% } -%> +<% } -%> end diff --git a/packages/plugin-fastlane/template/ios/fastlane/Fastfile b/packages/plugin-fastlane/template/ios/fastlane/Fastfile index 223a13b831..ff7b782a45 100644 --- a/packages/plugin-fastlane/template/ios/fastlane/Fastfile +++ b/packages/plugin-fastlane/template/ios/fastlane/Fastfile @@ -77,11 +77,11 @@ end <% } -%> lane :increment_build_appcenter do - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> increment_build - <% } else { -%> +<% } else { -%> UI.user_error!("Fastlane: Tried to increment build number with appcenter but no appcenter configuration was provided in the build configuration.") - <% } -%> +<% } -%> end @@ -101,7 +101,7 @@ end <% } -%> lane :increment_build_firebase do - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> begin version = firebase_app_distribution_get_latest_release( app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", @@ -118,30 +118,30 @@ lane :increment_build_firebase do puts "Fastlane: did not find any applicable versions for 'firebase_app_distribution_get_latest_release" puts "Fastlane: #{e.message}" end - <% } else { -%> +<% } else { -%> UI.user_error!("Fastlane: Tried to increment build number with firebase but no firebase configuration was provided in the build configuration.") - <% } -%> +<% } -%> end lane :distribute do build - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%> appcenter_upload( owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>", app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>", destination_type: "<%= codePluginFastlane.plugin.ios.appCenter.destinationType %>", destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>" ) - <% } -%> +<% } -%> - <% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> +<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.firebase) { -%> firebase_app_distribution( app: "<%= codePluginFastlane.plugin.ios.firebase.appId %>", service_credentials_json_data: ENV["GOOGLE_SERVICE_CREDENTIALS"], release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"], groups: "<%= codePluginFastlane.plugin.ios.firebase.groups %>" ) - <% } -%> +<% } -%> end From 43eea7637d61f6aa3e93df100e5e60cdd7eb1eac Mon Sep 17 00:00:00 2001 From: Nick Burkhart Date: Thu, 7 Nov 2024 10:50:52 -0500 Subject: [PATCH 7/7] chore(fastlane): bump version and generate changelog --- packages/plugin-fastlane/CHANGELOG.md | 12 ++++++++++++ packages/plugin-fastlane/package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/plugin-fastlane/CHANGELOG.md b/packages/plugin-fastlane/CHANGELOG.md index 3a0b8e4f05..9c45a33353 100644 --- a/packages/plugin-fastlane/CHANGELOG.md +++ b/packages/plugin-fastlane/CHANGELOG.md @@ -1,5 +1,17 @@ # @brandingbrand/code-plugin-fastlane +## 3.1.0 + +### Minor Changes + +- Add Lanes for Firebase App Distributation Support based on build config + New Lanes: + - increment_build_appcenter - increment build version based on last App Center version + - increment_build_firebase - increment build version based on last Firebase version + - distribute (iOS) - build and upload to App Center and/or Firebase + - distribute_package (Android) - build and upload APK to App Center and/or Firebase + - distribute_bundle (Android) - build and upload AAB to App Center and/or Firebase + ## 3.0.1 ### Patch Changes diff --git a/packages/plugin-fastlane/package.json b/packages/plugin-fastlane/package.json index fe51177c0e..a1bffe0e3a 100644 --- a/packages/plugin-fastlane/package.json +++ b/packages/plugin-fastlane/package.json @@ -1,6 +1,6 @@ { "name": "@brandingbrand/code-plugin-fastlane", - "version": "3.0.1", + "version": "3.1.0", "description": "plugin for Flagship Code for fastlane and app center builds", "license": "MIT", "main": "src/index.ts",