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

Migrate to null safety and update to latest dependencies #102

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion bin/generate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main(List<String> args) async {
}

await Chain.capture(() async {
await writeHomebrewInfo(channel, revision, file.parent.path);
await writeHomebrewInfo(channel, revision, file.parent.path, false);
}, onError: (error, chain) {
print(error);
print(chain.terse);
Expand Down
49 changes: 25 additions & 24 deletions bin/update_homebrew.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import 'package:stack_trace/stack_trace.dart';
import 'package:update_homebrew/update_homebrew.dart';

void main(List<String> args) async {
await Chain.capture(() async {
updateHomeBrew(args);
}, onError: (error, chain) {
print(error);
print(chain.terse);
exitCode = 1;
});
}

Future<void> updateHomeBrew(List<String> args) async {
final parser = ArgParser()
..addFlag('dry-run', abbr: 'n')
..addOption('revision', abbr: 'r')
Expand All @@ -22,33 +32,24 @@ void main(List<String> args) async {
print(
"Usage: update_homebrew.dart -r version -c channel [-k ssh_key] [-n]\n"
" ssh_key should allow pushes to $githubRepo on github");
exitCode = 1;
exitCode = 64;
Copy link
Contributor

@sortie sortie Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to discern this from the above exit? Are you trying to handle one of them? The above one seems the most interesting case to catch, maybe it should be the 64 one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pub.dev/documentation/io/latest/io/ExitCode/usage-constant.html

Seemed like an appropriate value for this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo hoo!

return;
}

Map<String, String> gitEnvironment;

final key = options['key'] as String;
final repository = Directory.current.path;
final key = options['key'] as String?;
final gitEnvironment = <String, String>{};
if (key != null) {
final sshWrapper = Platform.script.resolve('ssh_with_key').toFilePath();
gitEnvironment = {'GIT_SSH': sshWrapper, 'SSH_KEY_PATH': key};
final sshWrapper =
Directory.current.uri.resolve('ssh_with_key').toFilePath();
gitEnvironment['GIT_SSH'] = sshWrapper;
gitEnvironment['SSH_KEY_PATH'] = key;
}

await Chain.capture(() async {
var repository = Platform.script.resolve('..').toFilePath();
await writeHomebrewInfo(channel, revision, repository);
await runGit(
['commit', '-a', '-m', 'Updated $channel branch to revision $revision'],
repository,
gitEnvironment);
if (dryRun) {
await runGit(['diff', 'origin/master'], repository, gitEnvironment);
} else {
await runGit(['push'], repository, gitEnvironment);
}
}, onError: (error, chain) {
print(error);
print(chain.terse);
exitCode = 1;
});
await writeHomebrewInfo(channel, revision, repository, dryRun);
await runGit(
['commit', '-a', '-m', 'Updated $channel branch to revision $revision'],
repository,
gitEnvironment,
dryRun);
await runGit(['push'], repository, gitEnvironment, dryRun);
}
4 changes: 2 additions & 2 deletions lib/src/impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Future<String> _getHash256(
var api = storage.StorageApi(client);
var url = 'channels/$channel/release/$version/sdk/$download.sha256sum';
var media = await api.objects.get('dart-archive', url,
downloadOptions: DownloadOptions.FullMedia) as Media;
downloadOptions: DownloadOptions.fullMedia) as Media;
var hashLine = await ascii.decodeStream(media.stream);
return RegExp('[0-9a-fA-F]*').stringMatch(hashLine);
return RegExp('[0-9a-fA-F]*').stringMatch(hashLine)!;
} finally {
client.close();
}
Expand Down
13 changes: 10 additions & 3 deletions lib/update_homebrew.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@ const formulaByChannel = {
Iterable<String> get supportedChannels => formulaByChannel.keys;

Future<void> writeHomebrewInfo(
String channel, String version, String repository) async {
String channel, String version, String repository, bool dryRun) async {
var formula = File(p.join(repository, formulaByChannel[channel]));
var contents = await formula.readAsString();
var hashes = await _getHashes(channel, version);
var updated = updateFormula(channel, contents, version, hashes);
await formula.writeAsString(updated, flush: true);
if (dryRun) {
print(updated);
} else {
await formula.writeAsString(updated, flush: true);
}
}

Future<void> runGit(List<String> args, String repository,
Map<String, String> gitEnvironment) async {
Map<String, String> gitEnvironment, bool dryRun) async {
if (dryRun) {
args = [args[0], '--dry-run', ...args.skip(1)];
}
print("git ${args.join(' ')}");

var result = await Process.run('git', args,
Expand Down
70 changes: 35 additions & 35 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ packages:
name: _discoveryapis_commons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.9"
version: "1.0.2"
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "22.0.0"
version: "30.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.2"
version: "2.7.0"
args:
dependency: "direct main"
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
version: "2.3.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.7.0"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
version: "0.3.5"
collection:
dependency: transitive
description:
Expand All @@ -77,7 +77,7 @@ packages:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.2"
version: "1.0.3"
crypto:
dependency: transitive
description:
Expand All @@ -92,27 +92,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.2"
googleapis:
dependency: "direct main"
description:
name: googleapis
url: "https://pub.dartlang.org"
source: hosted
version: "0.51.1"
version: "6.0.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.3+17"
version: "0.13.4"
http_multi_server:
dependency: transitive
description:
Expand All @@ -126,7 +133,7 @@ packages:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
version: "4.0.0"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -154,56 +161,49 @@ packages:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.0.2"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
version: "1.7.0"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.1"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.13"
version: "2.0.1"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.2"
path:
dependency: "direct main"
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.1"
pool:
dependency: transitive
description:
Expand All @@ -217,35 +217,35 @@ packages:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.9"
version: "1.2.0"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "3.0.0"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.9+2"
version: "1.1.0"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4+1"
version: "1.0.1"
source_map_stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -301,21 +301,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.5"
version: "1.19.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.4.6"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.15"
version: "0.4.7"
typed_data:
dependency: transitive
description:
Expand All @@ -329,14 +329,14 @@ packages:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "6.2.0"
version: "7.3.0"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.1"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -359,4 +359,4 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: update_homebrew

publish_to: none
environment:
sdk: '>=2.9.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dependencies:
_discoveryapis_commons: ^0.1.3+1
args: ^1.5.0
googleapis: ^0.51.0
http: ^0.11.1+1
_discoveryapis_commons: ^1.0.2
args: ^2.3.0
googleapis: ^6.0.0
http: ^0.13.4
path: ^1.4.1
stack_trace: ^1.3.2
test: ^1.16.5
Expand Down
Loading