-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[flutter_tools] check first for stable tag, then dev tag #55342
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] check first for stable tag, then dev tag #55342
Conversation
// Check first for a stable tag | ||
for (final String tag in tags) { | ||
final String trimmedTag = tag.trim(); | ||
if (RegExp(r'^\d+\.\d+\.\d+$').hasMatch(trimmedTag)) { |
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 would hoist this and the other RegExp out of the loop. Then, document the format they are expected to match.
Is it possible to reuse some of the existing version parsing logic here?
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 call on hoisting. I thought about reusing, but (at least in this file), they're all slightly different.
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 is understandable - consider centralizing and standardizing them, so that we can easily verify that each version has the same level of documentation and testing.
Also would hopefully prevent anyone from accidentally re-implementing them
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.
well, I take that back, I can do a little reuse, lemme play with this...
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.
hoisted regexes. PTAL
} | ||
} | ||
|
||
// If we're not currently on a tag, use git describe |
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 we're not currently on a tag, use git describe to find the most recent version tag.
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
final List<int> parsedParts = parts.map<int>( | ||
(String source) => source == null ? null : int.tryParse(source)).toList(); | ||
List<int> devParts = <int>[null, null]; | ||
if (parts[3] != null) { |
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 method is confusing, any way we can name the groups since parts[3] is group 4? Or create locals like:
final String majorVersion = match?.group(1);
final String minorVersion = match?.group(2);
final String patchVersion = match?.group(3);
final String preSuffix = match?.group(4);
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
final List<String> parts = versionPattern.matchAsPrefix(version)?.groups(<int>[1, 2, 3, 4, 5, 6]); | ||
r'^(\d+)\.(\d+)\.(\d+)(-\d+\.\d+\.pre)?$'); | ||
final Match match = versionPattern.matchAsPrefix(version); | ||
final List<String> parts = match?.groups(<int>[1, 2, 3, 4]); |
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.
For 1.2.3
will this return ['1', '2', 3'] or ['1', '2', 3', null]?
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.
The latter.
List<int> devParts = <int>[null, null]; | ||
if (parts[3] != null) { | ||
devParts = RegExp(r'^-dev\.(\d+)\.(\d+)') | ||
devParts = RegExp(r'^-(\d+)\.(\d+)\.pre') |
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.
Same here, the chaining is nice, but it's very confusing. I'd rather this be spelled out with some locals.
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
commits: 0, | ||
hash: '', |
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.
Are these used anymore?
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.
they will only be present if we're parsing the output of git describe
. this method is checking if we are exactly on a tag.
final int y = matchGroups[1] == null ? null : int.tryParse(matchGroups[1]); | ||
final int z = matchGroups[2] == null ? null : int.tryParse(matchGroups[2]); | ||
final String devString = matchGroups[3]; | ||
int m, n; |
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.
Can you rename these devVersion and devPatch?
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
final int y = matchGroups[1] == null ? null : int.tryParse(matchGroups[1]); | ||
final int z = matchGroups[2] == null ? null : int.tryParse(matchGroups[2]); | ||
final String devString = matchGroups[3]; | ||
int m, n; |
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.
Same, can you rename to devVersion and devPatch?
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
// TODO(fujino): Deprecate this https://github.com/flutter/flutter/issues/53850 | ||
/// Check for the release tag format of the form x.y.z-dev.m.n | ||
static GitTagVersion parseLegacyVersion(String version) { | ||
/// Check for the release tag format of the forms x.y.z or x.y.z-m.n.pre |
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.
Can you give a real example with digits, too?
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
|
||
/// Check for the release tag format of the form x.y.z-m.n.pre | ||
static GitTagVersion parseVersion(String version) { | ||
/// Detect output of git describe, of the form x.y.z-m.n.pre-<commits>-g<hash> |
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.
Same, can you give a real example here?
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
/// Check for the release tag format of the form x.y.z-dev.m.n | ||
static GitTagVersion parseLegacyVersion(String version) { | ||
/// Check for the release tag format of the forms x.y.z or x.y.z-m.n.pre | ||
static GitTagVersion parseTaggedVersion(String version) { |
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.
parseTaggedVersion
and parseGitVersion
look almost the same. Can they be combined with a regex that handles either case? ?>
is a non-capturing group.
I didn't run the unit tests, so this might not be quite right:
^(\d+)\.(\d+)\.(\d+)(-\d+\.\d+\.pre)?(?>-(\d+)-g([a-f0-9]+))?$
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 could combine the regexes, but i originally split these into two different methods as a code review suggestion because the the regex was getting difficult to read (which I agree). In particular, I feel like more explicit the regex, the less likely it is to be wrong.
At the same time, it feels bad having two methods that are almost the same. So not sure what to do.
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.
The methods seem sufficiently complex at this point to deduplicate, I'd rather trade an evil regex for fewer potential copy-paste issues like:
m = devGroups[0] == null ? null : int.tryParse(devGroups[0]);
n = devGroups[1] == null ? null : int.tryParse(devGroups[1]);
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.
Ok, I collapsed it into one. PTAL
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, thank you for sacrificing your mental wellbeing on this upgrade problem.
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
I'm not going to pretend that I've fully understood the git and regexps used, but the testing seems good so lets ship it
* [flutter_tools] fix type error in symbolize (#55212) * [flutter_tools] check first for stable tag, then dev tag (#55342) * [flutter_tools] enable `flutter upgrade` to support force pushed branches (#55594) * [flutter_tools] catch ProcessException and throw ToolExit during upgrade (#55759) * Update engine version to 376ad6a64b08aa26005e3f82aed26de2e290b572 Co-authored-by: Jonah Williams <campfish91@gmail.com> Co-authored-by: Christopher Fujino <fujino@google.com> Co-authored-by: Christopher Fujino <christopherfujino@gmail.com>
Description
In the situation where beta release
1.2.3-4.5.pre
is promoted to the stable channel as1.2.3
, the tool will have to disambiguate between multiple tags on the same commit. The desired outcome is to always favor the stable tag. Prior to this PR, the tool relied ongit describe ...
to pick the right tag. Testing locally, it seemed to do the right thing, but as this may not be stable (e.g. https://stackoverflow.com/questions/8089002/git-describe-with-two-tags-on-the-same-commit), this PR makes the following changes:git describe ...
to determine the version, first check if the current commit is already tagged (git tag --contains HEAD
), and if it is, check first for a stable tag, then for a dev tag.git describe ...
as before and parse.x.y.z-dev.m.n
, closing Deprecate legacy release tag parsing logic #53850.Related Issues
Fixes #55332 and #53850.
Tests
Updated test mocks to support an additional process call to git, and added additional test expectations.
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].