I want to get the last release tag of a github repository and then use it to define download links for .deb files.
Something like:
get-version:
plugin: nil
source: https://repo.git
source-type: git
override-pull: |
snapcraftctl pull
snapcraftctl set-version "$(git describe --tags --abbrev=0)"
echo "$SNAPCRAFT_PROJECT_VERSION" # <--- prints ""
download-deb:
after:
- get-version
plugin: dump
source: https://link/name_$SNAPCRAFT_PROJECT_VERSION_amd64.deb
It works if I use version:
but not with adopt-info:
and snapcraftctl set-version
. The link looks like https://link/name__amd64.deb
with adopt-info
.
ppd
May 19, 2020, 5:35pm
2
One possibility for env variable propagation:
In get-version
echo "export PROJECT_VERSION=123" > /tmp/snapcraft-project-version
in download-deb
. /tmp/snapcraft-project-version
Hmm snapcraftctl pull
didn’t respect the env variable :
download-deb:
plugin: dump
source: https://link/name_$PROJECT_VERSION_amd64.deb
source-type: deb
override-pull: |
export PROJECT_VERSION=123
printenv # <---- shows PROJECT_VERSION=123
snapcraftctl pull # <---- variable in link does not become 123 but stays "$PROJECT_VERSION"
printenv # <---- shows PROJECT_VERSION=123
edit: It looks like snapcraftctl
doesn’t respect changes
Sorry @frederickjh , this post wasn’t in the snapcraft category so I never saw it (I’ve fixed that now).
I’m afraid snapcraftctl doesn’t quite work this way, nor was it designed to. When you run snapcraftctl build, snapcraftctl isn’t the utility actually building, it’s still the parent snapcraft CLI, which is running under its own environment. When you call snapcraftctl build, you’re literally saying “please run the build exactly as you would have otherwise”. If you need to customize the build p…
ppd
May 20, 2020, 7:37am
4
I somehow missed you wanting to use the variable outside the scriptlet.
How about you download & extract the deb yourself, like so:
parts:
get-version:
plugin: nil
override-pull: |
set -eux
echo "export PROJECT_VERSION=2.44.1-2" > /tmp/snapd-project-version
download-deb:
after: [get-version]
plugin: nil
build-packages:
- wget
override-pull: |
set -eux
. /tmp/snapd-project-version
wget "http://ftp.de.debian.org/debian/pool/main/s/snapd/snapd_${PROJECT_VERSION}_amd64.deb" \
-O snapd.deb
override-build: |
set -eux
dpkg-deb -xv $SNAPCRAFT_PART_SRC/snapd.deb $SNAPCRAFT_PART_INSTALL
You could simplify this by not using two separate parts, but I don’t know your requirements.
ogra
May 20, 2020, 10:53am
5
you could do this as a one-liner and actually “stream the deb to disk”
wget -q -O- $URL | dpkg -x - "$SNAPCRAFT_PART_SRC/snapd"
2 Likes
Thank you both. If I had two sources in the normal case, i.e.:
source:
- on amd64: URL
- on i386: URL
What is the correct syntax to differentiate them in override-pull
?
ppd
May 20, 2020, 11:05am
7
You have access to SNAPCRAFT_ARCH_TRIPLET
. That should do it.
2 Likes
xnox
July 7, 2021, 11:34am
8
I know that it is a sample, but it still shows bad behavour. Please use apt download
which will verify GPG signatures on hashes of the deb, or please use https
links to download things.
Alternatively it is much better to use pull-pkg
or its variants (pull-lp-debs pull-debian-debs etc) which attempt to do all of the above for you.
2 Likes