[gimp] tools: add a `flatpak-releases` tool for quick testing with Flatpak.



commit 66cfa752917bb946aef35e07b9d75136f0f2a531
Author: Jehan <jehan girinstud io>
Date:   Sat Jan 22 15:43:53 2022 +0100

    tools: add a `flatpak-releases` tool for quick testing with Flatpak.
    
    Sometimes we want to make quick tests on old versions of GIMP.
    Rebuilding from source is definitely still an option, yet with flatpak,
    we have many past builds available easily to us (at time of writing: 19
    stable builds, 12 dev point-release builds and at least 3 nightlies —
    though I seem to have issues with signatures on gnome-nightly right now,
    so maybe there are more!).
    
    There are some command lines needed to check the build history, then to
    install a specific build, which I explained in developer docs (see
    devel-docs/debugging-tips.txt, section "Testing older GIMP versions").
    Yet it's clearly cumbersome and slow so I wrote this script today to
    automatize the process a bit.
    
    Running simply this command will list all available releases on the
    Flathub repository (adding --beta or --nightly will list the development
    releases and nightly builds instead):
    
    $ tools/flatpak-releases
    
    The listing will contain a topic describing the build as well as the
    date, all this prefixed by a number. For instance, this is an excerpt of
    the output for the dev releases:
    
    $ tools/flatpak-releases --beta
     0: Update dependencies (127a0fa7) [2022-01-13 16:59:43 +0000]
     1: Issue #106:  File->Create->From Screenshot not working. (9c831b14) [2021-12-14 21:46:52 +0000]
     2: Release GIMP 2.99.8. (908bf5b0) [2021-10-20 20:29:00 +0000]
     3: Release GIMP 2.99.6. (e04355dd) [2021-04-26 14:08:32 +0000]
     …
    
    The last build updates dependencies, the previous one fixes some
    specific issue and the 2 previous ones are point releases.
    Now say I needed to test/compare some behavior with how it was in 2.99.6
    (e.g. to verify a regression), I would then run:
    
    $ tools/flatpak-releases --beta -3
    
    This would install this specific dev build number 3. In just 2
    easy-to-remember commands and a few seconds, we can therefore list and
    install specific Flatpak builds.

 tools/flatpak-releases | 134 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 134 insertions(+)
---
diff --git a/tools/flatpak-releases b/tools/flatpak-releases
new file mode 100755
index 0000000000..6fa92d8e08
--- /dev/null
+++ b/tools/flatpak-releases
@@ -0,0 +1,134 @@
+#!/bin/bash
+
+# This is a very basic script for developper usage. It has a few known
+# limitations (feel free to send patches for these):
+# - It is targetted at GIMP usage primarily, hence able to check only
+#   Flathub (stable and beta remotes) and GNOME-nightly. Yet some
+#   generity is built-in so you can set your own application ID on
+#   command line and it should work.
+# - It assumes the remotes are named 'flathub', 'flathub-beta' and
+#   'gnome-nightly' (for stable, beta and nightly branches respectively)
+#   as these are the default names proposed by generated .flatpakref
+#   files (SuggestRemoteName field) when first installing software from
+#   this repository. So most people will have these remotes registered
+#   with these names. Yet it could technically be any name locally and
+#   this script is not verifying this.
+# - It also assumes the flathub remotes are installed at all (it can't
+#   search without them being installed and won't install these for
+#   you).
+# - It uses bash because I lazily didn't bother making it portable as
+#   it's really just a tool for core dev testing. Yet we of course
+#   welcome patches if some syntax needs to be rewritten for
+#   portability.
+
+install=-1
+appid=org.gimp.GIMP
+remote='flathub'
+branch='stable'
+prefix='--user'
+for var in "$@"
+do
+  if [[ $var =~ ^-([0-9]+)$ ]]; then
+    install=${BASH_REMATCH[1]}
+  elif [[ $var = '--beta' ]]; then
+    remote='flathub-beta'
+    branch='beta'
+  elif [[ $var = '--nightly' ]]; then
+    remote='gnome-nightly'
+    branch='master'
+  elif [[ $var = '--system' ]]; then
+    prefix='--system'
+  elif [[ $var =~ ^- ]]; then
+    echo "Usage: ./flathub-releases [--beta] [--system] [-X] [org.example.app]"
+    echo
+    echo "List all flatpak builds stored on Flathub or GNOME repository."
+    echo "The builds for org.gimp.GIMP are looked up by default unless"
+    echo "you provide explicitely another AppStream ID."
+    echo
+    echo "Adding a -X number as option install the numbered release"
+    echo "instead of listing them."
+    echo
+    echo "Options:"
+    echo
+    echo "-0: install the last build."
+    echo "-1: install the previous build."
+    echo "-2: install the before-previous build (and so on)."
+    echo
+    echo "--beta: list or install a beta release"
+    echo "--nightly: list or install a nightly release"
+    echo "--system: install as system flatpak (default to user install)"
+    exit 1
+  else
+    appid=$var
+  fi
+done
+
+package_info_cmd="flatpak remote-info $remote $appid"
+package_info=`$package_info_cmd 2>&1`
+got_info="$?"
+if [ "$got_info" -ne 0 ]; then
+  # By default flatpak will just use either the user or system install
+  # depending on what it finds. Funnily the command may fail if the
+  # remote is found not 0 or 1 but 2 times (both on user and system).
+  # Normally it would interactively ask to choose, but in this specific
+  # non-interactive case, it would just silently fail instead. So let's
+  # make a second try on user-installed remote (totally arbitrary
+  # choice).
+  package_info_cmd="flatpak remote-info --user $remote $appid"
+  package_info=`$package_info_cmd 2>&1`
+  got_info="$?"
+fi
+if [ "$got_info" -ne 0 ]; then
+  echo "Flathub query failed with the following error: $package_info"
+  exit 2
+fi
+
+release_number=0
+install_commit=
+while [ "$got_info" -eq 0 ]
+do
+  release_date=`echo "$package_info" | grep Date: |sed 's/^ *Date: //'`
+  release_commit=`echo "$package_info" | grep Commit: |sed 's/^ *Commit: //'`
+  release_subject=`echo "$package_info" | grep Subject: |sed 's/^ *Subject: //'`
+  if [ "$install" -eq -1 ]; then
+    # In non-install mode, just list the whole release.
+    printf "%2d: %s [%s]\n" $release_number "$release_subject" "$release_date"
+  elif [ "$install" -eq "$release_number" ]; then
+    install_commit=$release_commit
+    break
+  fi
+
+  parent_commit=`echo "$package_info" | grep Parent: |sed 's/^ *Parent: //'`
+  release_number=$(( $release_number + 1 ))
+
+  package_info=`$package_info_cmd --commit $parent_commit 2>&1`
+  got_info="$?"
+done
+
+if [ "$install" -ne -1 ]; then
+  if [ -n "$install_commit" ]; then
+    # Flatpak doesn't have a way to install directly a commit, but we
+    # can install then update. This will work whether the flatpak is
+    # already installed or not.
+
+    echo "[1/2] Installing $appid"
+    flatpak install -y $prefix $remote $appid//$branch
+
+    echo "[2/2] Updating to commit '$install_commit' ($release_number's previous build)"
+    flatpak update -y $prefix --commit=$install_commit $appid//$branch
+
+    if [ "$?" -eq 0 ]; then
+      echo "Build $release_number released on $release_date was installed."
+      echo "Build subject: $release_subject"
+      echo "Build commit on $remote: $release_commit"
+    else
+      echo "Failure to install build $release_number released on $release_date."
+      exit 2
+    fi
+  else
+    echo "There was no $release_number's build to install. Aborting."
+    exit 1
+  fi
+fi
+
+exit 0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]