Setting the snapcraft.yaml version field to 'git' produces undocumented and broken magic

Bug #1769519 reported by Neil McPhail
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Snapcraft
Confirmed
Undecided
Unassigned

Bug Description

I've found that if the version: field in snapcraft.yaml is set to 'git', snapcraft does some magic where a mangled form of `git describe` is substituted into the version: field. This seems like a superb feature, although it is missing from the documentation.

However, if the latest tag in the git repository contains invalid characters such as an underscore, the resultant snap will have an invalid version string and snap will refuse to install the package. Snapcraft itself does not produce an error.

I'd suggest this piece of magic is either fixed (perhaps substituting '-' characters for invalid characters) or removed.

(snapcraft version 2.42 on 16.04)

Revision history for this message
林博仁(Buo-ren, Lin) (buo-ren-lin) wrote :

Seems to be workaroundable by using the other undocumented version-script key?

Revision history for this message
Neil McPhail (njmcphail) wrote :

Yes. It'd be a shame if we had to perpetually rely on boilerplate input validation to perform such a useful function, though. If there is a consensus to only use version-script, this feature of version: should be removed to prevent unexpected breakage.

Revision history for this message
Kyle Fazzari (kyrofa) wrote :

There is actually a third option: you can do this in scriptlets as of snapcraft 2.41[1]. High-level: you need to set `adopt-info` to the part that will set the version, and then you can run `snapcraftctl set-version` in a scriptlet for that part. Read the post for more info.

[1] https://forum.snapcraft.io/t/extracting-information-from-sources-in-snapcraft-parts/4642

Changed in snapcraft:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.