From 0ea4f59fd3fd61d797d01e658ddb9a30c4acf44d Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 26 Sep 2024 09:23:31 -0700 Subject: [PATCH] Update the output for the trebuchet tool (#299) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.
Contribution guidelines:
- 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.
--- pkgs/trebuchet/README.md | 18 +++++----- pkgs/trebuchet/bin/trebuchet.dart | 55 ++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/pkgs/trebuchet/README.md b/pkgs/trebuchet/README.md index f2941eaa..924dc1e1 100644 --- a/pkgs/trebuchet/README.md +++ b/pkgs/trebuchet/README.md @@ -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 \ No newline at end of file +This basically executes the instructions at https://github.com/dart-lang/ecosystem/wiki/Merging-existing-repos-into-a-monorepo diff --git a/pkgs/trebuchet/bin/trebuchet.dart b/pkgs/trebuchet/bin/trebuchet.dart index 02bbfb7f..0345686c 100644 --- a/pkgs/trebuchet/bin/trebuchet.dart +++ b/pkgs/trebuchet/bin/trebuchet.dart @@ -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'; @@ -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' ], ); @@ -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')} '''); } @@ -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 filterRepo(List args) async { @@ -228,3 +238,10 @@ Future inTempDir(Future 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');