Use git version during build stage (downloading pre-built apps)


#1

Hello,

I’m trying to help the exercism cli team to make a snap package that can be automatically-built (maybe by build.snapcraft.io).

I’m trying to use version: git (which should work, the repo has tags for each version) but on my part build stage, when I try to download the tarfile, $SNAPCRAFT_PROJECT_VERSION has a value of git, which causes the download of https://github.com/exercism/cli/releases/download/$SNAPCRAFT_PROJECT_VERSION/exercism-linux-64bit.tgz to fail.

Documentation about $SNAPCRAFT_PROJECT_VERSION is very limited, from what I could find on this forum the git version is only available at later stages?

Is there an alternative way to do this?

Thank you :slight_smile:


#2

Can someone give an answer, please? :slight_smile:


#3

Hi,

The recommended way would probably be to use a scriptlet to download the tarball rather than the declarative source: attribute, or ideally you’d set source: to a git repository and then check out the right version in an override-pull: block. This method means you can drop the version: git line:

parts:
  exercism-cli:
    source: https://github.com/exercism/cli.git
    override-pull: |
      snapcraftctl pull
      last_committed_tag="$(git tag -l | grep -v v | sort -rV | head -n1)"
      last_committed_tag_ver="$(echo ${last_committed_tag} | sed 's/^v//')"
      git checkout "$last_committed_tag"
      snapcraftctl set-version "$last_committed_tag_ver"