-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[tool] Add features to support GCB auto-publish flow #6218
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
auto-submit
merged 3 commits into
flutter:main
from
stuartmorgan-g:tool-autopublish-gcp-prep
Mar 5, 2024
Merged
Changes from 2 commits
Commits
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 |
|---|---|---|
|
|
@@ -58,6 +58,11 @@ class PublishCommand extends PackageLoopingCommand { | |
| }) : _pubVersionFinder = | ||
| PubVersionFinder(httpClient: httpClient ?? http.Client()), | ||
| _stdin = stdinput ?? io.stdin { | ||
| argParser.addFlag(_alreadyTaggedFlag, | ||
| help: | ||
| 'Instead of tagging, validates that the current checkout is aleardy tagged with the expected version.\n' | ||
| 'This is primarily intended for use in CI publish steps triggered by tagging.', | ||
| negatable: false); | ||
| argParser.addMultiOption(_pubFlagsOption, | ||
| help: | ||
| 'A list of options that will be forwarded on to pub. Separate multiple flags with commas.'); | ||
|
|
@@ -83,13 +88,20 @@ class PublishCommand extends PackageLoopingCommand { | |
| argParser.addFlag(_skipConfirmationFlag, | ||
| help: 'Run the command without asking for Y/N inputs.\n' | ||
| 'This command will add a `--force` flag to the `pub publish` command if it is not added with $_pubFlagsOption\n'); | ||
| argParser.addFlag(_tagForAutopublishFlag, | ||
| help: | ||
| 'Runs the dry-run publish, and tags if it succeeds, but does not actually publish.\n' | ||
| 'This is intended for use with a separate publish step that is based on tag push events.', | ||
| negatable: false); | ||
| } | ||
|
|
||
| static const String _alreadyTaggedFlag = 'already-tagged'; | ||
| static const String _pubFlagsOption = 'pub-publish-flags'; | ||
| static const String _remoteOption = 'remote'; | ||
| static const String _allChangedFlag = 'all-changed'; | ||
| static const String _dryRunFlag = 'dry-run'; | ||
| static const String _skipConfirmationFlag = 'skip-confirmation'; | ||
| static const String _tagForAutopublishFlag = 'tag-for-autopublish'; | ||
|
||
|
|
||
| static const String _pubCredentialName = 'PUB_CREDENTIALS'; | ||
|
|
||
|
|
@@ -193,15 +205,27 @@ class PublishCommand extends PackageLoopingCommand { | |
| return PackageResult.fail(<String>['uncommitted changes']); | ||
| } | ||
|
|
||
| if (!await _publish(package)) { | ||
| return PackageResult.fail(<String>['publish failed']); | ||
| final bool tagOnly = getBoolArg(_tagForAutopublishFlag); | ||
| if (!tagOnly) { | ||
| if (!await _publish(package)) { | ||
| return PackageResult.fail(<String>['publish failed']); | ||
| } | ||
| } | ||
|
|
||
| if (!await _tagRelease(package)) { | ||
| return PackageResult.fail(<String>['tagging failed']); | ||
| final String tag = _getTag(package); | ||
| if (getBoolArg(_alreadyTaggedFlag)) { | ||
| if (!(await _getCurrentTags()).contains(tag)) { | ||
| printError('The current checkout is not already tagged "$tag"'); | ||
| return PackageResult.fail(<String>['missing tag']); | ||
| } | ||
| } else { | ||
| if (!await _tagRelease(package, tag)) { | ||
| return PackageResult.fail(<String>['tagging failed']); | ||
| } | ||
| } | ||
|
|
||
| print('\nPublished ${package.directory.basename} successfully!'); | ||
| final String action = tagOnly ? 'Tagged' : 'Published'; | ||
| print('\n$action ${package.directory.basename} successfully!'); | ||
| return PackageResult.success(); | ||
| } | ||
|
|
||
|
|
@@ -277,8 +301,7 @@ Safe to ignore if the package is deleted in this commit. | |
| // Tag the release with <package-name>-v<version>, and push it to the remote. | ||
| // | ||
| // Return `true` if successful, `false` otherwise. | ||
| Future<bool> _tagRelease(RepositoryPackage package) async { | ||
| final String tag = _getTag(package); | ||
| Future<bool> _tagRelease(RepositoryPackage package, String tag) async { | ||
| print('Tagging release $tag...'); | ||
| if (!getBoolArg(_dryRunFlag)) { | ||
| final io.ProcessResult result = await (await gitDir).runCommand( | ||
|
|
@@ -301,6 +324,22 @@ Safe to ignore if the package is deleted in this commit. | |
| return success; | ||
| } | ||
|
|
||
| Future<Iterable<String>> _getCurrentTags() async { | ||
| // git tag --points-at HEAD | ||
| final io.ProcessResult tagsResult = await (await gitDir).runCommand( | ||
| <String>['tag', '--points-at', 'HEAD'], | ||
| throwOnError: false, | ||
| ); | ||
| if (tagsResult.exitCode != 0) { | ||
| return <String>[]; | ||
| } | ||
|
|
||
| return (tagsResult.stdout as String) | ||
| .split('\n') | ||
| .map((String line) => line.trim()) | ||
| .where((String line) => line.isNotEmpty); | ||
| } | ||
|
|
||
| Future<bool> _checkGitStatus(RepositoryPackage package) async { | ||
| final io.ProcessResult statusResult = await (await gitDir).runCommand( | ||
| <String>[ | ||
|
|
||
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
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.
typo: already
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.
Little known fact, "aleardy" is actually the adverbal form of "all ears"; this is validating that it was tagged in a way that makes it all ears.
(Fixed.)