Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions scripts/check-android-sdk-mismatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,51 @@ const createSectionWarning = (title, content, icon = '❌') => {
return `### ${icon} ${title}\n\n${content}\n`;
};

/**
* Fetches the SDK version from gradle.properties in the gradle plugin GitHub repo.
* The file contains a line like: sdk_version = X.Y.Z
*/
function fetchBundledSentryAndroidVersion(gradlePluginVersion) {
function fetchFileContent(url) {
return new Promise((resolve, reject) => {
const url = `https://raw.githubusercontent.com/getsentry/sentry-android-gradle-plugin/${gradlePluginVersion}/plugin-build/gradle.properties`;

https
.get(url, res => {
if (res.statusCode !== 200) {
reject(new Error(`Could not fetch gradle.properties for version ${gradlePluginVersion}`));
reject(new Error(`HTTP ${res.statusCode} for ${url}`));
return;
}

let data = '';
res.on('data', chunk => (data += chunk));
res.on('end', () => {
// Look for: sdk_version = X.Y.Z
const versionMatch = data.match(/sdk_version\s*=\s*(\S+)/);
if (versionMatch) {
resolve(versionMatch[1]);
} else {
reject(new Error(`Could not find sdk_version in gradle.properties`));
}
});
res.on('end', () => resolve(data));
})
.on('error', reject);
});
}

/**
* Fetches the SDK version from the gradle plugin GitHub repo.
*
* Checks gradle.properties first (sdk_version = X.Y.Z, pre-6.10.0),
* then falls back to gradle/libs.versions.toml (sentry = "X.Y.Z", 6.10.0+).
*/
function fetchBundledSentryAndroidVersion(gradlePluginVersion) {
const base = `https://raw.githubusercontent.com/getsentry/sentry-android-gradle-plugin/${gradlePluginVersion}`;

return fetchFileContent(`${base}/plugin-build/gradle.properties`)
.then(data => {
const match = data.match(/sdk_version\s*=\s*(\S+)/);
if (match) {
return match[1];
}
throw new Error('sdk_version not found');
})
.catch(() =>
fetchFileContent(`${base}/gradle/libs.versions.toml`).then(data => {
const match = data.match(/^sentry\s*=\s*"([^"]+)"/m);
if (match) {
return match[1];
}
throw new Error(`Could not find sentry-android version for gradle plugin ${gradlePluginVersion}`);
}),
);
Comment thread
antonis marked this conversation as resolved.
}

module.exports = async function ({ fail, warn, __, ___, danger }) {
const gradlePluginFileChanged = danger.git.modified_files.includes(GRADLE_PLUGIN_FILE);
const buildGradleFileChanged = danger.git.modified_files.includes(BUILD_GRADLE_FILE);
Expand Down
Loading