Build a snap on a github tag

Hi,

for glpi-agent snap packaging I was faced to a problem when building the snap in a github Actions workflow. I wanted to create a snap like glpi-agent_1.0-git1234567_amd64.snap on a simple push and I managed to reach that goal using adopt-info feature and a dedicated override-build scriptlet. But I also wanted to build a glpi-agent_1.0-test16_amd64.snap when I tag a commit ref with 1.0-test16. This is to simplify our release process on github.

I searched a lot to handle that target. I understood GH environment is simply lost while building into the lxd container. Finally after a lot of local tests I managed to do the trick with a very very ugly hack…
I isolate the hack in a simple commit in our repo, but here is what it does:

  1. update the TERM environment variable of the snapcore/action-build action to include GITHUB_REF
  2. set GITHUB_REF and reset TERM from the passed modified TERM environment variable with in a build-environment directive.

As an example I was able to produce a 1.0-test16 snap package after pushing a tag for my g-bougard fork on GH.

As this is really very ugly, I really don’t like this hack. Also this hack may not working anymore in the future. So does anyone have a better and cleaner solution ?

Thanks

As I side-note, I don’t see a way to transmit the tag to the build.snapcraft.io system.

Even permitting to build manually on a tag/release and use the value for the build would be interesting. Actually, I understand I need to create a dedicated commit to just set the version.