Skip to content

Commit

Permalink
Merge branch 'main' into bo/macos-flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Jan 17, 2025
2 parents cbbb1fd + 09dfd60 commit 902ce8e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 53 deletions.
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ cspell:words pubspec erickzanardo xcframeworks Cupertino codesign codecov rkisha

This section contains past updates we've sent to customers.

## 1.6.4 (January 16, 2025)

- 🔐 Add support for signed patches on Windows
-`shorebird patch` releases list should filter by specified platform
- 👀 Fix various `shorebird preview` errors on macOS (`ditto`)
- 🧑‍🔧 Improve error message when running `shorebird release macos` on an unsupported Flutter project

## 1.6.3 (January 14, 2025)

- 🐦 Support for Flutter 3.27.2
Expand Down
14 changes: 9 additions & 5 deletions packages/shorebird_cli/lib/src/commands/patch/patch_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl
releaseVersion: releaseVersion,
);
} else if (shorebirdEnv.canAcceptUserInput) {
release = await promptForRelease();
release = await promptForRelease(patcher.releaseType.releasePlatform);
} else {
logger.info(
'''Tip: make your patches build faster by specifying --release-version''',
Expand Down Expand Up @@ -418,21 +418,25 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl
}

/// Prompts the user for the specific release to patch.
Future<Release> promptForRelease() async {
Future<Release> promptForRelease(ReleasePlatform platform) async {
final releases = await codePushClientWrapper.getReleases(
appId: appId,
);

if (releases.isEmpty) {
final releasesForPlatform = releases.where(
(release) => release.platformStatuses.keys.contains(platform),
);

if (releasesForPlatform.isEmpty) {
logger.warn(
'''No releases found for app $appId. You need to make first a release before you can create a patch.''',
'''No ${platform.displayName} releases found for app $appId. You must first create a release before you can create a patch.''',
);
throw ProcessExit(ExitCode.usage.code);
}

return logger.chooseOne<Release>(
'Which release would you like to patch?',
choices: releases.sortedBy((r) => r.createdAt).reversed.toList(),
choices: [...releasesForPlatform.sortedBy((r) => r.createdAt).reversed],
display: (r) => r.version,
);
}
Expand Down
25 changes: 0 additions & 25 deletions packages/shorebird_cli/lib/src/extensions/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,6 @@ extension NullOrEmpty on String? {
bool get isNullOrEmpty => this == null || this!.isEmpty;
}

/// Extension on [String] to provide Ansi escape code helpers.
extension AnsiEscapes on String {
/// Removes ANSI escape codes (usually the result of a lightCyan.wrap or
/// similar) from this string. Used to clean up
String removeAnsiEscapes() {
// Convert ansi escape links to markdown links. This assumes the string is
// well-formed and that there are no nested links.
//
// Links are in the form of '\x1B]8;;<uri>\x1B\\<text>\x1B]8;;\x1B\\'
//
// See https://github.com/felangel/mason/blob/38a525b0607d8723df3b5b3fcc2c087efd9e1c93/packages/mason_logger/lib/src/link.dart
final hyperlinkRegex = RegExp(
r'\x1B\]8;;(.+)\x1B\\(.+)\x1B\]8;;\x1B\\',
);
final ansiEscapeRegex = RegExp(r'\x1B\[[0-?]*[ -/]*[@-~]');

// Replace all links with markdown links
// Remove all other ANSI escape codes
return replaceAllMapped(
hyperlinkRegex,
(match) => '[${match.group(2)!}](${match.group(1)!})',
).replaceAll(ansiEscapeRegex, '');
}
}

/// Extension on [String] to provide an `isUpperCase` getter.
extension IsUpperCase on String {
/// Returns `true` if this string is in uppercase.
Expand Down
3 changes: 1 addition & 2 deletions packages/shorebird_cli/lib/src/logging/shorebird_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:scoped_deps/scoped_deps.dart';
import 'package:shorebird_cli/src/extensions/string.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';

/// A reference to a [Logger] instance.
Expand Down Expand Up @@ -61,7 +60,7 @@ void writeToLogFile(Object? message, {required File logFile}) {
}

final timestampString = DateTime.now().toIso8601String();
final messageString = message.toString().removeAnsiEscapes();
final messageString = message.toString();
logFile.writeAsStringSync(
'$timestampString $messageString\n',
mode: FileMode.append,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ class MacosNetworkEntitlementValidator extends Validator {
String get description => 'macOS app has Outgoing Connections entitlement';

@override
bool canRunInCurrentContext() =>
_macosDirectory != null && _macosDirectory!.existsSync();
bool canRunInCurrentContext() => _macosDirectory?.existsSync() ?? false;

@override
String? get incorrectContextMessage => '''
The ${_macosDirectory?.path ?? 'macos'} directory does not exist.
The command you are running must be run within a Flutter app project that supports the macOS platform.''';

@override
Future<List<ValidationIssue>> validate() async {
Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_cli/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/shorebird_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shorebird_cli
description: Command-line tool to interact with Shorebird's services.
version: 1.6.3
version: 1.6.4
repository: https://github.com/shorebirdtech/shorebird

publish_to: none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,70 @@ void main() {

verify(
() => logger.warn(
'''No releases found for app $appId. You need to make first a release before you can create a patch.''',
'''No ${releasePlatform.displayName} releases found for app $appId. You must first create a release before you can create a patch.''',
),
).called(1);
});
});

group('when prompting for releases and multiple exist', () {
setUp(() {
when(
() => codePushClientWrapper.getReleases(appId: any(named: 'appId')),
).thenAnswer(
(_) async => [
Release(
id: 0,
appId: appId,
version: releaseVersion,
flutterRevision: flutterRevision,
flutterVersion: flutterVersion,
displayName: releaseVersion,
platformStatuses: {
releasePlatform: ReleaseStatus.active,
},
createdAt: DateTime(2023),
updatedAt: DateTime(2023),
),
Release(
id: 1,
appId: appId,
version: releaseVersion,
flutterRevision: flutterRevision,
flutterVersion: flutterVersion,
displayName: '2.0.0+1',
platformStatuses: {
ReleasePlatform.macos: ReleaseStatus.active,
ReleasePlatform.windows: ReleaseStatus.active,
},
createdAt: DateTime(2023),
updatedAt: DateTime(2023),
),
],
);
});

test(
'only lists and uses releases '
'for the specified platform', () async {
await expectLater(runWithOverrides(command.run), completes);
final captured = verify(
() => logger.chooseOne<Release>(
any(),
choices: captureAny(named: 'choices'),
display: any(named: 'display'),
),
).captured.single as List<Release>;

expect(captured.length, equals(1));
expect(captured.first.version, equals(releaseVersion));

verify(
() => patcher.buildPatchArtifact(releaseVersion: releaseVersion),
).called(1);
});
});

group('when running on CI', () {
setUp(() {
when(() => shorebirdEnv.canAcceptUserInput).thenReturn(false);
Expand Down
16 changes: 0 additions & 16 deletions packages/shorebird_cli/test/src/extensions/string_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/extensions/string.dart';
import 'package:test/test.dart';

Expand All @@ -23,21 +22,6 @@ void main() {
});
});

group('AnsiEscapes', () {
test('removes ansi escape codes from string', () {
expect(
styleUnderlined.wrap(
'''This ${red.wrap('is')} ${styleBlink.wrap('a')} ${lightCyan.wrap('test')}''',
)!.removeAnsiEscapes(),
equals('This is a test'),
);
});

test('returns string unchanged if no ansi escape codes are present', () {
expect('test'.removeAnsiEscapes(), equals('test'));
});
});

group('IsUpperCase', () {
test('returns true if a string contains only uppercase characters', () {
expect('TEST'.isUpperCase(), isTrue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ void main() {
runWithOverrides(() => validator.canRunInCurrentContext()),
isFalse,
);
expect(
runWithOverrides(() => validator.incorrectContextMessage),
contains(
'''The command you are running must be run within a Flutter app project that supports the macOS platform.''',
),
);
});
});
});
Expand Down

0 comments on commit 902ce8e

Please sign in to comment.