Yes I have, went into https://github.com/snapcore/snapd/blob/master/mkversion.sh saw the fallback logic and on the same branch above produces something like 3f5c735f+gitdirty. It omits the tags though which I find rather important to keep.
@sergiusens Sorry, I’m still having a hard time parsing your feedback or intention. Let me turn this around and tell you what we have and why. This is what I get when running mkversion.sh in the snapd repository:
% ./mkversion.sh
*** Setting version to '2.23.1+git134.g27f30d5' from git.
So, in order:
2.23.1 is the most recent tag in this tree
+git means we’re taking source from a repository rather than a release
134 means how far we are from the tagged version… much better for humans than the next
g27f30d5 is the exact revision used, and can probably be omitted in this context as it’s long and ugly
dirty is also omitted because it’s ugly and helps little (snap may have changes later anyway)
The current implementation is a little problematic and confusing. In my understanding version-script supersedes the existing and mandatory version field but when I use the environment variable SNAPCRAFT_PROJECT_VERSION in a plugin, its value refers to the previously superseded field, version.
Think of a case where dump plugin downloads a zip file from a dynamic URL based on the version number. Currently this results in a practically static URL because SNAPCRAFT_PROJECT_VERSION always refers to the hard-coded value of version field.
I have a packaging example here that elaborates the issue I am talking above.
A simple solution in my opinion would be to to call version-script block at the very start and export its returned value as SNAPCRAFT_PROJECT_VERSION.
The reason is, version-script was created to set a version in the metadata from information set from built sources, you are trying to use it the other way around, this won’t be possible with this implementation, ever.
It may find its way when the pre and post work taking into account the setting of metadata through setters takes place (Scripting and setting metadata in snapcraft), that work should start to be surfaced around January.
Hi @sergiusens. I don’t think this behaviour has been documented on the main site yet, and does seem to be slightly broken as per https://bugs.launchpad.net/snapcraft/+bug/1769519 . Would it be possible to patch the behaviour to deal with invalid characters such as underscores in git tags?