Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Allow routine Gradle version bumps without change approval

Manav Rathia73704eeedd9
diff --git a/.github/checks/change-approval/files.mjs b/.github/checks/change-approval/files.mjs
index ddee361601..7dd3ea8a03 100644
--- a/.github/checks/change-approval/files.mjs
+++ b/.github/checks/change-approval/files.mjs
@@ -49,7 +49,18 @@ const androidConfigFiles = new Set([
const configFile =
/(^|\/)(\.gitattributes|\.?clippy\.toml|rust-toolchain\.toml|\.cargo\/(config|audit)\.toml|\.npmrc|\.nvmrc|\.tool-versions|\.node-version|\.python-version|gradle-wrapper\.properties)$/;
-export function checkFiles({ files }) {
+const normalizeGradleVersions = (text) =>
+ text
+ .replace(
+ /^([ \t]*versionName\s*=?\s*["'])\d[\w.+-]*(?=["']$)/gm,
+ (_, prefix) => `${prefix}0`,
+ )
+ .replace(
+ /^([ \t]*versionCode\b\s*=?\s*(?:[^\n]*\?:\s*)?)\d+$/gm,
+ (_, prefix) => `${prefix}0`,
+ );
+
+export function checkFiles({ files, readVersions }) {
const binaries = files
.filter(
({ path, binary, deleted }) =>
@@ -69,6 +80,15 @@ export function checkFiles({ files }) {
(path.startsWith("android/") &&
androidConfigFiles.has(basename(path))),
)
+ .filter(({ path, added, deleted }) => {
+ if (added || deleted || !/\.gradle(\.kts)?$/.test(path))
+ return true;
+ const { before, after } = readVersions(path);
+ return (
+ normalizeGradleVersions(before) !==
+ normalizeGradleVersions(after)
+ );
+ })
.map(({ path }) => path);
const configs = files
.filter(({ path }) => configFile.test(path))
diff --git a/.github/checks/change-approval/test.mjs b/.github/checks/change-approval/test.mjs
index a696e3fe0f..e762397a55 100644
--- a/.github/checks/change-approval/test.mjs
+++ b/.github/checks/change-approval/test.mjs
@@ -845,6 +845,25 @@ test("Android lint configurations need approval when added, edited, or deleted",
}
});
+test("Gradle version bumps are exempt only when nothing else changes", (t) => {
+ const version = (n) => `versionName = "1.2.${n}"
+versionCode = findProperty("build")?.toString()?.toInt() ?: ${n}
+versionName '1.2.${n}-beta'
+versionCode ${n}
+`;
+ for (const path of [
+ "android/a/build.gradle",
+ "android/b/build.gradle.kts",
+ ]) {
+ const base = { [path]: version(1) };
+ assert.equal(scan(t, base, { [path]: version(2) }), "");
+ assert.match(
+ scan(t, base, { [path]: version(2) + 'apply(plugin = "other")\n' }),
+ /^1 guardrail file\n/,
+ );
+ }
+});
+
test("Android lint scripts and checks need approval when edited", (t) => {
assert.match(
scan(