From d8b3d20f29bf19da42795a6825152566a97563ff Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Mon, 4 Nov 2024 11:12:59 -0500 Subject: [PATCH] fix: handle gradle version strings missing a patch version (#2602) --- .../lib/src/executables/gradlew.dart | 5 +- .../test/src/executables/gradlew_test.dart | 60 +++++++++++++++---- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/packages/shorebird_cli/lib/src/executables/gradlew.dart b/packages/shorebird_cli/lib/src/executables/gradlew.dart index 954ffc0e..682fce6b 100644 --- a/packages/shorebird_cli/lib/src/executables/gradlew.dart +++ b/packages/shorebird_cli/lib/src/executables/gradlew.dart @@ -126,8 +126,9 @@ class Gradlew { Future version(String projectRoot) async { final result = await _run(['--version'], projectRoot); - // Tries to match version string in the output (e.g. "Gradle 7.6.3") - final versionPattern = RegExp(r'Gradle (\d+\.\d+\.\d+)'); + // Tries to match version string in the output (e.g. "Gradle 7.6.3" or + // "Grade 8.3") + final versionPattern = RegExp(r'Gradle (\d+\.\d+(\.\d+)?)'); final match = versionPattern.firstMatch(result.stdout.toString()); return match?.group(1) ?? 'unknown'; diff --git a/packages/shorebird_cli/test/src/executables/gradlew_test.dart b/packages/shorebird_cli/test/src/executables/gradlew_test.dart index 18666715..aa27db5f 100644 --- a/packages/shorebird_cli/test/src/executables/gradlew_test.dart +++ b/packages/shorebird_cli/test/src/executables/gradlew_test.dart @@ -436,10 +436,14 @@ BUILD FAILED in 3s File( p.join(tempDir.path, 'android', 'gradlew'), ).createSync(recursive: true); - when(() => result.stdout).thenReturn(''' + }); + + group('when version string has a patch version', () { + setUp(() { + when(() => result.stdout).thenReturn(''' ------------------------------------------------------------ -Gradle 7.6.3 +Gradle 12.34.56 ------------------------------------------------------------ Build time: 2023-10-04 15:59:47 UTC @@ -451,18 +455,50 @@ Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 11.0.23 (Azul Systems, Inc. 11.0.23+9-LTS) OS: Mac OS X 14.4.1 aarch64 '''); + }); + + test( + 'returns the correct version', + () async { + final version = await runWithOverrides( + () => gradlew.version(tempDir.path), + ); + expect(version, equals('12.34.56')); + }, + testOn: 'linux || mac-os', + ); }); - test( - 'returns the correct version', - () async { - final version = await runWithOverrides( - () => gradlew.version(tempDir.path), - ); - expect(version, '7.6.3'); - }, - testOn: 'linux || mac-os', - ); + group('when version string has only major and minor versions', () { + setUp(() { + when(() => result.stdout).thenReturn(''' + +------------------------------------------------------------ +Gradle 12.34 +------------------------------------------------------------ + +Build time: 2023-10-04 15:59:47 UTC +Revision: 1694251d59e0d4752d547e1fd5b5020b798a7e71 + +Kotlin: 1.7.10 +Groovy: 3.0.13 +Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 +JVM: 11.0.23 (Azul Systems, Inc. 11.0.23+9-LTS) +OS: Mac OS X 14.4.1 aarch64 +'''); + }); + + test( + 'returns the correct version', + () async { + final version = await runWithOverrides( + () => gradlew.version(tempDir.path), + ); + expect(version, equals('12.34')); + }, + testOn: 'linux || mac-os', + ); + }); group('when the output cannot be parsed', () { setUp(() {