Skip to content

Commit

Permalink
build: update bugsee manager and bugsee configuration in azure pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
koukibadr committed Nov 14, 2024
1 parent 1ff2ee5 commit d76958f
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 65 deletions.
Binary file added .DS_Store
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>"
]
},
{
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'

- 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
11 changes: 1 addition & 10 deletions build/steps-build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ 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 @@ -73,9 +66,6 @@ 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 All @@ -100,6 +90,7 @@ steps:
projectDirectory: '${{ parameters.pathToSrc }}/app'
verboseMode: true
dartDefine: ENV=$(applicationEnvironment)
dartDefine: BUGSEE_TOKEN=$(AndroidDevToken)

- template: templates/flutter-diagnostics.yml
parameters:
Expand Down
17 changes: 1 addition & 16 deletions build/steps-build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,6 @@ 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 Expand Up @@ -112,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.
63 changes: 47 additions & 16 deletions src/app/lib/business/bugsee/bugsee_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,90 @@ 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';

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
abstract interface class BugseeManager {
factory BugseeManager({
required Logger logger,
}) = _BugseeManager;

Future<void> initialize({required VoidCallback runApp});
///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;
String? bugseeAccessToken;

_BugseeManager({required this.logger});
late bool _isBugSeeInitialized;

_BugseeManager({
required this.logger,
});

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

if (bugseeAccessToken == null) {
logger.i("bugsee token is null, bugsee won't be initialized");
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;
Bugsee.launch(
bugseeAccessToken ?? '',
await Bugsee.launch(
bugseeToken,
appRunCallback: (isBugseeLaunched) {
if (!isBugseeLaunched) {
logger.e("bugsee is not initialized, verify bugsee token config");
logger
.e("BUGSEE: not initialized, verify bugsee token configuration");
}
runApp();
_isBugSeeInitialized = isBugseeLaunched;
},
launchOptions: launchOptions,
);
}

Future initializeTokensAndOptions() async {
Future initializeLaunchOptions() async {
if (Platform.isAndroid) {
launchOptions = AndroidLaunchOptions();
bugseeAccessToken = dotenv.env['BUGSEE_ANDROID_TOKEN'];
} else if (Platform.isIOS) {
launchOptions = IOSLaunchOptions();
bugseeAccessToken = dotenv.env['BUGSEE_IOS_TOKEN'];
}
}

@override
Future<void> logException({
required Exception exception,
StackTrace? stackTrace,
}) async {
if (_isBugSeeInitialized) {
await Bugsee.logException(exception, stackTrace);
}
}
}
14 changes: 0 additions & 14 deletions src/app/lib/business/environment/environment_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ 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 @@ -63,16 +57,8 @@ 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
10 changes: 4 additions & 6 deletions src/app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ late Logger _logger;

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

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

Future initializeComponents({bool? isMocked}) async {
Expand Down Expand Up @@ -129,6 +124,9 @@ Future _registerBugseeManager() async {
logger: GetIt.I.get<Logger>(),
),
);
GetIt.I.get<BugseeManager>().initialize(
bugseeToken: const String.fromEnvironment('BUGSEE_TOKEN'),
);
}

/// Registers the HTTP client.
Expand Down
1 change: 0 additions & 1 deletion src/app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ flutter:
- .env.dev
- .env.staging
- .env.prod
- .bugsee.dev
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

0 comments on commit d76958f

Please sign in to comment.