| Message ID | 20260226-release-parser-improvements-v1-1-3cc1c9842a87@bootlin.com |
|---|---|
| State | New |
| Headers | show |
| Series | release-parser.py improvements | expand |
Hi Antonin, On 2/26/26 3:26 PM, Antonin Godard wrote: > Sort the "releases" array to sort tags based on semantic versioning. > > Turning: > > "releases": [ "5.0", "5.0.1", "5.0.10", [...] "5.0.8", "5.0.9" ] > > into: > > "releases": [ "5.0", "5.0.1", "5.0.2", [...] "5.0.14", "5.0.15" ], > > Reported-by: Quentin Schulz <quentin.schulz@cherry.de> > Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> > --- > scripts/release-parser.py | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/scripts/release-parser.py b/scripts/release-parser.py > index e07fd71..882c0fd 100755 > --- a/scripts/release-parser.py > +++ b/scripts/release-parser.py > @@ -60,7 +60,8 @@ def get_git_tags(): > return semver.VersionInfo.parse(tag + ".0") > > tag_names = [parse(re.sub(r"yocto-", "", e.name)) for e in tags] > - tag_strings = [re.sub(r"yocto-", "", e.name) for e in tags] > + tag_strings = sorted([re.sub(r"yocto-", "", e.name) for e in tags], > + key=lambda x: [int(y) for y in x.split('.')]) > If you reused the tag_names (which contains semver.Version objects due to parse() I believe) variable, then you wouldn't need any of this. See >>> s=[semver.Version.parse("3.4.15"), semver.Version.parse("3.4.5"), semver.Version.parse("2.6.5")] >>> sorted(s) [Version(major=2, minor=6, patch=5, prerelease=None, build=None), Version(major=3, minor=4, patch=5, prerelease=None, build=None), Version(major=3, minor=4, patch=15, prerelease=None, build=None)] Then you can generate a string-only array by using: >>> [str(v) for v in tag_strings] Also, I think you can get rid of the parse function by using semver.VersionInfo.parse('1.2.3', optional_minor_and_patch=True) c.f. https://python-semver.readthedocs.io/en/latest/usage/parse-version-string.html. This does mean we allow versions with only a "major" part. Cheers, Quentin
diff --git a/scripts/release-parser.py b/scripts/release-parser.py index e07fd71..882c0fd 100755 --- a/scripts/release-parser.py +++ b/scripts/release-parser.py @@ -60,7 +60,8 @@ def get_git_tags(): return semver.VersionInfo.parse(tag + ".0") tag_names = [parse(re.sub(r"yocto-", "", e.name)) for e in tags] - tag_strings = [re.sub(r"yocto-", "", e.name) for e in tags] + tag_strings = sorted([re.sub(r"yocto-", "", e.name) for e in tags], + key=lambda x: [int(y) for y in x.split('.')]) if len(tag_names) == 1: latest_tag = repo.tags[
Sort the "releases" array to sort tags based on semantic versioning. Turning: "releases": [ "5.0", "5.0.1", "5.0.10", [...] "5.0.8", "5.0.9" ] into: "releases": [ "5.0", "5.0.1", "5.0.2", [...] "5.0.14", "5.0.15" ], Reported-by: Quentin Schulz <quentin.schulz@cherry.de> Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> --- scripts/release-parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)