-
Notifications
You must be signed in to change notification settings - Fork 29k
[flutter_tools] Make flutter git upstream configurable #61513
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] Make flutter git upstream configurable #61513
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Sorry for making many wrong commits at beginning. Please use rebase merge to hide them. 😢 |
No prob, we default to squash and merge, so each PR becomes one commit on master :) |
@@ -24,7 +24,7 @@ enum Channel { | |||
} | |||
|
|||
/// The flutter GitHub repository. | |||
const String _flutterGit = 'https://github.com/flutter/flutter.git'; | |||
final String _flutterGit = globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git'; |
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 looks like a good solution. One thing though, is that if the user has a typo in this env variable (or if it the remote is down), we should explicitly show the override value in any error message. If you check line 654 of this file, we throw an error if a command we run does not return a 0 exit code. Even though this error includes the complete command that failed, unfortunately, if FLUTTER_GIT_URL
env variable is wrong, we won't hit an error until line 257, which tries to run the command git fetch $_versionCheckRemote $branch
, which doesn't include the upstream URL in it. Probably the better version would be to add a catch
around 262, and IF we have an explicit FLUTTER_GIT_URL
override set in the environment, globals.printError('Warning: the Flutter git upstream was overriden by the environment variable FLUTTER_GIT_URL = ${globals.platform.environment['FLUTTER_GIT_URL']}');
(something like that, I didn't test it).
Also, this change should have unit tests in the file: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/general.shard/version_test.dart. Using the testUsingContext()
function, you can provide a FakePlatform
and ProcessManager
overrides (if you search the codebase for FakePlatform
, you'll find a lot of examples) where you set the environment variable and then expect that you are getting the correct git commands to the mockProcessManager
, specifically the one setting the upstream.
Let me know if you you run into any obstacles!
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 have finished print warning and unit test. But test running failed unexpected. Sorry for troubling but I have a problem now.
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.
Thanks for your contribution! This needs a test in order to be merged. How about something like this in version_test.dart?
testUsingContext('determine uses overridden git url', () {
final MockProcessUtils processUtils = MockProcessUtils();
when(processUtils.runSync(
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(RunResult(ProcessResult(108, 0, 'master', ''), <String>['git', 'fetch']));
when(processUtils.runSync(
<String>['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(RunResult(ProcessResult(109, 0, '', ''), <String>['git', 'fetch']));
when(processUtils.runSync(
<String>['git', 'tag', '--contains', 'HEAD'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(
RunResult(ProcessResult(110, 0, '', ''),
<String>['git', 'tag', '--contains', 'HEAD'],
));
when(processUtils.runSync(
<String>['git', 'describe', '--match', '*.*.*-*.*.pre', '--first-parent', '--long', '--tags'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(RunResult(ProcessResult(111, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe']));
GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true);
verify(processUtils.runSync(
<String>['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
));
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(environment: <String, String>{
'FLUTTER_GIT_URL': 'https://githubmirror.com/flutter.git',
}),
});
Those tests are kind of hard to write, sorry about that. I'd be happy to push the test to your fork, if you'd like!
Except flutter-build, all other test passed.
To be honest, I don't know what is it and other prs have this problem too.
flutter-build is our post-submit CI system, and at the moment it's failing, but this has nothing to do with your PR. Once this is in good shape, we'll handle merging your PR once it goes green!
@@ -24,7 +24,7 @@ enum Channel { | |||
} | |||
|
|||
/// The flutter GitHub repository. | |||
const String _flutterGit = 'https://github.com/flutter/flutter.git'; | |||
final String _flutterGit = globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git'; |
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.
Unfortunately this isn't really testable since it can't be changed after the first time it's set. I wrote a unit test for this that passed on its own, but failed when run with the entire test suite because it always returned https://github.com/flutter/flutter.git
because a previous test had initialized it.
How about:
String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ??
'https://github.com/flutter/flutter.git';
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.
Good catch
Really great. Thanks for all of your kindly helps. I'll work on them right now. |
I got trouble writing tests...sorry.
And so on, but I believe these should be enough. So basically, I need your help. 😢 |
60412f1
to
1376aa9
Compare
e0ffece
to
f98cfcb
Compare
Finally I managed to pass CI with tests. |
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.
Other than the one spacing nit, this LGTM. I'll approve and merge once that gets fixed, assuming @christopherfujino doesn't have any more suggestions.
LGTM once you make @jmagman 's spacing change |
Co-authored-by: Jenn Magder <magder@google.com>
The space problem fixed. Thanks. |
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
Description
Make flutter git upstream configurable from environment variable.
Used FLUTTER_GIT_URL to control _flutterGit value.
Related Issues
#61286
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.