Skip to content

Commit c70f467

Browse files
committed
Add updater script
1 parent 04af1cc commit c70f467

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

.github/workflows/update-deps.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@ jobs:
8686
changelog-entry: false
8787
secrets:
8888
api-token: ${{ secrets.CI_DEPLOY_KEY }}
89+
90+
sentry-android-gradle-plugin:
91+
uses: getsentry/github-workflows/.github/workflows/updater.yml@v2
92+
with:
93+
path: scripts/update-sentry-android-gradle-plugin.sh
94+
name: Sentry Android Gradle Plugin
95+
pattern: '^v[0-9.]+$' # only match non-preview versions
96+
pr-strategy: update
97+
changelog-entry: false
98+
secrets:
99+
api-token: ${{ secrets.CI_DEPLOY_KEY }}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ $# -lt 1 ]; then
5+
echo "Usage: $0 {get-version|get-repo|set-version <new_version>}"
6+
exit 1
7+
fi
8+
9+
# Files to search and update Sentry Android Gradle Plugin version
10+
files=(
11+
"$(dirname "$0")/../packages/core/plugin/src/withSentryAndroidGradlePlugin.ts"
12+
"$(dirname "$0")/../samples/react-native/android/build.gradle"
13+
)
14+
15+
# Regex patterns to match version declarations
16+
ts_regex="export const sentryAndroidGradlePluginVersion = ['\"]([0-9]+\.[0-9]+\.[0-9]+)['\"]"
17+
gradle_regex="classpath\(['\"]io\.sentry:sentry-android-gradle-plugin:([0-9]+\.[0-9]+\.[0-9]+)['\"]"
18+
19+
# Sentry uses a prefix in the repo tags, but we want to remove it for the version in the files
20+
tagPrefix='v'
21+
22+
first_match=""
23+
24+
for file in "${files[@]}"; do
25+
if [[ ! -f "$file" ]]; then
26+
continue
27+
fi
28+
while IFS= read -r line; do
29+
# Check both TypeScript and Gradle patterns
30+
if [[ $line =~ $ts_regex ]] || [[ $line =~ $gradle_regex ]]; then
31+
first_match="${BASH_REMATCH[1]}"
32+
break 2
33+
fi
34+
done < "$file"
35+
done
36+
37+
if [[ -z "$first_match" && "$1" != "get-repo" ]]; then
38+
echo "Failed to find the Sentry Android Gradle Plugin version in any of the following files:"
39+
for file in "${files[@]}"; do
40+
echo " - $file"
41+
done
42+
exit 1
43+
fi
44+
45+
case $1 in
46+
get-version)
47+
echo "$first_match"
48+
;;
49+
50+
get-repo)
51+
echo "https://github.com/getsentry/sentry-android-gradle-plugin"
52+
;;
53+
54+
set-version)
55+
if [ $# -ne 2 ]; then
56+
echo "Usage: $0 set-version <new_version>"
57+
exit 1
58+
fi
59+
new_version=$2
60+
# remove $tagPrefix from the $version by skipping the first `strlen($tagPrefix)` characters
61+
if [[ "$new_version" == "$tagPrefix"* ]]; then
62+
new_version="${new_version:${#tagPrefix}}"
63+
fi
64+
for file in "${files[@]}"; do
65+
if [[ ! -f "$file" ]]; then
66+
echo "⚠️ File not found: $file"
67+
continue
68+
fi
69+
updated=false
70+
tmpfile=$(mktemp)
71+
while IFS= read -r line; do
72+
if [[ $line =~ $ts_regex ]]; then
73+
new_line="export const sentryAndroidGradlePluginVersion = '${new_version}';"
74+
echo "$new_line" >> "$tmpfile"
75+
updated=true
76+
elif [[ $line =~ $gradle_regex ]]; then
77+
# Preserve the original quote style and indentation
78+
quote_char="'"
79+
if [[ $line == *\"* ]]; then
80+
quote_char="\""
81+
fi
82+
# Extract indentation from the original line
83+
indentation=$(echo "$line" | sed 's/[^ \t].*//')
84+
new_line="${indentation}classpath(${quote_char}io.sentry:sentry-android-gradle-plugin:${new_version}${quote_char})"
85+
echo "$new_line" >> "$tmpfile"
86+
updated=true
87+
else
88+
echo "$line" >> "$tmpfile"
89+
fi
90+
done < "$file"
91+
if $updated; then
92+
mv "$tmpfile" "$file"
93+
echo "✅ Updated $file to Sentry Android Gradle Plugin version: '$new_version'"
94+
else
95+
rm "$tmpfile"
96+
echo "⚠️ No Sentry Android Gradle Plugin version found in $file"
97+
fi
98+
done
99+
;;
100+
101+
*)
102+
echo "Unknown argument $1"
103+
echo "Usage: $0 {get-version|get-repo|set-version <new_version>}"
104+
exit 1
105+
;;
106+
esac

0 commit comments

Comments
 (0)