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

Update the output for the trebuchet tool #299

Merged
merged 2 commits into from
Sep 26, 2024
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
18 changes: 9 additions & 9 deletions pkgs/trebuchet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

This is a tool to move existing packages into monorepos.

## Running this tool
## Running the tool

```bash
dart run bin/trebuchet.dart \
--input-name coverage \
--branch-name master \
--input-path ~/projects/coverage/ \
--target tools \
--target-path ~/projects/tools/ \
--git-filter-repo ~/tools/git-filter-repo \
--dry-run
--input-name coverage \
--branch-name main \
--input-path ~/projects/coverage/ \
--target labs \
--target-path ~/projects/tools/ \
--git-filter-repo ~/tools/git-filter-repo \
--dry-run
```

This basically executes the instructions at https://github.com/dart-lang/ecosystem/wiki/Merging-existing-repos-into-a-monorepo
This basically executes the instructions at https://github.com/dart-lang/ecosystem/wiki/Merging-existing-repos-into-a-monorepo
55 changes: 36 additions & 19 deletions pkgs/trebuchet/bin/trebuchet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

// ignore_for_file: lines_longer_than_80_chars

import 'dart:io';

import 'package:args/args.dart';
Expand Down Expand Up @@ -148,7 +150,7 @@ class Trebuchet {
'--allow-unrelated-histories',
'${input}_package/$branchName',
'-m',
'Merge package:$input into shared tool repository'
'Merge package:$input into shared $target repository'
],
);

Expand All @@ -162,19 +164,24 @@ class Trebuchet {
);
}

final remainingSteps = [
'Move and fix workflow files',
if (!shouldPush)
'Run `git push --set-upstream origin merge-$input-package` in the monorepo directory',
'Disable squash-only in GitHub settings, and merge with a fast forward merge to the main branch, enable squash-only in GitHub settings.',
"Push tags to github using `git tag --list '$input*' | xargs git push origin`",
'Follow up with a PR adding links to the top-level readme table.',
'Transfer issues by running `dart run pkgs/repo_manage/bin/report.dart transfer-issues --source-repo dart-lang/$input --target-repo dart-lang/$target --add-label package:$input --apply-changes`',
"Add a commit to https://github.com/dart-lang/$input/ with it's readme pointing to the monorepo.",
'Update the auto-publishing settings on pub.dev/packages/$input.',
'Archive https://github.com/dart-lang/$input/.',
];

print('DONE!');
print('''
Steps left to do:

- Move and fix workflow files
${shouldPush ? '' : '- Run `git push --set-upstream origin merge-$input-package` in the monorepo directory'}
- Disable squash-only in GitHub settings, and merge with a fast forward merge to the main branch, enable squash-only in GitHub settings.
- Push tags to github using `git tag --list '$input*' | xargs git push origin`
- Follow up with a PR adding links to the top-level readme table.
- Transfer issues by running `dart run pkgs/repo_manage/bin/report.dart transfer-issues --source-repo dart-lang/$input --target-repo dart-lang/$target --add-label package:$input --apply-changes`
- Add a commit to https://github.com/dart-lang/$input/ with it's readme pointing to the monorepo.
- Update the auto-publishing settings on pub.dev/packages/$input.
- Archive https://github.com/dart-lang/$input/.
${remainingSteps.map((step) => ' - $step').join('\n')}
''');
}

Expand All @@ -191,27 +198,30 @@ ${shouldPush ? '' : '- Run `git push --set-upstream origin merge-$input-package`
bool overrideDryRun = false,
}) async {
final workingDirectory = inTarget ? targetPath : inputPath;
print('----------');
print('Running `$executable $arguments` in $workingDirectory');
print('');
print('${bold('$executable ${arguments.join(' ')}')} '
'${subtle('[$workingDirectory]')}');
if (!dryRun || overrideDryRun) {
final processResult = await Process.run(
executable,
arguments,
workingDirectory: workingDirectory,
);
print('stdout:');
print(processResult.stdout);
if ((processResult.stderr as String).isNotEmpty) {
print('stderr:');
print(processResult.stderr);
final out = processResult.stdout as String;
if (out.isNotEmpty) {
print(indent(out).trimRight());
}
final err = processResult.stderr as String;
if (err.isNotEmpty) {
print(indent(err).trimRight());
}
if (processResult.exitCode != 0) {
throw ProcessException(executable, arguments);
}
} else {
print('Not running, as --dry-run is set.');
print(' (not running; --dry-run is set)');
}
print('==========');
print('');
}

Future<void> filterRepo(List<String> args) async {
Expand All @@ -228,3 +238,10 @@ Future<void> inTempDir(Future<void> Function(Directory temp) f) async {
await f(tempDirectory);
await tempDirectory.delete(recursive: true);
}

String bold(String str) => '\u001b[1m$str\u001b[22m';

String subtle(String str) => '\u001b[2m$str\u001b[22m';

String indent(String str) =>
str.split('\n').map((line) => ' $line').join('\n');
Loading