Skip to content

Commit

Permalink
config: integrate bugsee in flutter template and update build pipelin…
Browse files Browse the repository at this point in the history
…e job
  • Loading branch information
koukibadr committed Nov 13, 2024
1 parent 6eb8ce9 commit 2dcce05
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 2 deletions.
10 changes: 10 additions & 0 deletions build/steps-build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ steps:
inputs:
secureFile: ${{ parameters.androidKeyStorePropertiesFile }}

# Flutter project signing process goes through 'key.properties' file which holds secure information about the keystore.
- task: DownloadSecureFile@1
name: bugseeFile
displayName: "Download Bug See Tokens from Secure Files"
inputs:
secureFile: ${{ parameters.bugSeeFile }}

# The file copied inside the source directory must be aligned with the name chosen in '/src/app/lib/android/app/build.gradle' where 'key.properties' is loaded.
- task: PowerShell@2
displayName: Copy Signing Configuration Files
Expand All @@ -66,6 +73,9 @@ steps:
Copy-Item -Path '$(keyStore.secureFilePath)' -Destination '${{ parameters.pathToSrc }}\app\android\app\${{ parameters.androidKeystoreFile }}'
Write-Host 'Key store copied to ${{ parameters.pathToSrc }}/app/android/app/${{ parameters.androidKeystoreFile }}.'
Copy-Item -Path '$(bugSeeFile.secureFilePath)' -Destination '${{ parameters.pathToSrc }}\app'
Write-Host 'Key store copied to ${{ parameters.pathToSrc }}/app.'
- template: templates/flutter-prepare.yml
parameters:
projectDirectory: '${{ parameters.pathToSrc }}/app'
Expand Down
16 changes: 16 additions & 0 deletions build/steps-build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ steps:
inputs:
secureFile: '${{ parameters.iosExportOptionsFile }}'

# Flutter project signing process goes through 'key.properties' file which holds secure information about the keystore.
- task: DownloadSecureFile@1
name: bugseeFile
displayName: "Download Bug See Tokens from Secure Files"
inputs:
secureFile: ${{ parameters.bugSeeFile }}

# The file copied inside the source directory must be aligned with the name chosen in '/src/app/lib/android/app/build.gradle' where 'key.properties' is loaded.
- task: PowerShell@2
displayName: Copy Bugsee Configuration File
inputs:
targetType: 'inline'
script: |
Copy-Item -Path '$(bugSeeFile.secureFilePath)' -Destination '${{ parameters.pathToSrc }}\app'
Write-Host 'Key store copied to ${{ parameters.pathToSrc }}/app.'
- template: templates/flutter-prepare.yml
parameters:
projectDirectory: '${{ parameters.pathToSrc }}/app'
Expand Down
2 changes: 2 additions & 0 deletions src/app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ app.*.map.json

# Localization related
lib/l10n/gen_l10n/*

.bugsee.dev
2 changes: 1 addition & 1 deletion src/app/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "com.android.application" version '7.4.2' apply false
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
// END: FlutterFire Configuration
Expand Down
60 changes: 60 additions & 0 deletions src/app/lib/business/bugsee/bugsee_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'dart:io';

import 'package:bugsee_flutter/bugsee_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:logger/logger.dart';
import 'package:logger/web.dart';

abstract interface class BugseeManager {
factory BugseeManager({
required Logger logger,
}) = _BugseeManager;

Future<void> initialize({required VoidCallback runApp});
}

final class _BugseeManager implements BugseeManager {
final Logger logger;

late BugseeLaunchOptions launchOptions;
String? bugseeAccessToken;

_BugseeManager({required this.logger});

@override
Future<void> initialize({
required VoidCallback runApp,
}) async {
await initializeTokensAndOptions();
if (kDebugMode) {
runApp();
return;
}

if (bugseeAccessToken == null) {
logger.i("bugsee token is null, bugsee won't be initialized");
}
HttpOverrides.global = Bugsee.defaultHttpOverrides;
Bugsee.launch(
bugseeAccessToken ?? '',
appRunCallback: (isBugseeLaunched) {
if (!isBugseeLaunched) {
logger.e("bugsee is not initialized, verify bugsee token config");
}
runApp();
},
launchOptions: launchOptions,
);
}

Future initializeTokensAndOptions() async {
if (Platform.isAndroid) {
launchOptions = AndroidLaunchOptions();
bugseeAccessToken = dotenv.env['BUGSEE_ANDROID_TOKEN'];
} else if (Platform.isIOS) {
launchOptions = IOSLaunchOptions();
bugseeAccessToken = dotenv.env['BUGSEE_IOS_TOKEN'];
}
}
}
14 changes: 14 additions & 0 deletions src/app/lib/business/environment/environment_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ final class _EnvironmentManager implements EnvironmentManager {
Environment.production: '.env.prod',
};

final Map<Environment, String> _bugseeFileName = {
Environment.development: '.bugsee.dev',
Environment.staging: '.bugsee.dev',
Environment.production: '.bugsee.dev',
};

@override
late List<Environment> environments;

Expand All @@ -57,8 +63,16 @@ final class _EnvironmentManager implements EnvironmentManager {
);
next = null;

await dotenv.load(
fileName: _bugseeFileName[current]!,
);
Map<String, String> bugSeeTokens = {
'BUGSEE_ANDROID_TOKEN': dotenv.env['BUGSEE_ANDROID_TOKEN']!,
'BUGSEE_IOS_TOKEN': dotenv.env['BUGSEE_IOS_TOKEN']!,
};
await dotenv.load(
fileName: _environmentFileNames[current]!,
mergeWith: bugSeeTokens,
);
}

Expand Down
16 changes: 15 additions & 1 deletion src/app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:app/access/logger/logger_repository.dart';
import 'package:app/access/mocking/mocking_repository.dart';
import 'package:app/app.dart';
import 'package:app/app_router.dart';
import 'package:app/business/bugsee/bugsee_manager.dart';
import 'package:app/business/dad_jokes/dad_jokes_service.dart';
import 'package:app/business/diagnostics/diagnostics_service.dart';
import 'package:app/business/environment/environment.dart';
Expand All @@ -36,13 +37,18 @@ late Logger _logger;
Future<void> main() async {
await initializeComponents();

runApp(const App());
GetIt.I.get<BugseeManager>().initialize(
runApp: () {
runApp(const App());
},
);
}

Future initializeComponents({bool? isMocked}) async {
WidgetsFlutterBinding.ensureInitialized();
await _registerAndLoadEnvironment();
await _registerAndLoadLoggers();
await _registerBugseeManager();

_logger.d("Initialized environment and logger.");

Expand Down Expand Up @@ -117,6 +123,14 @@ Future _registerAndLoadLoggers() async {
GetIt.I.registerSingleton(_logger);
}

Future _registerBugseeManager() async {
GetIt.I.registerSingleton<BugseeManager>(
BugseeManager(
logger: GetIt.I.get<Logger>(),
),
);
}

/// Registers the HTTP client.
void _registerHttpClient() {
final dio = Dio();
Expand Down
8 changes: 8 additions & 0 deletions src/app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
bugsee_flutter:
dependency: "direct main"
description:
name: bugsee_flutter
sha256: "570e37a678178d772a7fa2fc52cfe9e5bd3beadc225e89091d688a1d3c97e691"
url: "https://pub.dev"
source: hosted
version: "8.4.0"
build:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions src/app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
flutter_localizations:
sdk: flutter
intl: any
bugsee_flutter: ^8.4.0

# This is required with alice installed unless this PR is merged https://github.com/jhomlala/alice/pull/171
dependency_overrides:
Expand All @@ -57,3 +58,4 @@ flutter:
- .env.dev
- .env.staging
- .env.prod
- .bugsee.dev

0 comments on commit 2dcce05

Please sign in to comment.