Co-written with Sergio Costas Rodríguez.
As the number of snaps increases, the need for automation grows. Any automation to help us maintain a group of snaps is welcome and necessary for us to be able to scale. The solution detailed in this article has two main benefits:
This post details the steps taken to standardise snap building automation, and some ongoing tasks to achieve our automation vision: automate all the things!
All of our snap repos live under https://github.com/ubuntu/, so we can use GitHub infrastructure in our automation quest. Using GitHub actions, workflows, and runners, we have been able to automate updates to some extent, and we’re not stopping there!
As shown in the graphic below, the automation consists of four sequential steps:
The desktop-snaps repository contains the core bits needed for coordinating automation across many other snap repositories:
https://github.com/ubuntu/desktop-snaps
While there are several cool things in this repo, I’d like to bring your attention to the heart of our automation, updatesnap/updatesnapyaml.py, and the action that uses it, action.yml.
This script is provided with a repo that contains a snapcraft.yaml and searches each part’s upstream repo for a newer tag than the one being built in the snapcraft.yaml. If you were to run this locally, the required parameters of updatesnapyaml.py are $GITHUB_USER, $GITHUB_TOKEN, and a URL for a snap repository. For example:
$ ./updatesnapyaml.py --github-user $GITHUB_USER --github-token $GITHUB_TOKEN https://github.com/ubuntu/gnome-calculator.git
The tag value in the original snapcraft.yaml is compared to the latest tag available in the (often GNOME) upstream repository. If there is a newer tag upstream, then a new snapcraft.yaml is generated with just this tag change to the newer tag.
This is a GitHub composite action that uses updatesnapyaml.py to take tag changes further. The action commits the updated tag in the snapcraft.yaml change generated by updatesnapyaml.py. This one-line change is then pushed to the snap repo’s main branch.
Note that the action does not do anything by itself; there must be a workflow somewhere calling it to benefit from it.
Each individual snap has its own repository on GitHub. As you may know, GitHub workflows live in the .github/workflows/ directory. Then in the various snap repos, we have put in place an auto-update.yml workflow that utilizes our desktop-snaps action.
Each individual snap has its own repository on GitHub, and it is each of these repositories that has the workflows, that calls the action, to trigger automation awesomeness.
As you may know, GitHub workflows live in the .github/workflows/ directory. Then in the various snap repos, authors place an auto-update.yml workflow that uses the desktop-snaps action.yml discussed in the previous section.
For a snapcraft.yaml to work with our automation tools, a few things need to be in place first:
We wanted to save on the amount of data needing to be transferred from the upstream repo when checking for newer tags, so the snapcraft source-depth line is required for each part that expects to use the automation.
Since the automation is specifically for upstream tags, each part is required to include the source-tag line. If a part is instead tracking a branch, it will not be updated.
As you might expect, neither nil nor dump parts are considered for updates.
What powers do I have to limit tag update options? Many!
If you do not want just the latest tag provided by upstream, you can include metadata in your part to set boundaries. A metadata block should go somewhere in the part you’d like to control. Each line of the metadata starts with a #. Here is an example:
# ext:updatesnap
# version-format:
# lower-than: '45'
# no-9x-revisions: true
Using comments in the part you would like to limit lets you pin the major version, ignore X.90 revisions (which are often development versions not intended for general use), and so much more!
Note that it is not required to use this comment block in a part if you want the latest upstream tag to be applied and committed.
To showcase what is currently in place, let’s take a look at the gnome-calculator example:
https://github.com/ubuntu/gnome-calculator
The auto-update.yml used by gnome-calculator is a boilerplate workflow that can be copied to any project.
name: Push new tag update to stable branch
on:
schedule:
# Daily for now
- cron: '9 7 * * *'
workflow_dispatch:
jobs:
update-snapcraft-yaml:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Run desktop-snaps action
uses: ubuntu/desktop-snaps@stable
with:
token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.repository }}
It’s unnecessary to provide the full snapcraft.yaml here, but I’ll point out the relevant section:
parts:
gnome-calculator:
source: https://gitlab.gnome.org/GNOME/gnome-calculator.git
source-tag: '44.0'
source-depth: 1
# ext:updatesnap
# version-format:
# lower-than: '45'
# no-9x-revisions: true
As you can see, the gnome-calculator part has the required source-tag and source-depth lines.
As previously mentioned, the workflow used in the gnome-calculator repository is a boilerplate one that anyone can copy and paste into their own .github/workflows/ directory. Once it’s available in the main branch, you can manually launch the action or wait for it to happen on the cron schedule. Easy peasy.
We are currently working on implementing test plans using checkbox. While testing apps is currently a manual process in checkbox, we have aspirations to automate this promotion testing with the use of visual aid inspection tools.
https://github.com/ubuntu/desktop-snaps/tree/stable/checkbox-test-plans
If you are a new contributor and would like to help test snaps, or provide more test plans, please go checkout our docs page to learn how you can contribute.
The efforts that have gone into snap automation will improve the scalability and maintainability of any snaps that benefit from the provided automation. This will have the perk of also keeping the user on the latest upstream tag release with minimal manual effort on our side.
Anyone with a GitHub snap repository is welcome and encouraged to use the work Canonical has invested in this automation project. We would love to hear your thoughts! Here are a couple of links to help direct your feedback:
Welcome to the Ubuntu Weekly Newsletter, Issue 883 for the week of March 9 –…
In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…
In this article, we will see how to install clang tool on Ubuntu or Debian…
When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…
You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…
Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…