Skip to content
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

cli: Add "get-latest-version" util command #503

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hadess
Copy link

@hadess hadess commented Jun 19, 2023

This gets the latest version specified in an appdata file, which,
combined with utilities such as check-news.sh1, can be used to check
whether the date specified in the appdata's release information is
correct.

See https://gitlab.gnome.org/GNOME/evince/-/issues/1950

Closes: #502

Fixes: 3f88c4e ("Add new is-satisfied check to test relations from the command-line")
This gets the latest version specified in an appdata file, which,
combined with utilities such as check-news.sh[1], can be used to check
whether the date specified in the appdata's release information is
correct.

See https://gitlab.gnome.org/GNOME/evince/-/issues/1950

Closes: ximion#502

[1]: https://gitlab.gnome.org/GNOME/totem/-/blob/master/check-news.sh
@hadess hadess force-pushed the wip/hadess/add-get-latest-version branch from 8d4b43c to 4e8120a Compare June 19, 2023 19:05
gnomesysadmins pushed a commit to GNOME/evince that referenced this pull request Jun 20, 2023
Instead of appstream-util, as it is in deep maintenance mode.

See: ximion/appstream#503
_("Check if requirements of a component (via its ID or MetaInfo file) are satisfied on this system."),
as_client_run_is_satisfied);
ascli_add_cmd (commands,
2, "get-latest-version", NULL, "FILE",
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if this should be called metainfo-latest-version or something, to make clear we're not querying the latest AppStream version... But the confusion potential is probably not that high...

ascli_add_cmd (commands,
2, "get-latest-version", NULL, "FILE",
/* TRANSLATORS: `appstreamcli get-latest-version command description. */
_("Get the latest version from the AppData file"),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
_("Get the latest version from the AppData file"),
_("Get the latest version from the MetaInfo file"),

(the file format is called MetaInfo, AppData is an ancient name from an early draft)

(g_str_has_suffix (fname, ".yml")) ||
(g_str_has_suffix (fname, ".yaml"))) {
/* if we have YAML, we also automatically assume a catalog style */
as_metadata_set_format_style (metad, AS_FORMAT_STYLE_CATALOG);
Copy link
Owner

Choose a reason for hiding this comment

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

Does it make any sense to read this for CATALOG data? Since catalog files contain many components, you would currently just get a random version, so I don't think that makes sense.
I think it would be better if this code would just error-out in that case and limit itself to metainfo files.
The added benefit of that would be that this code would be much smaller then too ;-)

for (guint i = 0; i < releases->len; i++) {
AsRelease *release_tmp = g_ptr_array_index (releases, i);
if (release_newest == NULL ||
as_release_get_timestamp (release_tmp) > as_release_get_timestamp (release_newest))
Copy link
Owner

Choose a reason for hiding this comment

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

We may not always have a timestamp (e.g. for development versions / unreleased ones).
Since the release entries must be sorted highest to lowest, we could cheat here and just pick the first release entry, or we could go the extra mile of comparing version numbers if one of the releases has no timestamp...

Is it common that there are sorting errors with release elements? (appstreamcli validate should throw an error for that).

return 3;
}

cpt = g_object_ref (as_metadata_get_component (metad));
Copy link
Owner

Choose a reason for hiding this comment

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

nitpick: You don't need to reference the AsComponent here, as it is held for the duration of AsMetadata's life. That said, it also doesn't really hurt either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "get-latest-version" cli command
2 participants