Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: integrate bugsee in flutter template and update build pipeline #48

Merged
merged 9 commits into from
Nov 19, 2024
Merged
Binary file added .DS_Store
koukibadr marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
8 changes: 6 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"program": "src/app/lib/main.dart",
"toolArgs": [
"--dart-define",
"ENV=Staging"
"ENV=Staging",
"--dart-define",
"BUGSEE_TOKEN=<token>"
]
},
{
Expand All @@ -39,7 +41,9 @@
"program": "src/app/lib/main.dart",
"toolArgs": [
"--dart-define",
"ENV=Production"
"ENV=Production",
"--dart-define",
"BUGSEE_TOKEN=<token>"
koukibadr marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down
1 change: 1 addition & 0 deletions build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ stages:
firebaseJsonFile: $(InternalFirebaseJson)
firebaseOptionsDartFile: $(InternalFirebaseOptionsDart)
googleServicesJsonFile: $(InternalGoogleServicesJson)
bugseeVariableGroup: 'FlutterApplicationTemplate.BugSee.Tokens'
koukibadr marked this conversation as resolved.
Show resolved Hide resolved

- stage: AppCenter_TestFlight_Staging
condition: and(succeeded(), eq(variables['IsPullRequestBuild'], 'false'))
Expand Down
3 changes: 3 additions & 0 deletions build/stage-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
type: string
- name: googleServicesJsonFile
type: string
- name: bugseeVariableGroup
type: string
default: ''

jobs:
- job: OnWindows_ReleaseNotes
Expand Down
1 change: 1 addition & 0 deletions build/steps-build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ steps:
projectDirectory: '${{ parameters.pathToSrc }}/app'
verboseMode: true
dartDefine: ENV=$(applicationEnvironment)
dartDefine: BUGSEE_TOKEN=$(AndroidDevToken)
koukibadr marked this conversation as resolved.
Show resolved Hide resolved

- template: templates/flutter-diagnostics.yml
parameters:
Expand Down
1 change: 1 addition & 0 deletions build/steps-build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ steps:
verboseMode: true
exportOptionsPlist: '$(exportOptions.secureFilePath)'
dartDefine: ENV=$(applicationEnvironment)
dartDefine: BUGSEE_TOKEN=$(iOSDevToken)

- template: templates/flutter-diagnostics.yml
parameters:
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
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
koukibadr marked this conversation as resolved.
Show resolved Hide resolved
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
// END: FlutterFire Configuration
Expand Down
91 changes: 91 additions & 0 deletions src/app/lib/business/bugsee/bugsee_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import 'dart:io';

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

const String bugseeTokenFormat =
r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$';

///Service related to initializing Bugsee service
koukibadr marked this conversation as resolved.
Show resolved Hide resolved
abstract interface class BugseeManager {
factory BugseeManager({
required Logger logger,
}) = _BugseeManager;

///initialize bugsee with given token
///bugsee is not available in debug mode
///* [bugseeToken]: nullable bugsee token, if null bugsee won't be initialized make sure you provide
///[BUGSEE_TOKEN] in the env using `--dart-define` or `launch.json` on vscode
Future<void> initialize({
String? bugseeToken,
});

///Manually log a provided exception with a stack trace
Future<void> logException({
required Exception exception,
StackTrace? stackTrace,
});
}

final class _BugseeManager implements BugseeManager {
final Logger logger;

late BugseeLaunchOptions launchOptions;

late bool _isBugSeeInitialized;

_BugseeManager({
required this.logger,
});

@override
Future<void> initialize({
String? bugseeToken,
}) async {
initializeLaunchOptions();
_isBugSeeInitialized = false;
if (kDebugMode) {
logger.i("BUGSEE: deactivated in debug mode");
return;
}

if (bugseeToken == null ||
!RegExp(bugseeTokenFormat).hasMatch(bugseeToken)) {
logger.i("BUGSEE: token is null or invalid, bugsee won't be initialized");
return;
}

HttpOverrides.global = Bugsee.defaultHttpOverrides;
await Bugsee.launch(
bugseeToken,
appRunCallback: (isBugseeLaunched) {
if (!isBugseeLaunched) {
logger
.e("BUGSEE: not initialized, verify bugsee token configuration");
}
_isBugSeeInitialized = isBugseeLaunched;
},
launchOptions: launchOptions,
);
}

Future initializeLaunchOptions() async {
koukibadr marked this conversation as resolved.
Show resolved Hide resolved
if (Platform.isAndroid) {
launchOptions = AndroidLaunchOptions();
} else if (Platform.isIOS) {
launchOptions = IOSLaunchOptions();
}
}

@override
Future<void> logException({
required Exception exception,
StackTrace? stackTrace,
}) async {
if (_isBugSeeInitialized) {
await Bugsee.logException(exception, stackTrace);
}
}
}
14 changes: 13 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 @@ -35,14 +36,14 @@ late Logger _logger;

Future<void> main() async {
await initializeComponents();

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 +118,17 @@ Future _registerAndLoadLoggers() async {
GetIt.I.registerSingleton(_logger);
}

Future _registerBugseeManager() async {
GetIt.I.registerSingleton<BugseeManager>(
BugseeManager(
logger: GetIt.I.get<Logger>(),
),
);
GetIt.I.get<BugseeManager>().initialize(
bugseeToken: const String.fromEnvironment('BUGSEE_TOKEN'),
);
}

/// 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
1 change: 1 addition & 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 Down
4 changes: 4 additions & 0 deletions src/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

Prefix your items with `(Template)` if the change is about the template and not the resulting application.

## 0.21.0
- Add bugsee sdk in Fluttter template
- Update build stage in `steps-build-android.yml` and `steps-build-ios` providing bugsee token

## 0.20.4
- Updates to documentation

Expand Down