From d76958f685687ec66aa4f89f54bfc1265b3fe513 Mon Sep 17 00:00:00 2001 From: Badr Kouki Date: Thu, 14 Nov 2024 12:38:34 +0100 Subject: [PATCH] build: update bugsee manager and bugsee configuration in azure pipeline --- .DS_Store | Bin 0 -> 6148 bytes .vscode/launch.json | 8 ++- build/azure-pipelines.yml | 1 + build/stage-build.yml | 3 + build/steps-build-android.yml | 11 +-- build/steps-build-ios.yml | 17 +---- src/.DS_Store | Bin 0 -> 6148 bytes .../lib/business/bugsee/bugsee_manager.dart | 63 +++++++++++++----- .../environment/environment_manager.dart | 14 ---- src/app/lib/main.dart | 10 ++- src/app/pubspec.yaml | 1 - src/cli/CHANGELOG.md | 4 ++ 12 files changed, 67 insertions(+), 65 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..08900a3f1c889c9a83eab371640b48fb8537c8ed GIT binary patch literal 6148 zcmeHKO-lnY5S`d+w~Ek%g5DOqidHR3@v>C?1Fq;nrFL!6#dRaytv!^&p4A_uf5hM8 zn*}{^ulQ3?|ZcTRLW}&8xX>l3m}2KFJ@Cj~3ro<3B9rLbP=NZg2>U0vO_z>pJ!c-_iy&cbY)p8P^M%!8itOBD7 zB_CYoKKA)(LWa*ShcvI2*6aG^!Ld<~mj#zKWON a$`Et81N01L8ZiU2e*}~awy_F)s{(JGpu~*; literal 0 HcmV?d00001 diff --git a/.vscode/launch.json b/.vscode/launch.json index 37ad4306..55e8e8cf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -28,7 +28,9 @@ "program": "src/app/lib/main.dart", "toolArgs": [ "--dart-define", - "ENV=Staging" + "ENV=Staging", + "--dart-define", + "BUGSEE_TOKEN=" ] }, { @@ -39,7 +41,9 @@ "program": "src/app/lib/main.dart", "toolArgs": [ "--dart-define", - "ENV=Production" + "ENV=Production", + "--dart-define", + "BUGSEE_TOKEN=" ] }, { diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index a4ce924d..8cc33658 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -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')) diff --git a/build/stage-build.yml b/build/stage-build.yml index 6ebe0553..0e0b6b12 100644 --- a/build/stage-build.yml +++ b/build/stage-build.yml @@ -56,6 +56,9 @@ type: string - name: googleServicesJsonFile type: string +- name: bugseeVariableGroup + type: string + default: '' jobs: - job: OnWindows_ReleaseNotes diff --git a/build/steps-build-android.yml b/build/steps-build-android.yml index 35849e76..c1e9181c 100644 --- a/build/steps-build-android.yml +++ b/build/steps-build-android.yml @@ -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 @@ -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' @@ -100,6 +90,7 @@ steps: projectDirectory: '${{ parameters.pathToSrc }}/app' verboseMode: true dartDefine: ENV=$(applicationEnvironment) + dartDefine: BUGSEE_TOKEN=$(AndroidDevToken) - template: templates/flutter-diagnostics.yml parameters: diff --git a/build/steps-build-ios.yml b/build/steps-build-ios.yml index ac484f23..9a852577 100644 --- a/build/steps-build-ios.yml +++ b/build/steps-build-ios.yml @@ -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' @@ -112,6 +96,7 @@ steps: verboseMode: true exportOptionsPlist: '$(exportOptions.secureFilePath)' dartDefine: ENV=$(applicationEnvironment) + dartDefine: BUGSEE_TOKEN=$(iOSDevToken) - template: templates/flutter-diagnostics.yml parameters: diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b893053f523adae32946995a15b826b3a15b3c3e GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8O({YT3iY<&wP63S6fdFH7cim+m73V1!I%yGF^5vfS$!aV5ueAI z-L16N+FKEwf!S|&b|&Hb60#Y_7;lZb6~+pTF$)|qm4o3M!+rDxOPNRpkmEH5krzl0 zR&QRkkWGQ#r~p2@G;>+RA}^kOet|z2mdo!vmCkHzX05E1x2~K!89PIFI2yFv{spd1 zr3}33-1W}on;P*j*BiaTNjq1|@gK7Z)@i$T#%(0ii8ez~jm}rC@Fs@4hbtyM32G`{f7bed( zm}u1HjGN|zn>%yUp>TC~xV}*7jN2M%Bn3!;c?HsXS-|uEczORnUqmZXfE4&s3h+$Z zX}5rqIa?RV;aMxduffqUFVXl}0uyx 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 initialize({ + String? bugseeToken, + }); + + ///Manually log a provided exception with a stack trace + Future 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 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 logException({ + required Exception exception, + StackTrace? stackTrace, + }) async { + if (_isBugSeeInitialized) { + await Bugsee.logException(exception, stackTrace); } } } diff --git a/src/app/lib/business/environment/environment_manager.dart b/src/app/lib/business/environment/environment_manager.dart index b52052bf..74484c4d 100644 --- a/src/app/lib/business/environment/environment_manager.dart +++ b/src/app/lib/business/environment/environment_manager.dart @@ -33,12 +33,6 @@ final class _EnvironmentManager implements EnvironmentManager { Environment.production: '.env.prod', }; - final Map _bugseeFileName = { - Environment.development: '.bugsee.dev', - Environment.staging: '.bugsee.dev', - Environment.production: '.bugsee.dev', - }; - @override late List environments; @@ -63,16 +57,8 @@ final class _EnvironmentManager implements EnvironmentManager { ); next = null; - await dotenv.load( - fileName: _bugseeFileName[current]!, - ); - Map 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, ); } diff --git a/src/app/lib/main.dart b/src/app/lib/main.dart index 5fa513c7..3f83d5df 100644 --- a/src/app/lib/main.dart +++ b/src/app/lib/main.dart @@ -36,12 +36,7 @@ late Logger _logger; Future main() async { await initializeComponents(); - - GetIt.I.get().initialize( - runApp: () { - runApp(const App()); - }, - ); + runApp(const App()); } Future initializeComponents({bool? isMocked}) async { @@ -129,6 +124,9 @@ Future _registerBugseeManager() async { logger: GetIt.I.get(), ), ); + GetIt.I.get().initialize( + bugseeToken: const String.fromEnvironment('BUGSEE_TOKEN'), + ); } /// Registers the HTTP client. diff --git a/src/app/pubspec.yaml b/src/app/pubspec.yaml index c619e709..5b600d32 100644 --- a/src/app/pubspec.yaml +++ b/src/app/pubspec.yaml @@ -58,4 +58,3 @@ flutter: - .env.dev - .env.staging - .env.prod - - .bugsee.dev diff --git a/src/cli/CHANGELOG.md b/src/cli/CHANGELOG.md index 07c8c62f..a5ec128b 100644 --- a/src/cli/CHANGELOG.md +++ b/src/cli/CHANGELOG.md @@ -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