-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[flutter_tools] Skip version freshness check for non-standard remotes #97202
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
[flutter_tools] Skip version freshness check for non-standard remotes #97202
Conversation
d5b20da to
cf122c3
Compare
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.
rather than hard-coding here, could you also store this in globals, next to flutterGit?
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.
Getting back to this, why does this need to be in globals? This and flutterGit would be only used in version.dart. We could probably remove them from globals and instead pass globals.platform around.
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.
SGTM
14afae7 to
7045442
Compare
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.
this context platform never gets called in the test, right?
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.
Unless the test doesn't call globals.flutterGit, which it definitely does :)
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.
I can see that before we were injecting the platform, we were accidentally leaking the real system platform into the test suite, which is a huge cause of flakiness in our tool test suite. For the tests that only depend on a created instance of VersionUpstreamValidator, can you use testWithoutContext() instead of testUsingContext()? With testWithoutContext(), any test that tries to call context.get() via the globals. or any other method will throw. This way we know exactly what our the code depends on, and we don't get tests accidentally passing because the system they were running on had the correct platform setup. I imagine you will have to also inject flutterGitSshUrl via the constructor.
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.
We would also need to provide globals.flutterGit too if that's the case.
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.
Yeah. I know it's a pain, but it's the best way we have right now for ensuring that we're not leaking global state.
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.
...which adds two parameters which similar semantics?
VersionUpstreamValidator({
required this.version,
required this.platform,
required this.flutterGitUrl,
required this.flutterGitSshUrl,
});Can't think of a better name to give to these parameters.
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.
Yeah, that feels bad. However, the only other way I can think of would be to define a class for GitHubRemote, that takes in an org and project name, and has two getters for httpsUrl and sshUrl, but that seems like overkill?
|
Adding to my comment here and my inference of the usage of
flutter/packages/flutter_tools/lib/src/version.dart Lines 274 to 283 in cddd552
This will be redundant once this PR lands(and can be removed). flutter/packages/flutter_tools/lib/src/version.dart Lines 634 to 641 in cddd552
From what I can see, this is used for version resolution, before which the tool fetches in the newer tags. An interesting consequence of using FLUTTER_GIT_URL here that if the custom remote does not have the newer tags (which is the case for forks updated through git pull upstream master && git push origin master), a wrong version is calculated(#15529).
I confirmed this by running
|
Yeah, I don't think there's much we can do about this, other than deprecating the use of git tags for version resolution, which I would like to do but don't really have time for. |
|
@christopherfujino to solve the issue you mentioned at #97202 (comment), can we instead do #97202 (comment) and use a different VersionUpstreamValidator({
required this.version,
required this.platform,
- required this.flutterGitSshUrl,
- required this.flutterGitUrl,
- });
+ }) : _flutterGit = platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
- final String flutterGitSshUrl;
- final String flutterGitUrl;
+ final String _flutterGit;
final FlutterVersion version;
final Platform platform;
...
// Strip `.git` suffix before comparing the remotes
- final String sanitizedRepositoryUrl = stripDotGit(repositoryUrl);
- final String sanitizedFlutterGitUrl = stripDotGit(flutterGitUrl);
- final String sanitizedFlutterGitSshUrl = stripDotGit(flutterGitSshUrl);
+ final List<String> sanitizedStandardRemotes = <String>[
+ _flutterGit,
+ '[email protected]:flutter/flutter.git',
+ ].map((String remote) => stripDotGit(remote)).toList();A similar change can be made(in a future PR) where - static GitTagVersion determine(ProcessUtils processUtils, {String? workingDirectory, bool fetchTags = false, String gitRef = 'HEAD'}) {
+ static GitTagVersion determine(
+ ProcessUtils processUtils,
+ Platform platform, {
+ String? workingDirectory,
+ bool fetchTags = false,
+ String gitRef = 'HEAD'
+ }) {
if (fetchTags) {
final String channel = _runGit('git rev-parse --abbrev-ref HEAD', processUtils, workingDirectory);
if (channel == 'dev' || channel == 'beta' || channel == 'stable') {
globals.printTrace('Skipping request to fetchTags - on well known channel $channel.');
} else {
- _runGit('git fetch ${globals.flutterGit} --tags -f', processUtils, workingDirectory);
+ final String flutterGit = platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
+ _runGit('git fetch $flutterGit --tags -f', processUtils, workingDirectory); |
fa51406 to
720a22a
Compare
SGTM |
720a22a to
e145881
Compare
7e00826 to
c24c877
Compare
c24c877 to
89e9739
Compare
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.
I think it's a little unusual for the API of this method to be void while it is the responsibility of the caller to catch a VersionCheckError. Could you instead have this method return VersionCheckError? and then in the method, instead of throwing, simply return the error.
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.
Done.
christopherfujino
left a comment
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.
This overall LGTM, with the nit about the validator.run returning a nullable error rather than throwing.
89e9739 to
efb5d35
Compare
christopherfujino
left a comment
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.
LGTM, thanks!
|
This pull request is not suitable for automatic merging in its current state.
|
|
@Jasguerrero can you take a look too? |
Jasguerrero
left a comment
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.
LGTM
This PR makes the tool skip checking for version freshness if the remote being tracked by the current channel/branch is "not-standard".
A standard remote is either
https://github.com/flutter/flutter.git/[email protected]:flutter/flutter.gitor the one set in the environment variableFLUTTER_GIT_URL.This makes the tool check for freshness from the same repo it will fetch the updates when running the
upgradesub-command. Another added bonus, it prevents the unnecessary check for freshness from a user's forked repo, however the user can still configureFLUTTER_GIT_URLfor freshness check anyway in that case.Fixes #14120.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.