Getting snapcraft.yaml version from a script
gregory.lutostanski at canonical.com
Fri Mar 31 19:57:13 UTC 2017
Curious how everyone makes sure the version string in the snapcraft.yaml up
to date. And if there is an easy way to essentially drive it via 'git tags'
and 'git describe'. If anyone has an recipe I would be very happy to use it
across my repos.
I've tried the following prepare script:
sed -i 's/^version: .*/version: '`git describe --tags`'/'
But that won't work because snapcraft has read it before checking out the
part to build. And I don't like having a separate build script if not
necessary (especially since the launchpad builders wont use it).
I have been playing around with npm recently, and the way their versions
work are good -- but they are only dealing with public releases with a set
semver (usually), but at least they have a script to update it with
What I would really like is to not directly specify the version but let
snapcraft get it for me by executing a script.
If there is nothing already existent out there... here is a proposal for
allowing it and letting it be backward compatible:
By default get it from the top-level 'version' value in snapcraft.yaml
If that is not present one (and only one) of the parts must have a
'source-version' key,value pair, where the value is a script to be
executed -- just like the prepare step.
 could also be named source-version-script
This would get us the following: allow to specify string version using the
old keyword. Make a new-keyword that allows us to set the version based on
The two different examples would look like...
source-version: git describe --tags
A further extension could be to have the source plugins (such as
git/bzr/hg) have default source-version commands and if there is a part
with the same name as the snap, use that by default, but that is just sugar
and implicit data (which could be argued for either way).
Thoughts, or other ways people are doing this now would be greatly
appreciated. By the way, not sure if this is already thought out or if this
is even the right place for a post like this.
More information about the Snapcraft