Skip to content

Commit

Permalink
Update the output for the trebuchet tool (#299)
Browse files Browse the repository at this point in the history
Update the output for the trebuchet tool:
- use bold for commands in the stdout output; indent subprocess putput
by two spaces
- interpolate the target repo name into the post-PR steps

---

- [x] I’ve reviewed the contributor guide and applied the relevant
portions to this PR.

<details>
  <summary>Contribution guidelines:</summary><br>

- See our [contributor
guide](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md)
for general expectations for PRs.
- Larger or significant changes should be discussed in an issue before
creating a PR.
- Contributions to our repos should follow the [Dart style
guide](https://dart.dev/guides/language/effective-dart) and use `dart
format`.
- Most changes should add an entry to the changelog and may need to [rev
the pubspec package
version](https://github.com/dart-lang/sdk/blob/main/docs/External-Package-Maintenance.md#making-a-change).
- Changes to packages require [corresponding
tests](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md#Testing).

Note that many Dart repos have a weekly cadence for reviewing PRs -
please allow for some latency before initial review feedback.
</details>
  • Loading branch information
devoncarew authored Sep 26, 2024
1 parent 70521d7 commit 0ea4f59
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
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');

0 comments on commit 0ea4f59

Please sign in to comment.