-
Notifications
You must be signed in to change notification settings - Fork 8
Add package:trebuchet to repo.
#289
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5be80a4
Add `package:trebuchet` to repo.
mosuem d9de1ab
Add license
mosuem f2c0827
Delete temp dir
mosuem 721d927
Refactor
mosuem e95aa33
Also delete subdirs
mosuem 620ff49
Abort on non-zero exit code
mosuem a52e3d3
Fix working dir
mosuem a4d84c1
Add tag push command
mosuem 0b5573b
Update README.md
mosuem e9ef9c7
Update pkgs/trebuchet/README.md
mosuem 2f0bc3f
Add python check
mosuem 90c85e4
Use .option
mosuem dffa983
Add continuation symbols
mosuem 5dfe4e5
Ask to push
mosuem 1a68695
Add newlien
mosuem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,7 @@ | ||
| Run | ||
mosuem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| dart run bin/trebuchet.dart --input-name coverage --branch-name master --input-path ~/projects/coverage/ --target-path ~/projects/tools/ --git-filter-repo ~/tools/git-filter-repo | ||
mosuem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| This basically executes the instructions at https://github.com/dart-lang/ecosystem/wiki/Merging-existing-repos-into-a-monorepo | ||
This file contains hidden or 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 @@ | ||
| include: package:dart_flutter_team_lints/analysis_options.yaml | ||
|
|
||
| linter: | ||
| rules: | ||
| - prefer_final_locals |
This file contains hidden or 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,212 @@ | ||
| // Copyright (c) 2024, 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:path/path.dart' as p; | ||
|
|
||
| Future<void> main(List<String> arguments) async { | ||
| final argParser = ArgParser() | ||
| ..addOption( | ||
| 'input-name', | ||
| help: 'Name of the package which should be transferred to a mono-repo', | ||
| ) | ||
| ..addOption( | ||
| 'input-path', | ||
| help: 'Path to the package which should be transferred to a mono-repo', | ||
| ) | ||
| ..addOption( | ||
| 'target-path', | ||
| help: 'Path to the mono-repo', | ||
| ) | ||
| ..addOption( | ||
| 'branch-name', | ||
| help: 'The name of the main branch on the input repo', | ||
| defaultsTo: 'main', | ||
| ) | ||
| ..addOption( | ||
| 'git-filter-repo', | ||
| help: 'Path to the git-filter-repo tool', | ||
| ) | ||
| ..addFlag( | ||
| 'push', | ||
| help: 'Whether to push the branch to remote', | ||
| defaultsTo: true, | ||
| ) | ||
| ..addFlag( | ||
| 'help', | ||
| abbr: 'h', | ||
| help: 'Prints usage info', | ||
| negatable: false, | ||
| ) | ||
| ..addFlag( | ||
| 'dry-run', | ||
| help: 'Do not actually execute any of the steps', | ||
| defaultsTo: false, | ||
| ); | ||
|
|
||
| String input; | ||
| String inputPath; | ||
| String targetPath; | ||
| String branchName; | ||
| String gitFilterRepo; | ||
| bool push; | ||
| bool dryRun; | ||
| try { | ||
| final parsed = argParser.parse(arguments); | ||
| if (parsed.flag('help')) { | ||
| print(argParser.usage); | ||
| exit(0); | ||
| } | ||
|
|
||
| input = parsed['input-name'] as String; | ||
mosuem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| inputPath = parsed['input-path'] as String; | ||
| targetPath = parsed['target-path'] as String; | ||
| branchName = parsed['branch-name'] as String; | ||
| gitFilterRepo = parsed['git-filter-repo'] as String; | ||
| push = parsed.flag('push'); | ||
| dryRun = parsed.flag('dry-run'); | ||
| } catch (e) { | ||
| print(e); | ||
| print(''); | ||
| print(argParser.usage); | ||
| exit(1); | ||
| } | ||
|
|
||
| final trebuchet = Trebuchet( | ||
| input: input, | ||
| inputPath: inputPath, | ||
| targetPath: targetPath, | ||
| branchName: branchName, | ||
| gitFilterRepo: gitFilterRepo, | ||
| push: push, | ||
| dryRun: dryRun, | ||
| ); | ||
|
|
||
| await trebuchet.hurl(); | ||
| } | ||
|
|
||
| class Trebuchet { | ||
| final String input; | ||
| final String inputPath; | ||
| final String targetPath; | ||
| final String branchName; | ||
| final String gitFilterRepo; | ||
| final bool push; | ||
| final bool dryRun; | ||
|
|
||
| Trebuchet({ | ||
| required this.input, | ||
| required this.inputPath, | ||
| required this.targetPath, | ||
| required this.branchName, | ||
| required this.gitFilterRepo, | ||
| required this.push, | ||
| required this.dryRun, | ||
| }); | ||
|
|
||
| Future<void> hurl() async { | ||
| print('Rename to `pkgs/`'); | ||
| await filterRepo(['--path-rename', ':pkgs/$input/']); | ||
|
|
||
| print('Prefix tags'); | ||
| await filterRepo(['--tag-rename', ':$input-']); | ||
|
|
||
| print('Replace issue references in commit messages'); | ||
| await inTempDir((tempDirectory) async { | ||
| final regexFile = File(p.join(tempDirectory.path, 'expressions.txt')); | ||
| await regexFile.create(); | ||
| await regexFile.writeAsString('regex:#(\\d)==>dart-lang/$input#\\1'); | ||
| await filterRepo(['--replace-message', regexFile.path]); | ||
| }); | ||
|
|
||
| print('Create branch at target'); | ||
| await runProcess('git', ['checkout', '-b', 'merge-$input-package']); | ||
|
|
||
| print('Add a remote for the local clone of the moving package'); | ||
| await runProcess( | ||
| 'git', | ||
| ['remote', 'add', '${input}_package', inputPath], | ||
| ); | ||
| await runProcess('git', ['fetch', '${input}_package']); | ||
|
|
||
| print('Merge branch into monorepo'); | ||
| await runProcess( | ||
| 'git', | ||
| [ | ||
| 'merge', | ||
| '--allow-unrelated-histories', | ||
| '${input}_package/$branchName', | ||
| '-m', | ||
| 'Merge package:$input into shared tool repository' | ||
| ], | ||
| ); | ||
|
|
||
| if (push) { | ||
| print('Push to remote'); | ||
| await runProcess( | ||
| 'git', | ||
| ['push', '--set-upstream', 'origin', 'merge-$input-package'], | ||
| ); | ||
| } | ||
|
|
||
| print('DONE!'); | ||
| print(''' | ||
| Steps left to do: | ||
| - Move and fix workflow files | ||
| ${push ? '' : '- 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. | ||
| - 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/. | ||
| '''); | ||
| } | ||
|
|
||
| Future<void> runProcess( | ||
| String executable, | ||
| List<String> arguments, { | ||
| bool inTarget = true, | ||
| }) async { | ||
| final workingDirectory = inTarget ? targetPath : inputPath; | ||
| print('----------'); | ||
| print('Running `$executable $arguments` in $workingDirectory'); | ||
| if (!dryRun) { | ||
| 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); | ||
| } | ||
| if (processResult.exitCode != 0) { | ||
| throw ProcessException(executable, arguments); | ||
| } | ||
| } else { | ||
| print('Not running, as --dry-run is set.'); | ||
| } | ||
| print('=========='); | ||
| } | ||
|
|
||
| Future<void> filterRepo(List<String> args) async { | ||
| await runProcess( | ||
| 'python3', | ||
mosuem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [p.relative(gitFilterRepo, from: inputPath), ...args], | ||
| inTarget: false, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Future<void> inTempDir(Future<void> Function(Directory temp) f) async { | ||
| final tempDirectory = await Directory.systemTemp.createTemp(); | ||
| await f(tempDirectory); | ||
| await tempDirectory.delete(recursive: true); | ||
| } | ||
This file contains hidden or 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,16 @@ | ||
| name: trebuchet | ||
| description: A tool for hurling packages into monorepos. | ||
|
|
||
| publish_to: none | ||
|
|
||
| environment: | ||
| sdk: ^3.3.0 | ||
|
|
||
| dependencies: | ||
| args: ^2.5.0 | ||
| path: ^1.9.0 | ||
|
|
||
| dev_dependencies: | ||
| dart_flutter_team_lints: ^3.2.0 | ||
| lints: ^4.0.0 | ||
| test: ^1.24.0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.