blob: e61bbdd22eaaf9365f036797924c3310b5d80879 [file] [log] [blame]
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:args/args.dart';
import 'package:stack_trace/stack_trace.dart';
import 'package:update_homebrew/update_homebrew.dart';
main(List<String> args) async {
final parser = new ArgParser()
..addOption('revision', abbr: 'r')
..addOption('channel', abbr: 'c', allowed: ['dev', 'stable'])
..addOption('key', abbr: 'k');
final options = parser.parse(args);
final revision = options['revision'];
final channel = options['channel'];
if ([revision, channel].contains(null)) {
print("Usage: update_homebrew.dart -r revision -c channel [-k ssh_key]\n"
" ssh_key should allow pushes to ${GITHUB_REPO} on github");
exitCode = 1;
Map<String, String> gitEnvironment;
final key = options['key'];
if (key != null) {
final sshWrapper = Platform.script.resolve('ssh_with_key').toFilePath();
gitEnvironment = {'GIT_SSH': sshWrapper, 'SSH_KEY_PATH': key};
await Chain.capture(() async {
var tempDir = await Directory.systemTemp.createTemp('update_homebrew');
try {
var repository = tempDir.path;
await runGit(['clone', '${GITHUB_REPO}.git', '.'],
repository, gitEnvironment);
await writeHomebrewInfo(channel, revision, repository);
await runGit([
'Updated $channel branch to revision $revision'
], repository, gitEnvironment);
await runGit(['push'], repository, gitEnvironment);
} finally {
await tempDir.delete(recursive: true);
}, onError: (error, chain) {
exitCode = 1;