Skip to content

Commit

Permalink
Add versioning automation (#25)
Browse files Browse the repository at this point in the history
Added a scriptlet to the "foomatic-db" part in snapcraft.yaml to do an
automatic versioning. The use of the scriptlet is made use of by the
"adopt-info: foomatic-db" 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 foomatic-db. Revisions
  which keep the included foomatic-db version but do other changes, like
  build method patches, the other included software packages, like
  Ghostscript, cups-filters, QPDF, ... increase the added package
  release number, which is added to the upstream version number with a
  dash. Current version number is 20240110-1.

- foomatic-db is always pulled from the GIT. To grab a release, "source-tag:
  20240110" is added, with the release tag of the GIT repository of
  foomatic-db. In this case the upstream version number of the Snap is the
  one of the included foomatic-db.

- To grab a GIT snapshot between releases, the "source-tag: ..." line
  hast 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 foomatic-db
  release with added "+gitN.gXXXXXXXXX", where N is the number of
  commits with 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.

- 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 foomatic-db 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.

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 22, 2024
1 parent d2a1e51 commit 93d17c0
Showing 1 changed file with 58 additions and 12 deletions.
70 changes: 58 additions & 12 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ parts:
- --with-drivers=ps2write
- --enable-freetype
- --without-tesseract
- --without-gpdl
- --without-pcl
- --without-xps
- --datarootdir=/snap/ps-printer-app/current/usr/share/
stage-packages:
- libpaper1
Expand Down Expand Up @@ -532,8 +535,6 @@ parts:
source-type: git
source-tag: '20240109'
source-depth: 1
# Excluding foomatic-git from the update automation process
# as it lacks any official releases.
# ext:updatesnap
# version-format:
# format: '%V'
Expand All @@ -543,12 +544,10 @@ parts:
# Do the actual pull task
craftctl default
# Settings:
# Grade: stable/devel
GRADE=stable
# Package release number (integer)
PACKAGERELEASE=1
# Current upstream version of foomatic-db
#
# Force channel: auto/devel/edge/stable
CHANNEL=stable
# Force package release number (integer) or "auto"
PACKAGERELEASE=auto
# As foomatic-db is simply a collection of printer data and not
# some software which is under continuous development and
# milestones of the development turn into releases, it is simply
Expand All @@ -560,13 +559,59 @@ parts:
# the day after the day of the execution of the pull task of
# this part as the version number (this is the version in which
# the current GIT state would land).
sec_after_epoch=`date +%s`
upstreamversion="`date -d @$(( $sec_after_epoch + 86400 )) +%Y%m%d`"
# Time stamp of Snap build in Snap Store
snapbuilddatehuman=`curl -s -H 'Snap-Device-Series: 16' https://api.snapcraft.io/v2/snaps/info/ps-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/ps-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/ps-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 foomatic-db
# Assuming release tags are in the format YYYYMMDD
upstreamversion="$(git describe --tags --always | sed -e 's/^v//;s/-/+git/;s/\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1\2\3/')"
# 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"
override-build: |
set -eux
# Remove non-PostScript manufacturer PPD files
Expand All @@ -587,6 +632,7 @@ parts:
- perl-base
- python3
- xz-utils
- jq
stage-packages:
- python3
- xz-utils
Expand Down

0 comments on commit 93d17c0

Please sign in to comment.