Skip to content

Commit

Permalink
fix: handle gradle version strings missing a patch version (#2602)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Nov 4, 2024
1 parent 9e55e50 commit d8b3d20
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
5 changes: 3 additions & 2 deletions packages/shorebird_cli/lib/src/executables/gradlew.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ class Gradlew {
Future<String> 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';
Expand Down
60 changes: 48 additions & 12 deletions packages/shorebird_cli/test/src/executables/gradlew_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(() {
Expand Down

0 comments on commit d8b3d20

Please sign in to comment.