From 7627dbe69070221169d74bb01e678cd7cb7d2600 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 9 Oct 2024 17:58:54 +0200 Subject: [PATCH] new: [collabora,nextcloud] add ``upstream-versions`` hook --- collabora/hooks/upstream-versions | 49 +++++++++++++++++++++++++++++++ nextcloud/hooks/upstream-versions | 37 +++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 collabora/hooks/upstream-versions create mode 100755 nextcloud/hooks/upstream-versions diff --git a/collabora/hooks/upstream-versions b/collabora/hooks/upstream-versions new file mode 100755 index 0000000..6d08d17 --- /dev/null +++ b/collabora/hooks/upstream-versions @@ -0,0 +1,49 @@ +#!/bin/bash + +## List upstream available versions in reverse chronological order +## +## These versions information will be the input for the version information +## usually used by the build process. +## A external query of upstream sources will be done. +## + +## This script is launched by ``charm upstream-versions`` and will receive these env variables +## +## +## VERSION_LIMIT ## limit number of version to read +## +## +## The script CWD will be the root of the charm directory +## + +DOCKER_IMAGE_NAME=collabora/code + +semver:normalize() { + local upstream_version="$1" + local version="${upstream_version/./}" + read -r year_month major minor patch <<< ${version//./ } + if ! [ "${#patch}" == 1 ]; then + echo "Error: build number is not a single digit: '${patch}' (upstream: '${upstream_version}')" >&2 + return 1 + fi + if [ "${#major}" -gt 2 ]; then + echo "Error: major number is more than 2 digits: '${major}' (upstream: '${upstream_version}')" >&2 + return 1 + fi + major=$(printf "%02d" ${major}) + echo "${year_month}${major}.${minor}.${patch}" +} + + +upstream:list() { + local limit=${1:-5} + docker-tags-fetch "$DOCKER_IMAGE_NAME" -l "${limit}" -f "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | + sort -rV | + cut -f 1 -d "-" +} + + +while read -r "upstream_version"; do + normalized_version=$(semver:normalize "${upstream_version}") || exit 1 + printf "%s %s\n" "$(semver:normalize "${upstream_version}")" "$upstream_version" +done < <(upstream:list "${VERSION_LIMIT}") diff --git a/nextcloud/hooks/upstream-versions b/nextcloud/hooks/upstream-versions new file mode 100755 index 0000000..d869848 --- /dev/null +++ b/nextcloud/hooks/upstream-versions @@ -0,0 +1,37 @@ +#!/bin/bash + +## List upstream available versions in reverse chronological order +## +## These versions information will be the input for the version information +## usually used by the build process. +## A external query of upstream sources will be done. +## + +## This script is launched by ``charm upstream-versions`` and will receive these env variables +## +## +## VERSION_LIMIT ## limit number of version to read +## +## +## The script CWD will be the root of the charm directory +## + +DOCKER_IMAGE_NAME=nextcloud + +semver:normalize() { + local upstream_version="$1" + echo "$upstream_version" +} + + +upstream:list() { + local limit=${1:-5} + docker-tags-fetch "$DOCKER_IMAGE_NAME" -l "${limit}" -f "^[0-9]+\.[0-9]+\.[0-9]+-apache" | + sort -rV | + cut -f 1 -d "-" +} + + +while read -r "upstream_version"; do + printf "%s %s\n" "$(semver:normalize "${upstream_version}")" "$upstream_version" +done < <(upstream:list "${VERSION_LIMIT}")