Skip to content

Commit

Permalink
Added versioning automation (#6)
Browse files Browse the repository at this point in the history
Added a scriptlet to the "gutenprint" part in snapcraft.yaml to do an
automatic versioning. The use of the scriptlet is made use of by the
"adopt-info: gutenprint" entry in snapcraft.yaml.

It follows a versioning policy like this (which is very similar to the
one of Debian packages):

- Base version is the upstream version of the included Gutenprint. Revisions
  which keep the included Gutenprint version but do other changes, like
  build method patches, the other included software packages, like
  Ghostscript, cups-filters, ... increase the added package
  release number, which is added to the upstream version number with a
  dash. Current version number is 5.3.4-1.

- To grab a GIT snapshot between releases, the "source-tag: ..." line
  has to get commented out. to get the top of the GIT repository. In this case
  the upstream version number is the version number of the last Gutenprint
  release with added "+gitN.gXXXXXXXXX", where N is the number of
  commits which happened after the release and XXXXXXXXX is the commit
  ID. N is important to make the version number of a newer commit
  actually be considered newer (not tested yet).

- If a new Snap is built with the same upstream version of the newest
  Snap currently in the Snap Store, the package release number is
  automatically increased by 1. In case of a new upstream release being
  used, the package release number will get reset to 1.

- To reliably determine the version number of the currently available Snap and
  to avoid random package release number increases for each architecture,
  we always check the current version number of the Snap of the same
  architecture which we are currently building for.

- We do not bump the package release number if the current upload in the
  Snap Store is newer than the last GIT commit, as that would mean that the
  auto build is not triggered by the GIT commit but by clicking the "Rebuild"
  button in the Snap Store's web interface, meaning that we are doing a
  no-change-rebuild. Then we do not want to have a new package release
  number.

- Snaps built of released Guenprint Debian package versions are considered
  stable and get the "stable" grade and Snaps based on GIT snapshots are
  considered development snapshots and get the "devel" grade.

- Grade and package release number can get manually overridden.

- Added jq and libtool-bin to the `build-packages:` of the "gutenprint" part.
  They are needed for the versioning automation.

- Updated Gutenprint `./configure` parameters to skip building the
  documentation, which is not needed in the Snap

- Updated Ghostscript `./configure` parameters to exclude components
  unnecessary for this Snap.

This kind of versioning is also planned to be used by the other Snaps
at OpenPrinting. It is especially suitable also if the Snap packaging
is a repository separate from the underlying upstream project.

The versioning is especially introduced now to get a consistent
versioning of the Snaps, especially also as we are working towards
Ubuntu Core Desktop, an all-Snap Desktop distribution.

After some testing we are also considering to move versioning
automation into the ubuntu/desktop-snaps GitHub action (the
one hosting Snap update automation on new upstream releases)
to apply this automation on a wider range of Snaps.
  • Loading branch information
rudra-iitm authored Jan 24, 2024
1 parent 0f73732 commit 93ce29e
Showing 1 changed file with 59 additions and 11 deletions.
70 changes: 59 additions & 11 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ parts:
- --with-drivers=cups,pwgraster,ps2write
- --enable-freetype
- --without-tesseract
- --without-gpdl
- --without-xps
- --without-pcl
- --datarootdir=/snap/gutenprint-printer-app/current/usr/share/
stage-packages:
- libpaper1
Expand Down Expand Up @@ -465,25 +468,68 @@ parts:
- --disable-test
- --disable-testpattern
- --enable-nls
- --without-doc
override-pull: |
set -eux
# Do the actual pull task
craftctl default
# Settings:
# Grade: stable/devel
GRADE=stable
# Package release number (integer)
PACKAGERELEASE=1
# Current upstream version of Gutenprint
major=`cat configure.ac | grep pushdef | grep '\[GUTENPRINT_MAJOR_VERSION\]' | perl -p -e 's/^.*?\[(\d+)\].*$/\1/'`
minor=`cat configure.ac | grep pushdef | grep '\[GUTENPRINT_MINOR_VERSION\]' | perl -p -e 's/^.*?\[(\d+)\].*$/\1/'`
patch=`cat configure.ac | grep pushdef | grep '\[GUTENPRINT_MICRO_VERSION\]' | perl -p -e 's/^.*?\[(\d+)\].*$/\1/'`
upstreamversion="$major.$minor.$patch"
# Force channel: auto/devel/edge/stable
CHANNEL=stable
# Force package release number (integer) or "auto"
PACKAGERELEASE=auto
# Time stamp of Snap build in Snap Store
snapbuilddatehuman=`curl -s -H 'Snap-Device-Series: 16' https://api.snapcraft.io/v2/snaps/info/gutenprint-printer-app | jq -r '."channel-map" | .[] | select(.channel.name == "edge") | select(.channel.architecture == "amd64") | ."created-at"'`
snapbuilddate=`date +%s --date=$snapbuilddatehuman`
if [ -z "$snapbuilddate" ]; then
snapbuilddate=0
fi
# Time stamp of the last GIT commit of the snapping repository
pushd $CRAFT_PROJECT_DIR
gitcommitdate=`git log -1 --date=unix | grep Date: | perl -p -e 's/Date:\s*//'`
popd
if [ -z "$gitcommitdate" ]; then
gitcommitdate=0
fi
# Previous stable and development version
prevstable="$(curl -s -H 'Snap-Device-Series: 16' https://api.snapcraft.io/v2/snaps/info/gutenprint-printer-app | jq -r '."channel-map" | .[] | select(.channel.name == "stable") | select(.channel.architecture == "'$CRAFT_TARGET_ARCH'") | .version')"
if [ -z "$prevstable" ]; then
prevstable=0
fi
prevdevel="$(curl -s -H 'Snap-Device-Series: 16' https://api.snapcraft.io/v2/snaps/info/gutenprint-printer-app | jq -r '."channel-map" | .[] | select(.channel.name == "edge") | select(.channel.architecture == "'$CRAFT_TARGET_ARCH'") | .version')"
if [ -z "$prevdevel" ]; then
prevdevel=0
fi
# Previous version in general
dpkg --compare-versions "$prevdevel" lt "$prevstable" && prevversion=$prevstable || prevversion=$prevdevel
# Current upstream version of gutenprint
upstreamversion="$(git describe --tags --always | sed -E 's/^gutenprint-([0-9]+_[0-9]+_[0-9]+).*$/\1/; s/_/\./g')"
# Determine package release number
if test "x$PACKAGERELEASE" = "xauto"; then
packagerelease=`echo "$prevversion" | perl -p -e 's/^('"$upstreamversion"'\-(\d+)|.*)$/\2/'`
if [ -z "$packagerelease" ]; then
packagerelease=1
else
if test "$gitcommitdate" -gt "$snapbuilddate"; then
packagerelease=$(( $packagerelease + 1 ))
fi
fi
else
packagerelease=$PACKAGERELEASE
fi
# Compose version string
version="$upstreamversion-$PACKAGERELEASE"
version="$upstreamversion-$packagerelease"
# Select channel
if test "x$CHANNEL" = "xedge" -o "x$CHANNEL" = "xdevel"; then
grade=devel
elif test "x$CHANNEL" = "xstable"; then
grade=stable
else
[ -n "$(echo $version | grep "+git")" ] && grade=devel || grade=stable
fi
# Set version and grade
craftctl set version="$version"
craftctl set grade="$GRADE"
craftctl set grade="$grade"
build-packages:
- byacc
- libreadline-dev
Expand All @@ -492,6 +538,8 @@ parts:
- flex
- gettext
- chrpath
- libtool-bin
- jq
organize:
snap/gutenprint-printer-app/current/usr/share: usr/share
usr/lib/cups/filter/rastertogutenprint.5.3: usr/lib/gutenprint-printer-app/filter/rastertogutenprint.5.3
Expand Down

0 comments on commit 93ce29e

Please sign in to comment.