I previously use the following override-pull scriptlet to generate the snap version:
snapcraftctl pull
upstream_version="$(
git \
describe \
--always \
--dirty=-d \
--tags \
| sed s/^v//
)"
packaging_revision="$(
git \
-C .. \
describe \
--abbrev=4 \
--always \
--match nothing \
--dirty=-d
)"
snapcraftctl set-version \
"${upstream_version}+pkg-${packaging_revision}"
However, when building the snap using the multipass build environment the script fails on the packaging_revision parameter assignment as the parts
directory(/root/parts
in the multipass VM) no longer reside in the VCS source tree(/root/project
in the multipass VM).
Is there any way to get around this without any hacks and workarounds?
Here’s my workaround:
# WORKAROUND:
# Allow fetching project revision in multipass build
# environment, which uses out-of-tree build and packaging
# source tree repo location can't be determined via environment
# Unable to determine project version info in multipass build environment - snapcraft - snapcraft.io
# https://forum.snapcraft.io/t/unable-to-determine-project-version-info-in-multipass-build-environment/10416
if test -d /root/project; then
some_place_under_the_project_repo=/root/project
else
some_place_under_the_project_repo=..
fi
packaging_revision="$(
git \
-C "${some_place_under_the_project_repo}" \
describe \
--abbrev=4 \
--always \
--match nothing \
--dirty=-d
)"
#!/usr/bin/env bash
# Extract and set the snap's version from the main part
# 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com> © 2019
set \
-o errexit \
-o errtrace \
-o nounset \
-o pipefail
init(){
local \
flag_dry_run=false \
upstream_version \
packaging_revision \
some_place_under_the_project_repo \
snap_version_string
for commandline_argument in "${@}"; do
case "${commandline_argument}" in
This file has been truncated. show original
This topic is no longer an issue after Snapcraft exposes the SNAPCRAFT_PROJECT_DIR
environment variable since 3.4.1: Release Minor improvements · snapcore/snapcraft
2 Likes