forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add update packages roller (flutter#100982)
- Loading branch information
1 parent
0dd0c2e
commit a30012b
Showing
12 changed files
with
760 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2014 The Flutter Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
set -euo pipefail | ||
|
||
# Needed because if it is set, cd may print the path it changed to. | ||
unset CDPATH | ||
|
||
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one | ||
# link at a time, and then cds into the link destination and find out where it | ||
# ends up. | ||
# | ||
# The returned filesystem path must be a format usable by Dart's URI parser, | ||
# since the Dart command line tool treats its argument as a file URI, not a | ||
# filename. For instance, multiple consecutive slashes should be reduced to a | ||
# single slash, since double-slashes indicate a URI "authority", and these are | ||
# supposed to be filenames. There is an edge case where this will return | ||
# multiple slashes: when the input resolves to the root directory. However, if | ||
# that were the case, we wouldn't be running this shell, so we don't do anything | ||
# about it. | ||
# | ||
# The function is enclosed in a subshell to avoid changing the working directory | ||
# of the caller. | ||
function follow_links() ( | ||
cd -P "$(dirname -- "$1")" | ||
file="$PWD/$(basename -- "$1")" | ||
while [[ -h "$file" ]]; do | ||
cd -P "$(dirname -- "$file")" | ||
file="$(readlink -- "$file")" | ||
cd -P "$(dirname -- "$file")" | ||
file="$PWD/$(basename -- "$file")" | ||
done | ||
echo "$file" | ||
) | ||
|
||
PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")" | ||
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" | ||
REPO_DIR="$BIN_DIR/../../.." | ||
DART_BIN="$REPO_DIR/bin/dart" | ||
|
||
# Ensure pub get has been run in the repo before running the conductor | ||
(cd "$REPO_DIR/dev/conductor/core"; "$DART_BIN" pub get 1>&2) | ||
|
||
exec "$DART_BIN" --enable-asserts "$REPO_DIR/dev/conductor/core/bin/roll_packages.dart" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright 2014 The Flutter Authors. 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' as io; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:conductor_core/conductor_core.dart'; | ||
import 'package:conductor_core/packages_autoroller.dart'; | ||
import 'package:file/file.dart'; | ||
import 'package:file/local.dart'; | ||
import 'package:platform/platform.dart'; | ||
import 'package:process/process.dart'; | ||
|
||
const String kTokenOption = 'token'; | ||
const String kGithubClient = 'github-client'; | ||
const String kMirrorRemote = 'mirror-remote'; | ||
const String kUpstreamRemote = 'upstream-remote'; | ||
|
||
Future<void> main(List<String> args) async { | ||
final ArgParser parser = ArgParser(); | ||
parser.addOption( | ||
kTokenOption, | ||
help: 'GitHub access token env variable name.', | ||
defaultsTo: 'GITHUB_TOKEN', | ||
); | ||
parser.addOption( | ||
kGithubClient, | ||
help: 'Path to GitHub CLI client. If not provided, it is assumed `gh` is ' | ||
'present on the PATH.', | ||
); | ||
parser.addOption( | ||
kMirrorRemote, | ||
help: 'The mirror git remote that the feature branch will be pushed to. ' | ||
'Required', | ||
mandatory: true, | ||
); | ||
parser.addOption( | ||
kUpstreamRemote, | ||
help: 'The upstream git remote that the feature branch will be merged to.', | ||
hide: true, | ||
defaultsTo: 'https://github.com/flutter/flutter.git', | ||
); | ||
|
||
final ArgResults results; | ||
try { | ||
results = parser.parse(args); | ||
} on FormatException { | ||
io.stdout.writeln(''' | ||
Usage: | ||
${parser.usage} | ||
'''); | ||
rethrow; | ||
} | ||
|
||
final String mirrorUrl = results[kMirrorRemote]! as String; | ||
final String upstreamUrl = results[kUpstreamRemote]! as String; | ||
const Platform platform = LocalPlatform(); | ||
final String tokenName = results[kTokenOption]! as String; | ||
final String? token = platform.environment[tokenName]; | ||
if (token == null || token.isEmpty) { | ||
throw FormatException( | ||
'Tried to read a GitHub access token from env variable \$$tokenName but it was undefined or empty', | ||
); | ||
} | ||
|
||
final FrameworkRepository framework = FrameworkRepository( | ||
_localCheckouts, | ||
mirrorRemote: Remote.mirror(mirrorUrl), | ||
upstreamRemote: Remote.upstream(upstreamUrl), | ||
); | ||
|
||
await PackageAutoroller( | ||
framework: framework, | ||
githubClient: results[kGithubClient] as String? ?? 'gh', | ||
orgName: _parseOrgName(mirrorUrl), | ||
token: token, | ||
processManager: const LocalProcessManager(), | ||
).roll(); | ||
} | ||
|
||
String _parseOrgName(String remoteUrl) { | ||
final RegExp pattern = RegExp(r'^https:\/\/github\.com\/(.*)\/'); | ||
final RegExpMatch? match = pattern.firstMatch(remoteUrl); | ||
if (match == null) { | ||
throw FormatException( | ||
'Malformed upstream URL "$remoteUrl", should start with "https://github.com/"', | ||
); | ||
} | ||
return match.group(1)!; | ||
} | ||
|
||
Checkouts get _localCheckouts { | ||
const FileSystem fileSystem = LocalFileSystem(); | ||
const ProcessManager processManager = LocalProcessManager(); | ||
const Platform platform = LocalPlatform(); | ||
final Stdio stdio = VerboseStdio( | ||
stdout: io.stdout, | ||
stderr: io.stderr, | ||
stdin: io.stdin, | ||
); | ||
return Checkouts( | ||
fileSystem: fileSystem, | ||
parentDirectory: _localFlutterRoot.parent, | ||
platform: platform, | ||
processManager: processManager, | ||
stdio: stdio, | ||
); | ||
} | ||
|
||
Directory get _localFlutterRoot { | ||
String filePath; | ||
const FileSystem fileSystem = LocalFileSystem(); | ||
const Platform platform = LocalPlatform(); | ||
|
||
filePath = platform.script.toFilePath(); | ||
final String checkoutsDirname = fileSystem.path.normalize( | ||
fileSystem.path.join( | ||
fileSystem.path.dirname(filePath), // flutter/dev/conductor/core/bin | ||
'..', // flutter/dev/conductor/core | ||
'..', // flutter/dev/conductor | ||
'..', // flutter/dev | ||
'..', // flutter | ||
), | ||
); | ||
return fileSystem.directory(checkoutsDirname); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
export 'src/packages_autoroller.dart'; |
Oops, something went wrong.