From f1a5405705bbc0b319fd52f63c50e743d6e885dc Mon Sep 17 00:00:00 2001 From: QcFe <10742159+QcFe@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:03:12 +0100 Subject: [PATCH] feat(ci): switch sentry sourcemap upload to wizard management --- .github/workflows/build.yaml | 31 +++++++++++++++++++------- .gitignore | 2 ++ .nvmrc | 2 +- Gemfile.lock | 3 --- android/app/build.gradle | 2 ++ android/fastlane/Fastfile | 28 ++++++----------------- android/fastlane/Pluginfile | 1 - ios/fastlane/Fastfile | 15 ------------- ios/fastlane/Pluginfile | 1 - ios/students.xcodeproj/project.pbxproj | 2 +- metro.config.js | 8 +++++-- src/utils/sentry.ts | 10 ++++----- 12 files changed, 46 insertions(+), 59 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3fb244dd..ee4d879c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -195,26 +195,35 @@ jobs: run: | echo "${{ secrets.SUPPLY_GOOGLE_JSON_SECRET }}" | base64 -d > ${SUPPLY_GOOGLE_JSON_PATH} echo "${{ secrets.ANDROID_KEYSTORE_B64 }}" | base64 -d > ${KEYSTORE_PATH} + echo "${{ secrets.SENTRY_DOT_PROPERTIES }}" | base64 -d > sentry.properties chmod 600 ${KEYSTORE_PATH} ${SUPPLY_GOOGLE_JSON_PATH} - name: Fastlane VERIFY lane if: needs.configure.outputs.push_to_playstore == 'false' working-directory: ./android + env: + SENTRY_DISABLE_AUTO_UPLOAD: "true" run: bundle exec fastlane verify - name: Fastlane RELEASE lane + id: fastlane_release_android if: contains(fromJSON('["internal", "beta", "production"]'), needs.configure.outputs.push_to_playstore) working-directory: ./android env: STORE_TRACK: ${{ needs.configure.outputs.push_to_playstore }} - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} - SENTRY_ORG: ${{ vars.SENTRY_ORG }} run: bundle exec fastlane release + - name: Fastlane RELEASE lane [without Sentry] + if: steps.fastlane_release_android.outcome == 'failure' + working-directory: ./android + run: bundle exec fastlane release + env: + SENTRY_DISABLE_AUTO_UPLOAD: "true" - name: Fastlane APK lane if: | (github.event_name == 'push' && github.ref_type == 'tag') || github.event.inputs.create_release == 'true' run: bundle exec fastlane apk working-directory: ./android + env: + SENTRY_DISABLE_AUTO_UPLOAD: "true" - name: Upload Artifacts if: | (github.event_name == 'push' && github.ref_type == 'tag') || @@ -293,21 +302,27 @@ jobs: echo "${{ secrets.MATCH_GIT_AUTH_PK }}" > ${MATCH_GIT_PRIVATE_KEY} chmod 600 ${MATCH_GIT_PRIVATE_KEY} echo "${{ secrets.SUPPLY_GOOGLE_SERVICE_INFO_PLIST }}" | base64 -d > ${SUPPLY_GOOGLE_SERVICE_INFO_PLIST_PATH} + echo "${{ secrets.SENTRY_DOT_PROPERTIES }}" | base64 -d > sentry.properties chmod 600 ${MATCH_GIT_PRIVATE_KEY} ${SUPPLY_GOOGLE_SERVICE_INFO_PLIST_PATH} - name: Fastlane VERIFY lane if: needs.configure.outputs.push_to_testflight == 'false' working-directory: ./ios + env: + SENTRY_DISABLE_AUTO_UPLOAD: "true" run: | bundle exec fastlane verify - name: Fastlane RELEASE lane + id: fastlane_release_ios if: needs.configure.outputs.push_to_testflight == 'true' working-directory: ./ios + run: bundle exec fastlane release + continue-on-error: true + - name: Fastlane RELEASE lane [without Sentry] + if: steps.fastlane_release_ios.outcome == 'failure' + working-directory: ./ios + run: bundle exec fastlane release env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} - SENTRY_ORG: ${{ vars.SENTRY_ORG }} - run: | - bundle exec fastlane release + SENTRY_DISABLE_AUTO_UPLOAD: "true" create-release: name: Create GitHub Release diff --git a/.gitignore b/.gitignore index 3a0e01fc..509f91f2 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,5 @@ npm-debug.* /ios/fastlane/report.xml .npmrc +android/sentry.properties +ios/sentry.properties diff --git a/.nvmrc b/.nvmrc index 123b0527..9be0c705 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -18.20.2 +18.20.7 diff --git a/Gemfile.lock b/Gemfile.lock index 19b50bac..cb4fc261 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -167,8 +167,6 @@ GEM xcodeproj (>= 1.13.0, < 2.0.0) xcpretty (~> 0.4.0) xcpretty-travis-formatter (>= 0.0.3, < 2.0.0) - fastlane-plugin-sentry (1.27.1) - os (~> 1.1, >= 1.1.4) fastlane-plugin-versioning_android (0.1.1) fastlane-sirp (1.0.0) sysrandom (~> 1.0) @@ -295,7 +293,6 @@ DEPENDENCIES cocoapods (>= 1.13, != 1.15.1, != 1.15.0) concurrent-ruby (< 1.3.4) fastlane - fastlane-plugin-sentry fastlane-plugin-versioning_android xcodeproj (< 1.26.0) diff --git a/android/app/build.gradle b/android/app/build.gradle index d99d0f5e..3a1a3d6c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -75,6 +75,8 @@ def enableProguardInReleaseBuilds = false */ def jscFlavor = 'org.webkit:android-jsc:+' +apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle") + android { ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion diff --git a/android/fastlane/Fastfile b/android/fastlane/Fastfile index 86708dd0..5a12f3f7 100644 --- a/android/fastlane/Fastfile +++ b/android/fastlane/Fastfile @@ -24,7 +24,6 @@ buildProps = { } platform :android do - desc "Build and sign bundle" lane :verify do gradle( @@ -43,31 +42,18 @@ platform :android do properties: buildProps, ) - upload_to_play_store( - track: ENV['STORE_TRACK'], - release_status: "draft", - ) - - source_map_path = 'app/build/generated/sourcemaps/react/release/index.android.bundle.map' - bundle_path = 'app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle' + upload_to_play_store( + track: ENV['STORE_TRACK'], + release_status: "draft", + ) - begin - sentry_upload_sourcemap( - auth_token: ENV['SENTRY_AUTH_TOKEN'], - org_slug: ENV['SENTRY_ORG'], - project_slug: ENV['SENTRY_PROJECT'], - version: 'it.polito.students@' + ENV['APP_VERSION'], - dist: ENV['BUILD_NO'], - sourcemap: [bundle_path, source_map_path], - rewrite: true - ) - rescue => e - UI.important("Sentry sourcemap upload failed => #{e.message}") - end end desc "Assemble signed Android APK" lane :apk do + android_set_version_name(version_name: ENV['APP_VERSION']) + android_set_version_code(version_code: ENV['BUILD_NO']) + gradle( task: "assembleRelease", properties: buildProps, diff --git a/android/fastlane/Pluginfile b/android/fastlane/Pluginfile index 9a0b82d5..052b0905 100644 --- a/android/fastlane/Pluginfile +++ b/android/fastlane/Pluginfile @@ -3,4 +3,3 @@ # Ensure this file is checked in to source control! gem 'fastlane-plugin-versioning_android' -gem 'fastlane-plugin-sentry' \ No newline at end of file diff --git a/ios/fastlane/Fastfile b/ios/fastlane/Fastfile index a3e8e44e..c81873bd 100644 --- a/ios/fastlane/Fastfile +++ b/ios/fastlane/Fastfile @@ -40,21 +40,6 @@ platform :ios do apple_id: "6443913305", ) - source_map_path = '../../main.jsbundle.map' - - begin - sentry_upload_sourcemap( - auth_token: ENV['SENTRY_AUTH_TOKEN'], - org_slug: ENV['SENTRY_ORG'], - project_slug: ENV['SENTRY_PROJECT'], - version: 'it.polito.students@' + ENV['APP_VERSION'], - dist: ENV['BUILD_NO'], - sourcemap: [source_map_path], - rewrite: true - ) - rescue => e - UI.important("Sentry sourcemap upload failed => #{e.message}") - end end lane :verify do diff --git a/ios/fastlane/Pluginfile b/ios/fastlane/Pluginfile index 75661bc1..273a6b6f 100644 --- a/ios/fastlane/Pluginfile +++ b/ios/fastlane/Pluginfile @@ -1,4 +1,3 @@ # Autogenerated by fastlane # # Ensure this file is checked in to source control! -gem 'fastlane-plugin-sentry' \ No newline at end of file diff --git a/ios/students.xcodeproj/project.pbxproj b/ios/students.xcodeproj/project.pbxproj index dfd62c13..efaa81d2 100644 --- a/ios/students.xcodeproj/project.pbxproj +++ b/ios/students.xcodeproj/project.pbxproj @@ -409,7 +409,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export SOURCEMAP_FILE=\"../main.jsbundle.map\";\n\nset -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n"; + shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\\\"\"\n"; }; 085B7CE994A953E0D75AFD27 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; diff --git a/metro.config.js b/metro.config.js index 9d41685e..ec9f34a9 100644 --- a/metro.config.js +++ b/metro.config.js @@ -1,4 +1,6 @@ -const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); +const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); + +const { withSentryConfig } = require('@sentry/react-native/metro'); /** * Metro configuration @@ -8,4 +10,6 @@ const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); */ const config = {}; -module.exports = mergeConfig(getDefaultConfig(__dirname), config); +module.exports = withSentryConfig( + mergeConfig(getDefaultConfig(__dirname), config), +); diff --git a/src/utils/sentry.ts b/src/utils/sentry.ts index f535ab6f..929616b0 100644 --- a/src/utils/sentry.ts +++ b/src/utils/sentry.ts @@ -1,10 +1,10 @@ -import { APP_BUILD, APP_VERSION } from '@env'; import * as Sentry from '@sentry/react-native'; import { isEnvProduction } from './env'; -export const routingInstrumentation = - new Sentry.ReactNavigationInstrumentation(); +export const routingInstrumentation = Sentry.reactNavigationIntegration({ + enableTimeToInitialDisplay: true, +}); export const initSentry = () => { Sentry.init({ @@ -12,12 +12,10 @@ export const initSentry = () => { enabled: isEnvProduction, enableNative: true, integrations: [ - new Sentry.ReactNativeTracing({ + Sentry.reactNativeTracingIntegration({ routingInstrumentation, }), ], - release: `it.polito.students@${APP_VERSION}`, - dist: APP_BUILD, environment: process.env.NODE_ENV, tracesSampleRate: 1.0, });