-
Notifications
You must be signed in to change notification settings - Fork 1
feat(rfc_tools): implement semantic RFC number validator CLI #10
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
Open
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2924bb4
feat(rfc_tools): implement semantic RFC number validator CLI
jtmcdole 0cded8f
your rights have been unreserved
jtmcdole f9e4fee
github annotation and validator cleanup
jtmcdole ac7da6c
refactor(rfc_tools): standardize validator exit codes and add RfcFile…
jtmcdole 5d81988
reviewer feedback
jtmcdole 17cdaa4
Revert "reviewer comments:"
jtmcdole 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,85 @@ | ||
| // Copyright 2026 The Flutter Authors. | ||
| // 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:file/local.dart'; | ||
| import 'package:rfc_tools/src/validator.dart'; | ||
|
|
||
| void main(List<String> arguments) async { | ||
| final parser = ArgParser() | ||
| ..addOption( | ||
| 'base-branch', | ||
| help: 'If provided, validate against the base git branch for collisions', | ||
| ) | ||
| ..addFlag( | ||
| 'no-drafts', | ||
| negatable: false, | ||
| help: | ||
| 'Reject any ".0000" draft RFCs (required for Merge Queue and main).', | ||
| ) | ||
| ..addFlag( | ||
| 'github-actions', | ||
| negatable: false, | ||
| help: | ||
| 'Output errors in GitHub Actions annotation format (::error file=...::).', | ||
| ) | ||
| ..addFlag( | ||
| 'help', | ||
| abbr: 'h', | ||
| negatable: false, | ||
| help: 'Show usage instructions.', | ||
| ); | ||
|
|
||
| ArgResults results; | ||
| try { | ||
| results = parser.parse(arguments); | ||
| } catch (e) { | ||
| stderr.writeln('Error parsing arguments: $e\n'); | ||
| stderr.writeln(parser.usage); | ||
| exitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| if (results.flag('help')) { | ||
| stdout.writeln('RFC Semantic Validator - Flutter RFC Repository Tooling\n'); | ||
| stdout.writeln(parser.usage); | ||
| return; | ||
| } | ||
|
|
||
| final baseBranch = results.option('base-branch') ?? ''; | ||
| final noDrafts = results.flag('no-drafts'); | ||
| final githubActions = results.flag('github-actions'); | ||
|
|
||
| const fs = LocalFileSystem(); | ||
| final validator = RfcValidator(fs: fs); | ||
|
|
||
| final (:isSuccess, :errors) = await validator.validate( | ||
| noDrafts: noDrafts, | ||
| checkBase: results.wasParsed('base-branch'), | ||
| baseBranch: baseBranch, | ||
| ); | ||
|
|
||
| if (!isSuccess) { | ||
| stderr.writeln('RFC validation failed with ${errors.length} error(s):\n'); | ||
| for (final error in errors) { | ||
| if (githubActions) { | ||
| stderr.writeln(error.toGithubAnnotation()); | ||
| } else { | ||
| stderr.writeln('[ERROR] $error'); | ||
| } | ||
| } | ||
| exitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| stdout.writeln( | ||
| 'RFC numbers validated cleanly. No collisions or illegal drafts found.', | ||
| ); | ||
| } | ||
|
|
||
| void printHelp(ArgParser parser) { | ||
| stdout.writeln('RFC Semantic Validator - Flutter RFC Repository Tooling\n'); | ||
| stdout.writeln(parser.usage); | ||
| } | ||
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,53 @@ | ||
| // Copyright 2026 The Flutter Authors. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// Interface for objects that can be formatted as GitHub Actions workflow annotations. | ||
| abstract interface class GithubAnnotatable { | ||
| /// Formats this object as a GitHub Actions workflow annotation string. | ||
| String toGithubAnnotation(); | ||
| } | ||
|
|
||
| /// Extension on [String] for GitHub Actions workflow command formatting. | ||
| extension GithubAnnotationExtension on String { | ||
| /// Encodes special characters (`%`, `\r`, `\n`) in this string per GitHub Actions | ||
| /// workflow command specifications so multiline formatting is preserved. | ||
| String toGithubWorkflowValue() { | ||
| return replaceAll( | ||
| '%', | ||
| '%25', | ||
| ).replaceAll('\r', '%0D').replaceAll('\n', '%0A'); | ||
| } | ||
|
|
||
| /// Formats this string message as a GitHub Actions workflow annotation. | ||
| /// | ||
| /// Example: | ||
| /// ```dart | ||
| /// 'File not found'.toGithubAnnotation(filePath: 'rfc/110.0001.md'); | ||
| /// => '::error file=rfc/110.0001.md::File not found' | ||
| /// | ||
| /// 'Syntax error'.toGithubAnnotation( | ||
| /// filePath: 'rfc/110.0001.md', | ||
| /// line: 12, | ||
| /// column: 4, | ||
| /// ); | ||
| /// => '::error file=rfc/110.0001.md,line=12,col=4::Syntax error' | ||
| /// ``` | ||
| String toGithubAnnotation({ | ||
| required String filePath, | ||
| int? line, | ||
| int? column, | ||
| String type = 'error', | ||
| String? title, | ||
| }) { | ||
| final encoded = toGithubWorkflowValue(); | ||
| final params = <String>[ | ||
| 'file=$filePath', | ||
| if (line != null) 'line=$line', | ||
| if (column != null) 'col=$column', | ||
| if (title != null) 'title=$title', | ||
| ].join(','); | ||
|
|
||
| return '::$type $params::$encoded'; | ||
| } | ||
| } |
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,57 @@ | ||
| // Copyright 2026 The Flutter Authors. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:io'; | ||
|
|
||
| /// Signature for running an external process asynchronously. | ||
| typedef ProcessRunner = | ||
| Future<ProcessResult> Function(String executable, List<String> arguments); | ||
|
|
||
| /// Abstract client for interacting with the GitHub API / CLI. | ||
| abstract interface class GitHubClient { | ||
| /// Checks whether a GitHub user exists. | ||
| Future<bool> userExists(String username); | ||
| } | ||
|
|
||
| /// Production implementation using the `gh` CLI. | ||
| class CliGitHubClient implements GitHubClient { | ||
| /// The process runner used to execute external commands. | ||
| final ProcessRunner processRunner; | ||
|
|
||
| const CliGitHubClient({this.processRunner = Process.run}); | ||
|
|
||
| @override | ||
| Future<bool> userExists(String username) async { | ||
| try { | ||
| final result = await processRunner('gh', [ | ||
| 'api', | ||
| 'users/$username', | ||
| '--silent', | ||
| ]); | ||
| if (result.exitCode != 0) { | ||
| stdout.writeln('exit code: ${result.exitCode}'); | ||
| stdout.writeln('gh api stdout:'); | ||
| stdout.writeln(result.stdout); | ||
| stderr.writeln('gh api stderr:'); | ||
| stderr.writeln(result.stderr); | ||
| } | ||
| return result.exitCode == 0; | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Test double with in-memory state for hermetic unit testing. | ||
| class FakeGitHubClient implements GitHubClient { | ||
| final Set<String> existingUsers; | ||
|
|
||
| FakeGitHubClient({Set<String>? existingUsers}) | ||
| : existingUsers = existingUsers ?? <String>{}; | ||
|
|
||
| @override | ||
| Future<bool> userExists(String username) async { | ||
| return existingUsers.contains(username); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user runs
dart run bin/validate_rfc_number.dart --base-branch upstream/mainwon't the --base-branch flag be silently ignored because checkMain defaults to false?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, and I think I can use args to check that it was actually passed in by a user. Instead of two flags, I'll add one (base-branch) and if its provided, we'll check against it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(note to self, make sure the action is updated)