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 instructions for trebuchet #306

Merged
merged 17 commits into from
Oct 31, 2024
1 change: 1 addition & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Remove the `version` pubspec checks (these largely duplicate the feedback
provided by publishing automation).
- Set minimum SDK version to `3.5.0` because of the `dart_apitool` dependency.

## 0.9.3

Expand Down
77 changes: 32 additions & 45 deletions pkgs/repo_manage/lib/issue_transfer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,46 @@ class TransferIssuesCommand extends ReportCommand {
TransferIssuesCommand()
: super('transfer-issues',
'Bulk transfer issues from one repo to another.') {
argParser.addFlag(
'apply-changes',
negatable: false,
help: 'WARNING: This will transfer the issues. Please preview the changes'
"first by running without '--apply-changes'.",
defaultsTo: false,
);
argParser.addMultiOption(
'issues',
valueHelp: '1,2,3',
help: 'Specifiy the numbers of specific issues to transfer, otherwise'
' transfers all.',
);
argParser.addOption(
'source-repo',
valueHelp: 'repo-org/repo-name',
help: 'The source repository for the issues to be moved from.',
mandatory: true,
);
argParser.addOption(
'target-repo',
valueHelp: 'repo-org/repo-name',
help: 'The target repository name where the issues will be moved to.',
mandatory: true,
);
argParser.addOption(
'add-label',
help: 'Add a label to all transferred issues.',
valueHelp: 'package:foo',
);
argParser
..addFlag(
'apply-changes',
negatable: false,
help:
'WARNING: This will transfer the issues. Please preview the changes'
"first by running without '--apply-changes'.",
defaultsTo: false,
)
..addOption(
'source-repo',
valueHelp: 'repo-org/repo-name',
help: 'The source repository for the issues to be moved from.',
mandatory: true,
)
..addOption(
'target-repo',
valueHelp: 'repo-org/repo-name',
help: 'The target repository name where the issues will be moved to.',
mandatory: true,
)
..addOption(
'add-label',
help: 'Add a label to all transferred issues.',
valueHelp: 'package:foo',
);
}

@override
String get invocation =>
'${super.invocation} --source-repo repo-org/old-repo-name --target-repo repo-org/new-repo-name --add-label pkg:old-repo-name';
'${super.invocation} --source-repo repo-org/old-repo-name --target-repo repo-org/new-repo-name --add-label package:old-repo-name';

@override
Future<int> run() async {
var applyChanges = argResults!['apply-changes'] as bool;
var parsedArgs = argResults!;
var applyChanges = parsedArgs.flag('apply-changes');

var sourceRepo = argResults!['source-repo'] as String;
var targetRepo = argResults!['target-repo'] as String;
var sourceRepo = parsedArgs.option('source-repo')!;
var targetRepo = parsedArgs.option('target-repo')!;

var issueNumberString = argResults!['issues'] as List<String>?;
var issueNumbers = issueNumberString?.map(int.parse).toList();
var labelName = argResults!['add-label'] as String?;

if (!applyChanges) {
Expand All @@ -68,7 +63,6 @@ class TransferIssuesCommand extends ReportCommand {
return await transferAndLabelIssues(
RepositorySlug.full(sourceRepo),
RepositorySlug.full(targetRepo),
issueNumbers,
labelName,
applyChanges,
);
Expand All @@ -77,7 +71,6 @@ class TransferIssuesCommand extends ReportCommand {
Future<int> transferAndLabelIssues(
RepositorySlug sourceRepo,
RepositorySlug targetRepo, [
List<int>? issueNumbers,
String? labelName,
bool applyChanges = false,
]) async {
Expand Down Expand Up @@ -118,10 +111,7 @@ class TransferIssuesCommand extends ReportCommand {
return 0;
}

Future<List<String>> getIssueIds(
RepositorySlug slug, [
List<int>? issueNumbers,
]) async {
Future<List<String>> getIssueIds(RepositorySlug slug) async {
final queryString = '''query {
repository(owner:"${slug.owner}", name:"${slug.name}") {
issues(last:100) {
Expand All @@ -144,9 +134,6 @@ class TransferIssuesCommand extends ReportCommand {
var nodes = issues['nodes'] as List;
return nodes
.map((node) => node as Map)
.where((node) => issueNumbers != null
? issueNumbers.contains(node['number'] as int)
: true)
.map((node) => node['id'] as String)
.toList();
},
Expand Down
3 changes: 2 additions & 1 deletion pkgs/trebuchet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ This is a tool to move existing packages into monorepos.
```bash
dart run bin/trebuchet.dart \
--input-name coverage \
--branch-name main \
--input-branch-name main \
--target-branch-name main \
--input-path ~/projects/coverage/ \
--target tools \
--target-path ~/projects/tools/ \
Expand Down
114 changes: 98 additions & 16 deletions pkgs/trebuchet/bin/trebuchet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:io';

import 'package:args/args.dart';
import 'package:path/path.dart' as p;
import 'package:pubspec_parse/pubspec_parse.dart';

Future<void> main(List<String> arguments) async {
final argParser = ArgParser()
Expand All @@ -28,7 +29,12 @@ Future<void> main(List<String> arguments) async {
help: 'Path to the mono-repo',
)
..addOption(
'branch-name',
'input-branch-name',
help: 'The name of the main branch on the input repo',
defaultsTo: 'main',
)
..addOption(
'target-branch-name',
help: 'The name of the main branch on the input repo',
defaultsTo: 'main',
)
Expand All @@ -52,7 +58,8 @@ Future<void> main(List<String> arguments) async {
String inputPath;
String target;
String targetPath;
String branchName;
String inputBranchName;
String targetBranchName;
String gitFilterRepo;
bool dryRun;
try {
Expand All @@ -66,7 +73,8 @@ Future<void> main(List<String> arguments) async {
inputPath = parsed.option('input-path')!;
target = parsed.option('target')!;
targetPath = parsed.option('target-path')!;
branchName = parsed.option('branch-name')!;
inputBranchName = parsed.option('input-branch-name')!;
targetBranchName = parsed.option('target-branch-name')!;
gitFilterRepo = parsed.option('git-filter-repo')!;
dryRun = parsed.flag('dry-run');
} catch (e) {
Expand All @@ -81,7 +89,8 @@ Future<void> main(List<String> arguments) async {
inputPath: inputPath,
target: target,
targetPath: targetPath,
branchName: branchName,
inputBranchName: inputBranchName,
targetBranchName: targetBranchName,
gitFilterRepo: gitFilterRepo,
dryRun: dryRun,
);
Expand All @@ -94,7 +103,8 @@ class Trebuchet {
final String inputPath;
final String target;
final String targetPath;
final String branchName;
final String inputBranchName;
final String targetBranchName;
final String gitFilterRepo;
final bool dryRun;

Expand All @@ -103,7 +113,8 @@ class Trebuchet {
required this.inputPath,
required this.target,
required this.targetPath,
required this.branchName,
required this.inputBranchName,
required this.targetBranchName,
required this.gitFilterRepo,
required this.dryRun,
});
Expand Down Expand Up @@ -148,12 +159,52 @@ class Trebuchet {
[
'merge',
'--allow-unrelated-histories',
'${input}_package/$branchName',
'${input}_package/$inputBranchName',
'-m',
'Merge package:$input into shared $target repository'
'Merge package:$input into the $target monorepo',
],
);

print('Replace URI in pubspec');
Pubspec? pubspec;
if (!dryRun) {
final pubspecFile =
File(p.join(targetPath, 'pkgs', input, 'pubspec.yaml'));
final pubspecContents = await pubspecFile.readAsString();
pubspec = Pubspec.parse(pubspecContents);
final newPubspecContents = pubspecContents.replaceFirst(
'repository: https://github.com/dart-lang/$input',
'repository: https://github.com/dart-lang/$target/tree/$targetBranchName/pkgs/$input',
);
await pubspecFile.writeAsString(newPubspecContents);
}

print('Add issue template');
final issueTemplateFile =
File(p.join(targetPath, '.github', 'ISSUE_TEMPLATE', '$input.md'));
final issueTemplateContents = '''
---
name: "package:$input"
about: "Create a bug or file a feature request against package:$input."
labels: "package:$input"
---''';
if (!dryRun) {
await issueTemplateFile.create(recursive: true);
await issueTemplateFile.writeAsString(issueTemplateContents);
}

print('Remove CONTRIBUTING.md');
if (!dryRun) {
final contributingFile =
File(p.join(targetPath, 'pkgs', input, 'CONTRIBUTING.md'));
if (await contributingFile.exists()) await contributingFile.delete();
}

print('Committing changes');
await runProcess('git', ['add', '.']);
await runProcess(
'git', ['commit', '-m', 'Add issue template and other fixes']);

final shouldPush = getInput('Push to remote? (y/N)');

if (shouldPush) {
Expand All @@ -165,16 +216,47 @@ class Trebuchet {
}

final remainingSteps = [
'move and fix workflow files',
if (!shouldPush)
'run `git push --set-upstream origin merge-$input-package` in the monorepo directory',
"enable 'Allow merge commits' in GitHub settings; merge the PR with 'Create a merge commit'; disable 'Allow merge commits'",
"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`',
'update the auto-publishing settings on pub.dev/packages/$input',
"add a commit to https://github.com/dart-lang/$input/ with it's readme pointing to the monorepo",
'archive https://github.com/dart-lang/$input/',
'Move and fix workflow files, labeler.yaml, and badges in the README.md',
'Rev the version of the package, so that pub.dev points to the correct site',
'''
Add a line to the changelog:
```
* Move to `dart-lang/$target` monorepo.
```
''',
'''
Add the package to the top-level readme of the monorepo:
```
| [$input](pkgs/$input/) | ${pubspec?.description ?? ''} | [![pub package](https://img.shields.io/pub/v/$input.svg)](https://pub.dev/packages/$input) |
```
''',
"**Important!** Merge the PR with 'Create a merge commit' (enabling then disabling the `Allow merge commits` admin setting)",
'Update the auto-publishing settings on https://pub.dev/packages/$input/admin',
'''
Add the following text to https://github.com/dart-lang/$input/:'

```
> [!IMPORTANT]
> This repo has moved to https://github.com/dart-lang/$target/tree/$targetBranchName/pkgs/$input
```
''',
'Publish using the autopublish workflow',
"""Push tags to GitHub using
```git tag --list '$input*' | xargs git push origin```
""",
'''
Close open PRs in dart-lang/$input with the following message:

```
Closing as the [dart-lang/$input](https://github.com/dart-lang/$input) repository is merged into the [dart-lang/$target](https://github.com/dart-lang/$target) monorepo. Please re-open this PR there!
```
''',
'''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```
''',
'Archive https://github.com/dart-lang/$input/',
];

print('DONE!');
Expand Down
1 change: 1 addition & 0 deletions pkgs/trebuchet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
dependencies:
args: ^2.5.0
path: ^1.9.0
pubspec_parse: ^1.3.0

dev_dependencies:
dart_flutter_team_lints: ^3.2.0
Expand Down