Skip to content

Commit 68026c3

Browse files
authored
Migrate to null safety and update to latest dependencies (#102)
* Reland #101. * Fix gitEnvironment LateInitializationError. * Rework `--dry-run` to not touch the checkout. * Add very basic testing of `bin/update_homebrew.dart` (dry run doesn't throw).
1 parent 3596d24 commit 68026c3

7 files changed

+84
-72
lines changed

bin/generate.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void main(List<String> args) async {
4545
}
4646

4747
await Chain.capture(() async {
48-
await writeHomebrewInfo(channel, revision, file.parent.path);
48+
await writeHomebrewInfo(channel, revision, file.parent.path, false);
4949
}, onError: (error, chain) {
5050
print(error);
5151
print(chain.terse);

bin/update_homebrew.dart

+25-24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import 'package:stack_trace/stack_trace.dart';
99
import 'package:update_homebrew/update_homebrew.dart';
1010

1111
void main(List<String> args) async {
12+
await Chain.capture(() async {
13+
updateHomeBrew(args);
14+
}, onError: (error, chain) {
15+
print(error);
16+
print(chain.terse);
17+
exitCode = 1;
18+
});
19+
}
20+
21+
Future<void> updateHomeBrew(List<String> args) async {
1222
final parser = ArgParser()
1323
..addFlag('dry-run', abbr: 'n')
1424
..addOption('revision', abbr: 'r')
@@ -22,33 +32,24 @@ void main(List<String> args) async {
2232
print(
2333
"Usage: update_homebrew.dart -r version -c channel [-k ssh_key] [-n]\n"
2434
" ssh_key should allow pushes to $githubRepo on github");
25-
exitCode = 1;
35+
exitCode = 64;
2636
return;
2737
}
2838

29-
Map<String, String> gitEnvironment;
30-
31-
final key = options['key'] as String;
39+
final repository = Directory.current.path;
40+
final key = options['key'] as String?;
41+
final gitEnvironment = <String, String>{};
3242
if (key != null) {
33-
final sshWrapper = Platform.script.resolve('ssh_with_key').toFilePath();
34-
gitEnvironment = {'GIT_SSH': sshWrapper, 'SSH_KEY_PATH': key};
43+
final sshWrapper =
44+
Directory.current.uri.resolve('ssh_with_key').toFilePath();
45+
gitEnvironment['GIT_SSH'] = sshWrapper;
46+
gitEnvironment['SSH_KEY_PATH'] = key;
3547
}
36-
37-
await Chain.capture(() async {
38-
var repository = Platform.script.resolve('..').toFilePath();
39-
await writeHomebrewInfo(channel, revision, repository);
40-
await runGit(
41-
['commit', '-a', '-m', 'Updated $channel branch to revision $revision'],
42-
repository,
43-
gitEnvironment);
44-
if (dryRun) {
45-
await runGit(['diff', 'origin/master'], repository, gitEnvironment);
46-
} else {
47-
await runGit(['push'], repository, gitEnvironment);
48-
}
49-
}, onError: (error, chain) {
50-
print(error);
51-
print(chain.terse);
52-
exitCode = 1;
53-
});
48+
await writeHomebrewInfo(channel, revision, repository, dryRun);
49+
await runGit(
50+
['commit', '-a', '-m', 'Updated $channel branch to revision $revision'],
51+
repository,
52+
gitEnvironment,
53+
dryRun);
54+
await runGit(['push'], repository, gitEnvironment, dryRun);
5455
}

lib/src/impl.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Future<String> _getHash256(
2020
var api = storage.StorageApi(client);
2121
var url = 'channels/$channel/release/$version/sdk/$download.sha256sum';
2222
var media = await api.objects.get('dart-archive', url,
23-
downloadOptions: DownloadOptions.FullMedia) as Media;
23+
downloadOptions: DownloadOptions.fullMedia) as Media;
2424
var hashLine = await ascii.decodeStream(media.stream);
25-
return RegExp('[0-9a-fA-F]*').stringMatch(hashLine);
25+
return RegExp('[0-9a-fA-F]*').stringMatch(hashLine)!;
2626
} finally {
2727
client.close();
2828
}

lib/update_homebrew.dart

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,23 @@ const formulaByChannel = {
2626
Iterable<String> get supportedChannels => formulaByChannel.keys;
2727

2828
Future<void> writeHomebrewInfo(
29-
String channel, String version, String repository) async {
29+
String channel, String version, String repository, bool dryRun) async {
3030
var formula = File(p.join(repository, formulaByChannel[channel]));
3131
var contents = await formula.readAsString();
3232
var hashes = await _getHashes(channel, version);
3333
var updated = updateFormula(channel, contents, version, hashes);
34-
await formula.writeAsString(updated, flush: true);
34+
if (dryRun) {
35+
print(updated);
36+
} else {
37+
await formula.writeAsString(updated, flush: true);
38+
}
3539
}
3640

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

4148
var result = await Process.run('git', args,

pubspec.lock

+35-35
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ packages:
77
name: _discoveryapis_commons
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "0.1.9"
10+
version: "1.0.2"
1111
_fe_analyzer_shared:
1212
dependency: transitive
1313
description:
1414
name: _fe_analyzer_shared
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "22.0.0"
17+
version: "30.0.0"
1818
analyzer:
1919
dependency: transitive
2020
description:
2121
name: analyzer
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.7.2"
24+
version: "2.7.0"
2525
args:
2626
dependency: "direct main"
2727
description:
2828
name: args
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.6.0"
31+
version: "2.3.0"
3232
async:
3333
dependency: transitive
3434
description:
3535
name: async
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "2.7.0"
38+
version: "2.8.2"
3939
boolean_selector:
4040
dependency: transitive
4141
description:
@@ -56,7 +56,7 @@ packages:
5656
name: cli_util
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "0.3.3"
59+
version: "0.3.5"
6060
collection:
6161
dependency: transitive
6262
description:
@@ -77,7 +77,7 @@ packages:
7777
name: coverage
7878
url: "https://pub.dartlang.org"
7979
source: hosted
80-
version: "0.15.2"
80+
version: "1.0.3"
8181
crypto:
8282
dependency: transitive
8383
description:
@@ -92,27 +92,34 @@ packages:
9292
url: "https://pub.dartlang.org"
9393
source: hosted
9494
version: "6.1.2"
95+
frontend_server_client:
96+
dependency: transitive
97+
description:
98+
name: frontend_server_client
99+
url: "https://pub.dartlang.org"
100+
source: hosted
101+
version: "2.1.2"
95102
glob:
96103
dependency: transitive
97104
description:
98105
name: glob
99106
url: "https://pub.dartlang.org"
100107
source: hosted
101-
version: "2.0.1"
108+
version: "2.0.2"
102109
googleapis:
103110
dependency: "direct main"
104111
description:
105112
name: googleapis
106113
url: "https://pub.dartlang.org"
107114
source: hosted
108-
version: "0.51.1"
115+
version: "6.0.0"
109116
http:
110117
dependency: "direct main"
111118
description:
112119
name: http
113120
url: "https://pub.dartlang.org"
114121
source: hosted
115-
version: "0.11.3+17"
122+
version: "0.13.4"
116123
http_multi_server:
117124
dependency: transitive
118125
description:
@@ -126,7 +133,7 @@ packages:
126133
name: http_parser
127134
url: "https://pub.dartlang.org"
128135
source: hosted
129-
version: "3.1.4"
136+
version: "4.0.0"
130137
io:
131138
dependency: transitive
132139
description:
@@ -154,56 +161,49 @@ packages:
154161
name: logging
155162
url: "https://pub.dartlang.org"
156163
source: hosted
157-
version: "1.0.1"
164+
version: "1.0.2"
158165
matcher:
159166
dependency: transitive
160167
description:
161168
name: matcher
162169
url: "https://pub.dartlang.org"
163170
source: hosted
164-
version: "0.12.10"
171+
version: "0.12.11"
165172
meta:
166173
dependency: transitive
167174
description:
168175
name: meta
169176
url: "https://pub.dartlang.org"
170177
source: hosted
171-
version: "1.4.0"
178+
version: "1.7.0"
172179
mime:
173180
dependency: transitive
174181
description:
175182
name: mime
176183
url: "https://pub.dartlang.org"
177184
source: hosted
178-
version: "1.0.0"
185+
version: "1.0.1"
179186
node_preamble:
180187
dependency: transitive
181188
description:
182189
name: node_preamble
183190
url: "https://pub.dartlang.org"
184191
source: hosted
185-
version: "1.4.13"
192+
version: "2.0.1"
186193
package_config:
187194
dependency: transitive
188195
description:
189196
name: package_config
190197
url: "https://pub.dartlang.org"
191198
source: hosted
192-
version: "2.0.0"
199+
version: "2.0.2"
193200
path:
194201
dependency: "direct main"
195202
description:
196203
name: path
197204
url: "https://pub.dartlang.org"
198205
source: hosted
199206
version: "1.8.0"
200-
pedantic:
201-
dependency: transitive
202-
description:
203-
name: pedantic
204-
url: "https://pub.dartlang.org"
205-
source: hosted
206-
version: "1.11.1"
207207
pool:
208208
dependency: transitive
209209
description:
@@ -217,35 +217,35 @@ packages:
217217
name: pub_semver
218218
url: "https://pub.dartlang.org"
219219
source: hosted
220-
version: "2.0.0"
220+
version: "2.1.0"
221221
shelf:
222222
dependency: transitive
223223
description:
224224
name: shelf
225225
url: "https://pub.dartlang.org"
226226
source: hosted
227-
version: "0.7.9"
227+
version: "1.2.0"
228228
shelf_packages_handler:
229229
dependency: transitive
230230
description:
231231
name: shelf_packages_handler
232232
url: "https://pub.dartlang.org"
233233
source: hosted
234-
version: "2.0.1"
234+
version: "3.0.0"
235235
shelf_static:
236236
dependency: transitive
237237
description:
238238
name: shelf_static
239239
url: "https://pub.dartlang.org"
240240
source: hosted
241-
version: "0.2.9+2"
241+
version: "1.1.0"
242242
shelf_web_socket:
243243
dependency: transitive
244244
description:
245245
name: shelf_web_socket
246246
url: "https://pub.dartlang.org"
247247
source: hosted
248-
version: "0.2.4+1"
248+
version: "1.0.1"
249249
source_map_stack_trace:
250250
dependency: transitive
251251
description:
@@ -301,21 +301,21 @@ packages:
301301
name: test
302302
url: "https://pub.dartlang.org"
303303
source: hosted
304-
version: "1.16.5"
304+
version: "1.19.1"
305305
test_api:
306306
dependency: transitive
307307
description:
308308
name: test_api
309309
url: "https://pub.dartlang.org"
310310
source: hosted
311-
version: "0.2.19"
311+
version: "0.4.6"
312312
test_core:
313313
dependency: transitive
314314
description:
315315
name: test_core
316316
url: "https://pub.dartlang.org"
317317
source: hosted
318-
version: "0.3.15"
318+
version: "0.4.7"
319319
typed_data:
320320
dependency: transitive
321321
description:
@@ -329,14 +329,14 @@ packages:
329329
name: vm_service
330330
url: "https://pub.dartlang.org"
331331
source: hosted
332-
version: "6.2.0"
332+
version: "7.3.0"
333333
watcher:
334334
dependency: transitive
335335
description:
336336
name: watcher
337337
url: "https://pub.dartlang.org"
338338
source: hosted
339-
version: "1.0.0"
339+
version: "1.0.1"
340340
web_socket_channel:
341341
dependency: transitive
342342
description:
@@ -359,4 +359,4 @@ packages:
359359
source: hosted
360360
version: "3.1.0"
361361
sdks:
362-
dart: ">=2.12.0 <3.0.0"
362+
dart: ">=2.14.0 <3.0.0"

pubspec.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: update_homebrew
22

33
publish_to: none
44
environment:
5-
sdk: '>=2.9.0 <3.0.0'
5+
sdk: '>=2.12.0 <3.0.0'
66

77
dependencies:
8-
_discoveryapis_commons: ^0.1.3+1
9-
args: ^1.5.0
10-
googleapis: ^0.51.0
11-
http: ^0.11.1+1
8+
_discoveryapis_commons: ^1.0.2
9+
args: ^2.3.0
10+
googleapis: ^6.0.0
11+
http: ^0.13.4
1212
path: ^1.4.1
1313
stack_trace: ^1.3.2
1414
test: ^1.16.5

0 commit comments

Comments
 (0)