Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle gradle version strings missing a patch version #2602

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
58 changes: 47 additions & 11 deletions packages/shorebird_cli/test/src/executables/gradlew_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ 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
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('7.6.3'));
},
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 8.3
------------------------------------------------------------

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('8.3'));
},
testOn: 'linux || mac-os',
);
});

group('when the output cannot be parsed', () {
setUp(() {
Expand Down
Loading