Cannot get version from git

Hi, I try to build my Python CLI app https://snapcraft.io/zshgpt https://github.com/AndersSteenNilsen/zshgpt

First I tried

name: zshgpt
summary: Power up your zsh with gpt
description: Power up your zsh with gpt.
grade: stable
version: git
confinement: devmode
base: core20
license: MIT
architectures:
  - build-on: [arm64, armhf, amd64]

apps:
  zshgpt:
    command: bin/zshgpt
    plugs: [home, network, network-bind, removable-media]

parts:
  zshgpt:
    plugin: python
    python-packages: [zshgpt]

The result I got was always a version like 0+git.<hash> Even though I have tagged the repo

git describe --tag
v1.0.1

I debugged and changed snapcraft.yaml to

name: zshgpt
summary: Power up your zsh with gpt
description: Power up your zsh with gpt.
grade: stable
version: git
confinement: devmode
base: core20
license: MIT
adopt-info: zshgpt
architectures:
  - build-on: [arm64, armhf, amd64]

apps:
  zshgpt:
    command: bin/zshgpt
    plugs: [home, network, network-bind, removable-media]

parts:
  zshgpt:
    plugin: python
    python-packages: [zshgpt]
    override-pull: |
      snapcraftctl pull
      git -C /root/project describe --tags #For debugging
      snapcraftctl set-version $(git -C /root/project describe --tags)

(For reference I also tried snapcraftctl set-version $(git describe --tags) But got something like This directory nor any parent directory is a git repo)

I got correct result when I ran snapcraft locally, but when I pushed the changes to my repo I got this message:

+ git -C /root/project describe --tags
fatal: cannot change to '/root/project': No such file or directory

Would be happy to get some feedback in order to resolve this.

PS: I also found the information around version:git lacking in the tutorial/reference

Ported to core22. Check the PR please.

Thank you so much for your contribution <3. I had to add build-for in architecture and source in parts. Now it builds, but I get Built, failed to release. For completeness and if someone have the same problem, this is now my snapcraft.yaml

name: zshgpt
summary: Power up your zsh with gpt
description: Power up your zsh with gpt.
grade: stable
confinement: strict
base: core22
adopt-info: zshgpt
architectures:
  - build-on: [amd64]
    # build-for: [all]
    build-for: [amd64]
apps:
  zshgpt:
    command: bin/zshgpt
    plugs: [home, network, network-bind, removable-media]

parts:
  zshgpt:
    plugin: python
    python-packages: [zshgpt]
    source: .
    override-pull: |
      craftctl default
      craftctl set version=$(git describe --tags --abbrev=0 | cut -c 2-)
2 Likes