From 04af1ccfadc9da079caec207a396e70262b6cc43 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Jul 2025 12:50:47 +0300 Subject: [PATCH 1/5] Use one constant for version string --- .../core/plugin/src/withSentryAndroidGradlePlugin.ts | 6 +++--- .../expo-plugin/withSentryAndroidGradlePlugin.test.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/core/plugin/src/withSentryAndroidGradlePlugin.ts b/packages/core/plugin/src/withSentryAndroidGradlePlugin.ts index 27a9a4d904..04ee5cc73c 100644 --- a/packages/core/plugin/src/withSentryAndroidGradlePlugin.ts +++ b/packages/core/plugin/src/withSentryAndroidGradlePlugin.ts @@ -13,6 +13,8 @@ export interface SentryAndroidGradlePluginOptions { includeSourceContext?: boolean; } +export const sentryAndroidGradlePluginVersion = '4.14.1'; + /** * Adds the Sentry Android Gradle Plugin to the project. * https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#enable-sentry-agp @@ -29,8 +31,6 @@ export function withSentryAndroidGradlePlugin( includeSourceContext = false, }: SentryAndroidGradlePluginOptions = {}, ): any { - const version = '4.14.1'; - // Modify android/build.gradle const withSentryProjectBuildGradle = (config: any): any => { return withProjectBuildGradle(config, (projectBuildGradle: any) => { @@ -45,7 +45,7 @@ export function withSentryAndroidGradlePlugin( return config; } - const dependency = `classpath("io.sentry:sentry-android-gradle-plugin:${version}")`; + const dependency = `classpath("io.sentry:sentry-android-gradle-plugin:${sentryAndroidGradlePluginVersion}")`; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (projectBuildGradle.modResults.contents.includes(dependency)) { diff --git a/packages/core/test/expo-plugin/withSentryAndroidGradlePlugin.test.ts b/packages/core/test/expo-plugin/withSentryAndroidGradlePlugin.test.ts index be48ecea14..6b513afd41 100644 --- a/packages/core/test/expo-plugin/withSentryAndroidGradlePlugin.test.ts +++ b/packages/core/test/expo-plugin/withSentryAndroidGradlePlugin.test.ts @@ -2,7 +2,10 @@ import { withAppBuildGradle, withProjectBuildGradle } from '@expo/config-plugins import { warnOnce } from '../../plugin/src/utils'; import type { SentryAndroidGradlePluginOptions } from '../../plugin/src/withSentryAndroidGradlePlugin'; -import { withSentryAndroidGradlePlugin } from '../../plugin/src/withSentryAndroidGradlePlugin'; +import { + sentryAndroidGradlePluginVersion, + withSentryAndroidGradlePlugin, +} from '../../plugin/src/withSentryAndroidGradlePlugin'; jest.mock('@expo/config-plugins', () => ({ withProjectBuildGradle: jest.fn(), @@ -43,7 +46,6 @@ describe('withSentryAndroidGradlePlugin', () => { }); it('adds the Sentry plugin to build.gradle when enableAndroidGradlePlugin is enabled', () => { - const version = '4.14.1'; const options: SentryAndroidGradlePluginOptions = { enableAndroidGradlePlugin: true }; (withProjectBuildGradle as jest.Mock).mockImplementation((config, callback) => { @@ -65,13 +67,12 @@ describe('withSentryAndroidGradlePlugin', () => { }); expect(modifiedGradle.modResults.contents).toContain( - `classpath("io.sentry:sentry-android-gradle-plugin:${version}")`, + `classpath("io.sentry:sentry-android-gradle-plugin:${sentryAndroidGradlePluginVersion}")`, ); }); it('warnOnce if the Sentry plugin is already included in build.gradle', () => { - const version = '4.14.1'; - const includedBuildGradle = `dependencies { classpath("io.sentry:sentry-android-gradle-plugin:${version}")}`; + const includedBuildGradle = `dependencies { classpath("io.sentry:sentry-android-gradle-plugin:${sentryAndroidGradlePluginVersion}")}`; const options: SentryAndroidGradlePluginOptions = { enableAndroidGradlePlugin: true }; (withProjectBuildGradle as jest.Mock).mockImplementation((config, callback) => { From c70f4678c028377af3d4c12b20bcbdc4506b3e0b Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Jul 2025 12:51:01 +0300 Subject: [PATCH 2/5] Add updater script --- .github/workflows/update-deps.yml | 11 ++ .../update-sentry-android-gradle-plugin.sh | 106 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100755 scripts/update-sentry-android-gradle-plugin.sh diff --git a/.github/workflows/update-deps.yml b/.github/workflows/update-deps.yml index 8bdad428d5..8959d5d93c 100644 --- a/.github/workflows/update-deps.yml +++ b/.github/workflows/update-deps.yml @@ -86,3 +86,14 @@ jobs: changelog-entry: false secrets: api-token: ${{ secrets.CI_DEPLOY_KEY }} + + sentry-android-gradle-plugin: + uses: getsentry/github-workflows/.github/workflows/updater.yml@v2 + with: + path: scripts/update-sentry-android-gradle-plugin.sh + name: Sentry Android Gradle Plugin + pattern: '^v[0-9.]+$' # only match non-preview versions + pr-strategy: update + changelog-entry: false + secrets: + api-token: ${{ secrets.CI_DEPLOY_KEY }} diff --git a/scripts/update-sentry-android-gradle-plugin.sh b/scripts/update-sentry-android-gradle-plugin.sh new file mode 100755 index 0000000000..5eab0e4de3 --- /dev/null +++ b/scripts/update-sentry-android-gradle-plugin.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ $# -lt 1 ]; then + echo "Usage: $0 {get-version|get-repo|set-version }" + exit 1 +fi + +# Files to search and update Sentry Android Gradle Plugin version +files=( + "$(dirname "$0")/../packages/core/plugin/src/withSentryAndroidGradlePlugin.ts" + "$(dirname "$0")/../samples/react-native/android/build.gradle" +) + +# Regex patterns to match version declarations +ts_regex="export const sentryAndroidGradlePluginVersion = ['\"]([0-9]+\.[0-9]+\.[0-9]+)['\"]" +gradle_regex="classpath\(['\"]io\.sentry:sentry-android-gradle-plugin:([0-9]+\.[0-9]+\.[0-9]+)['\"]" + +# Sentry uses a prefix in the repo tags, but we want to remove it for the version in the files +tagPrefix='v' + +first_match="" + +for file in "${files[@]}"; do + if [[ ! -f "$file" ]]; then + continue + fi + while IFS= read -r line; do + # Check both TypeScript and Gradle patterns + if [[ $line =~ $ts_regex ]] || [[ $line =~ $gradle_regex ]]; then + first_match="${BASH_REMATCH[1]}" + break 2 + fi + done < "$file" +done + +if [[ -z "$first_match" && "$1" != "get-repo" ]]; then + echo "Failed to find the Sentry Android Gradle Plugin version in any of the following files:" + for file in "${files[@]}"; do + echo " - $file" + done + exit 1 +fi + +case $1 in +get-version) + echo "$first_match" + ;; + +get-repo) + echo "https://github.com/getsentry/sentry-android-gradle-plugin" + ;; + +set-version) + if [ $# -ne 2 ]; then + echo "Usage: $0 set-version " + exit 1 + fi + new_version=$2 + # remove $tagPrefix from the $version by skipping the first `strlen($tagPrefix)` characters + if [[ "$new_version" == "$tagPrefix"* ]]; then + new_version="${new_version:${#tagPrefix}}" + fi + for file in "${files[@]}"; do + if [[ ! -f "$file" ]]; then + echo "⚠️ File not found: $file" + continue + fi + updated=false + tmpfile=$(mktemp) + while IFS= read -r line; do + if [[ $line =~ $ts_regex ]]; then + new_line="export const sentryAndroidGradlePluginVersion = '${new_version}';" + echo "$new_line" >> "$tmpfile" + updated=true + elif [[ $line =~ $gradle_regex ]]; then + # Preserve the original quote style and indentation + quote_char="'" + if [[ $line == *\"* ]]; then + quote_char="\"" + fi + # Extract indentation from the original line + indentation=$(echo "$line" | sed 's/[^ \t].*//') + new_line="${indentation}classpath(${quote_char}io.sentry:sentry-android-gradle-plugin:${new_version}${quote_char})" + echo "$new_line" >> "$tmpfile" + updated=true + else + echo "$line" >> "$tmpfile" + fi + done < "$file" + if $updated; then + mv "$tmpfile" "$file" + echo "✅ Updated $file to Sentry Android Gradle Plugin version: '$new_version'" + else + rm "$tmpfile" + echo "⚠️ No Sentry Android Gradle Plugin version found in $file" + fi + done + ;; + +*) + echo "Unknown argument $1" + echo "Usage: $0 {get-version|get-repo|set-version }" + exit 1 + ;; +esac From 990a349568522326ab7e04e0b41d0cc7b01262a0 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Jul 2025 12:52:30 +0300 Subject: [PATCH 3/5] Add temporary branch to test bump script --- .github/workflows/update-deps.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update-deps.yml b/.github/workflows/update-deps.yml index 8959d5d93c..db5fa9c959 100644 --- a/.github/workflows/update-deps.yml +++ b/.github/workflows/update-deps.yml @@ -8,6 +8,7 @@ on: push: branches: - main + - antonis/sagp-updater # temporary branch to test bump script jobs: android: From 8512da195468c72907121c0d401608a1b52d8e62 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Jul 2025 12:58:44 +0300 Subject: [PATCH 4/5] Update version matching pattern --- .github/workflows/update-deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-deps.yml b/.github/workflows/update-deps.yml index db5fa9c959..139d27e255 100644 --- a/.github/workflows/update-deps.yml +++ b/.github/workflows/update-deps.yml @@ -93,7 +93,7 @@ jobs: with: path: scripts/update-sentry-android-gradle-plugin.sh name: Sentry Android Gradle Plugin - pattern: '^v[0-9.]+$' # only match non-preview versions + pattern: '^[0-9.]+$' pr-strategy: update changelog-entry: false secrets: From 8692ee4f547974a04ffce19f5dba409c0d424ebe Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Jul 2025 13:02:52 +0300 Subject: [PATCH 5/5] Revert "Add temporary branch to test bump script" This reverts commit 990a349568522326ab7e04e0b41d0cc7b01262a0. --- .github/workflows/update-deps.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/update-deps.yml b/.github/workflows/update-deps.yml index 139d27e255..4c52f128f4 100644 --- a/.github/workflows/update-deps.yml +++ b/.github/workflows/update-deps.yml @@ -8,7 +8,6 @@ on: push: branches: - main - - antonis/sagp-updater # temporary branch to test bump script jobs: android: