Skip to content

Commit

Permalink
Merge pull request #2771 from brandingbrand/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleClapton authored Nov 22, 2024
2 parents 71916ed + f58040d commit 7beeea1
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 7 deletions.
54 changes: 51 additions & 3 deletions apps/docs/src/content/docs/packages/plugin-fastlane.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -108,6 +108,10 @@ export default defineBuild<CodePluginFastlane>({
destinationType: "group",
destinations: ["iat"],
},
firebase: {
appId: '1234',
groups: ['iat'],
},
},
android: {
appCenter: {
Expand All @@ -116,6 +120,10 @@ export default defineBuild<CodePluginFastlane>({
destinationType: "group",
destinations: ["iat"],
},
firebase: {
appId: '4321',
groups: ['iat'],
},
},
},
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
:::
12 changes: 12 additions & 0 deletions packages/plugin-fastlane/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
66 changes: 64 additions & 2 deletions packages/plugin-fastlane/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -97,6 +117,31 @@ describe('plugin-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('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',
);
expect(fastfileContent).toContain('firebase_app_distribution');
expect(fastfileContent).not.toContain('appcenter_upload');
});

it('android', async () => {
Expand All @@ -111,14 +156,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('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('appcenter_upload');
expect(fastfileContent).not.toContain('firebase_app_distribution');
});

it('android bundle without increment build', async () => {
Expand Down Expand Up @@ -151,4 +201,16 @@ 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',
);

expect(fastfileContent).toContain('firebase_app_distribution');
expect(fastfileContent).not.toContain('appcenter_upload');
});
});
2 changes: 1 addition & 1 deletion packages/plugin-fastlane/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
32 changes: 32 additions & 0 deletions packages/plugin-fastlane/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -44,6 +59,7 @@ type FastlaneIOS = {
* Configuration for App Center for iOS.
*/
appCenter?: AppCenterIOS;
firebase?: FirebaseIOS;
};

/**
Expand Down Expand Up @@ -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.
*/
Expand All @@ -79,4 +110,5 @@ type FastlaneAndroid = {
* Configuration for App Center for Android.
*/
appCenter?: AppCenterAndroid;
firebase?: FirebaseAndroid;
};
73 changes: 73 additions & 0 deletions packages/plugin-fastlane/template/android/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ lane :increment_build do
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.")
<% } -%>
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}"
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.android && codePluginFastlane.plugin.android.appCenter) { -%>
lane :appcenter_assemble do
increment_build
Expand All @@ -51,12 +82,54 @@ lane :appcenter_bundle do
<% } -%>
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) { -%>
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"],
release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"],
groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>"
)
<% } -%>
end
lane :distribute_bundle do
bundle
<% 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"],
release_notes: ENV["FIREBASE_DISTRIBUTE_RELEASE_NOTES"],
android_artifact_type: "AAB",
groups: "<%= codePluginFastlane.plugin.android.firebase.groups %>"
)
<% } -%>
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Ensure this file is checked in to source control!

gem 'fastlane-plugin-appcenter'
gem 'fastlane-plugin-firebase_app_distribution'
Loading

0 comments on commit 7beeea1

Please sign in to comment.