Skip to content

Commit 774257e

Browse files
antonisclaude
andauthored
fix(ci): Support version catalog in android SDK version check (#6280)
The sentry-android-gradle-plugin moved the bundled SDK version from plugin-build/gradle.properties to gradle/libs.versions.toml in 6.10.0. Fall back to the TOML file when gradle.properties lacks sdk_version. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 378eb4b commit 774257e

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

scripts/check-android-sdk-mismatch.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,51 @@ const createSectionWarning = (title, content, icon = '❌') => {
99
return `### ${icon} ${title}\n\n${content}\n`;
1010
};
1111

12-
/**
13-
* Fetches the SDK version from gradle.properties in the gradle plugin GitHub repo.
14-
* The file contains a line like: sdk_version = X.Y.Z
15-
*/
16-
function fetchBundledSentryAndroidVersion(gradlePluginVersion) {
12+
function fetchFileContent(url) {
1713
return new Promise((resolve, reject) => {
18-
const url = `https://raw.githubusercontent.com/getsentry/sentry-android-gradle-plugin/${gradlePluginVersion}/plugin-build/gradle.properties`;
19-
2014
https
2115
.get(url, res => {
2216
if (res.statusCode !== 200) {
23-
reject(new Error(`Could not fetch gradle.properties for version ${gradlePluginVersion}`));
17+
reject(new Error(`HTTP ${res.statusCode} for ${url}`));
2418
return;
2519
}
2620

2721
let data = '';
2822
res.on('data', chunk => (data += chunk));
29-
res.on('end', () => {
30-
// Look for: sdk_version = X.Y.Z
31-
const versionMatch = data.match(/sdk_version\s*=\s*(\S+)/);
32-
if (versionMatch) {
33-
resolve(versionMatch[1]);
34-
} else {
35-
reject(new Error(`Could not find sdk_version in gradle.properties`));
36-
}
37-
});
23+
res.on('end', () => resolve(data));
3824
})
3925
.on('error', reject);
4026
});
4127
}
4228

29+
/**
30+
* Fetches the SDK version from the gradle plugin GitHub repo.
31+
*
32+
* Checks gradle.properties first (sdk_version = X.Y.Z, pre-6.10.0),
33+
* then falls back to gradle/libs.versions.toml (sentry = "X.Y.Z", 6.10.0+).
34+
*/
35+
function fetchBundledSentryAndroidVersion(gradlePluginVersion) {
36+
const base = `https://raw.githubusercontent.com/getsentry/sentry-android-gradle-plugin/${gradlePluginVersion}`;
37+
38+
return fetchFileContent(`${base}/plugin-build/gradle.properties`)
39+
.then(data => {
40+
const match = data.match(/sdk_version\s*=\s*(\S+)/);
41+
if (match) {
42+
return match[1];
43+
}
44+
throw new Error('sdk_version not found');
45+
})
46+
.catch(() =>
47+
fetchFileContent(`${base}/gradle/libs.versions.toml`).then(data => {
48+
const match = data.match(/^sentry\s*=\s*"([^"]+)"/m);
49+
if (match) {
50+
return match[1];
51+
}
52+
throw new Error(`Could not find sentry-android version for gradle plugin ${gradlePluginVersion}`);
53+
}),
54+
);
55+
}
56+
4357
module.exports = async function ({ fail, warn, __, ___, danger }) {
4458
const gradlePluginFileChanged = danger.git.modified_files.includes(GRADLE_PLUGIN_FILE);
4559
const buildGradleFileChanged = danger.git.modified_files.includes(BUILD_GRADLE_FILE);

0 commit comments

Comments
 (0)