Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[tool] refactor publish plugin command #3779

Merged
merged 7 commits into from
Apr 5, 2021

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Apr 1, 2021

Refactoring publish plugin command to get ready for a new feature to publish and tag release based on git diff.

See #3776 (comment)

behavioral change: The command now validate the git remote first before checking package directory. Because when we change this command later to run multiple publishes, the git remote validation only needs to happen once.

@google-cla google-cla bot added the cla: yes label Apr 1, 2021
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structure looks good, just small suggestions

argParser.addOption(
_allOption,
help:
'Based the diff between $_kBaseShaOption and HEAD, publish all the plugins that has pubspec change in this diff.\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "have pubspec changes"

_allOption,
help:
'Based the diff between $_kBaseShaOption and HEAD, publish all the plugins that has pubspec change in this diff.\n'
'The --package option is ignored if this flag is on. (This is currently under construction)' ,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "under construction" mean here? Is the plan for this behavior to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It meant it is not supported yet. I had everything wired up in a different branch but i thought to introduce this pr as an intermediate step is easier to review.

I should just remove the flag int this PR as well and add this flag when actually adding this feature.

argParser.addOption(
_allOption,
help:
'Based the diff between $_kBaseShaOption and HEAD, publish all the plugins that has pubspec change in this diff.\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle the case where there have been multiple releases of a single plugin in the range, or are we going to avoid that issue in automation by never doing a range spanning multiple changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue won't exist when we start the automate process, because every commit that contains a pubspec change is going to run a publish command.

There might be leftovers before the automation so we might need to handle that, handle it manually before automation doesn't seem to be too bad.

_print('Package published!');
}

Future<void> _tagRelease({@required Directory packageDir, @required String remote, @required String remoteUrl, @required bool shouldPushTag}) async {
if (!argResults[_tagReleaseOption]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense to wrap the call to _tagRelease in this check, rather than making the function silently no-op based on an argument.

final String tag = _getTag();
await processRunner.runAndExitOnError('git', <String>['tag', tag],
workingDir: _packageDir);
final String tag = _getTag(packageDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's flip this and the line above, so the print can include the tag for ease of debugging issues.

if (package == null) {
_print(
'Must specify a package to publish. See `plugin_tools help publish-plugin`.');
Directory _checkPackageDir(String package) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to something like _getPackageDir (and document that it throws if the dir doesn't exist)? I would expect a check function to either return a bool, or return nothing.

Copy link
Contributor Author

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuartmorgan Updated per comments. PTAL

argParser.addOption(
_allOption,
help:
'Based the diff between $_kBaseShaOption and HEAD, publish all the plugins that has pubspec change in this diff.\n'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue won't exist when we start the automate process, because every commit that contains a pubspec change is going to run a publish command.

There might be leftovers before the automation so we might need to handle that, handle it manually before automation doesn't seem to be too bad.

_allOption,
help:
'Based the diff between $_kBaseShaOption and HEAD, publish all the plugins that has pubspec change in this diff.\n'
'The --package option is ignored if this flag is on. (This is currently under construction)' ,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It meant it is not supported yet. I had everything wired up in a different branch but i thought to introduce this pr as an intermediate step is easier to review.

I should just remove the flag int this PR as well and add this flag when actually adding this feature.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cyanglaz cyanglaz added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 5, 2021
@fluttergithubbot fluttergithubbot merged commit bd2dbb1 into flutter:master Apr 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 5, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants