From cde516671ffc2be8d456faab5aa32c83cecfbe77 Mon Sep 17 00:00:00 2001 From: vii Date: Wed, 2 Dec 2026 14:01:29 -0600 Subject: [PATCH] fix(ci): gate releases on tag version and main, retry flaky installs A release tag must match the CMake VERSION and point at a commit on main. Image pulls, pacman, apt and the Flatpak builder install now retry. --- .github/workflows/build-packages.yml | 40 +++++++++++++++++++++++++--- .github/workflows/flatpak.yml | 28 +++++++++++++++---- .github/workflows/release.yml | 21 +++++++++++++++ scripts/check_release_tag.sh | 35 ++++++++++++++++++++++++ tests/native_packaging_test.sh | 27 ++++++++++++++++++- 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100755 scripts/check_release_tag.sh diff --git a/.github/workflows/build-packages.yml b/.github/workflows/build-packages.yml index 17f8c4d1..b7e855bf 100644 --- a/.github/workflows/build-packages.yml +++ b/.github/workflows/build-packages.yml @@ -54,19 +54,30 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | + image=ghcr.io/archlinux/archlinux:base-devel@sha256:c3953446016873a756fb7814f10087cac1634c127f7302e80c81c512da796d05 + # ghcr.io and the mirrors drop connections; one bad fetch shouldn't fail a release. + for attempt in 1 2 3; do + docker pull "$image" && break + [[ $attempt -lt 3 ]] || exit 1 + sleep $((attempt * 20)) + done docker run --rm \ --volume "$GITHUB_WORKSPACE:/workspace" \ --workdir /workspace \ --env GH_TOKEN \ --env UPINFO \ --env APPIMAGE_NAME \ - ghcr.io/archlinux/archlinux:base-devel@sha256:c3953446016873a756fb7814f10087cac1634c127f7302e80c81c512da796d05 bash -Eeuo pipefail -c ' + "$image" bash -Eeuo pipefail -c ' + for attempt in 1 2 3; do pacman -Syu --noconfirm --needed \ cmake git ninja pkgconf lld sdl3 sdl3_ttf curl openssl \ nlohmann-json libyaml libelf minizip minizip-ng capstone gtk4 \ libadwaita libsecret webkitgtk-6.0 libutf8proc fontconfig libglvnd \ vulkan-headers zlib libplacebo ffmpeg bubblewrap xdg-dbus-proxy \ - patchelf jq unzip file ca-certificates dbus zsync + patchelf jq unzip file ca-certificates dbus zsync && break + [[ $attempt -lt 3 ]] || exit 1 + sleep 20 + done ./scripts/install_anylinux_dependencies.sh @@ -175,12 +186,18 @@ jobs: else version="$(./scripts/package_version.sh)" fi + for attempt in 1 2 3; do + docker pull ubuntu:26.04 && break + [[ $attempt -lt 3 ]] || exit 1 + sleep $((attempt * 20)) + done docker run --rm \ --volume "$GITHUB_WORKSPACE:/workspace" \ --workdir /workspace \ --env MOCKTAIL_PACKAGE_VERSION="$version" \ ubuntu:26.04 bash -Eeuo pipefail -c ' export DEBIAN_FRONTEND=noninteractive + echo "Acquire::Retries \"3\";" >/etc/apt/apt.conf.d/80-retries apt-get update apt-get install --yes --no-install-recommends \ build-essential cmake git ninja-build pkg-config lld fakeroot \ @@ -237,6 +254,11 @@ jobs: else version="$(./scripts/package_version.sh)" fi + for attempt in 1 2 3; do + docker pull "fedora:$FEDORA" && break + [[ $attempt -lt 3 ]] || exit 1 + sleep $((attempt * 20)) + done docker run --rm \ --volume "$GITHUB_WORKSPACE:/workspace" \ --workdir /workspace \ @@ -294,15 +316,25 @@ jobs: version="$(./scripts/package_version.sh)" fi sed -i "s/^pkgver=.*/pkgver=${version}/" packaging/arch/PKGBUILD + image=ghcr.io/archlinux/archlinux:base-devel@sha256:c3953446016873a756fb7814f10087cac1634c127f7302e80c81c512da796d05 + for attempt in 1 2 3; do + docker pull "$image" && break + [[ $attempt -lt 3 ]] || exit 1 + sleep $((attempt * 20)) + done docker run --rm \ --volume "$GITHUB_WORKSPACE:/workspace" \ --workdir /workspace \ - ghcr.io/archlinux/archlinux:base-devel@sha256:c3953446016873a756fb7814f10087cac1634c127f7302e80c81c512da796d05 bash -Eeuo pipefail -c ' + "$image" bash -Eeuo pipefail -c ' + for attempt in 1 2 3; do pacman -Syu --needed --noconfirm \ cmake git ninja pkgconf lld sdl3 sdl3_ttf curl openssl \ nlohmann-json libyaml libelf minizip capstone gtk4 \ libadwaita libsecret webkitgtk-6.0 libutf8proc fontconfig libpng \ - libplacebo ffmpeg vulkan-headers vulkan-icd-loader libglvnd zlib + libplacebo ffmpeg vulkan-headers vulkan-icd-loader libglvnd zlib && break + [[ $attempt -lt 3 ]] || exit 1 + sleep 20 + done useradd --create-home builder chown -R builder:builder /workspace runuser -u builder -- env MOCKTAIL_SOURCE_DIR=/workspace \ diff --git a/.github/workflows/flatpak.yml b/.github/workflows/flatpak.yml index 01187f0a..7e762ce1 100644 --- a/.github/workflows/flatpak.yml +++ b/.github/workflows/flatpak.yml @@ -139,12 +139,30 @@ jobs: shell: bash timeout-minutes: 10 run: | + set -Eeuo pipefail apt_opts=(-o Acquire::Retries=3 -o Acquire::http::Timeout=30) - sudo apt-get "${apt_opts[@]}" update - sudo apt-get "${apt_opts[@]}" install --yes \ - flatpak flatpak-builder gnupg ostree - flatpak remote-add --user --if-not-exists flathub \ - https://dl.flathub.org/repo/flathub.flatpakrepo + packages=(flatpak flatpak-builder gnupg ostree) + download() { + sudo apt-get "${apt_opts[@]}" update && + sudo timeout 180 apt-get "${apt_opts[@]}" install --yes \ + --download-only "${packages[@]}" + } + # Same slow Azure mirror as ci.yml; finished downloads stay cached. + if ! download; then + echo "::warning::Ubuntu mirror too slow, retrying on archive.ubuntu.com" + if [[ -f /etc/apt/apt-mirrors.txt ]]; then + echo "http://archive.ubuntu.com/ubuntu/" | + sudo tee /etc/apt/apt-mirrors.txt >/dev/null + fi + download + fi + sudo apt-get "${apt_opts[@]}" install --yes "${packages[@]}" + for attempt in 1 2 3; do + flatpak remote-add --user --if-not-exists flathub \ + https://dl.flathub.org/repo/flathub.flatpakrepo && break + [[ $attempt -lt 3 ]] || exit 1 + sleep $((attempt * 15)) + done - name: Import signing key if: env.MOCKTAIL_PUBLISH == 'true' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ba8fad2..084e2206 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,28 @@ concurrency: cancel-in-progress: false jobs: + # Catches a mistagged release before anything is built or signed. It runs from + # the tagged commit, so it is no defense against a malicious tag; the "Release + # tags" ruleset, which lets only admins create v* tags, is. + gate: + name: Check release tag + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - name: Check out source + if: startsWith(github.ref, 'refs/tags/v') + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - name: Check tag against VERSION and main + if: startsWith(github.ref, 'refs/tags/v') + shell: bash + run: scripts/check_release_tag.sh "$GITHUB_REF_NAME" origin/main + build: name: Build + needs: [gate] uses: ./.github/workflows/build-packages.yml with: channel: release @@ -23,6 +43,7 @@ jobs: flatpak: name: Flatpak if: startsWith(github.ref, 'refs/tags/v') + needs: [gate] uses: ./.github/workflows/flatpak.yml permissions: contents: read diff --git a/scripts/check_release_tag.sh b/scripts/check_release_tag.sh new file mode 100755 index 00000000..4c4c53d0 --- /dev/null +++ b/scripts/check_release_tag.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# +# Release gate. +# check_release_tag.sh --version prints the CMake project VERSION +# check_release_tag.sh
fails unless is v and +# HEAD is already on
+# Pitfall: a mismatched tag makes the self-updater re-offer that release forever. + +set -Eeuo pipefail + +root="$(git rev-parse --show-toplevel)" +version="$(sed -nE '/^project\(/,/\)/s/^[[:space:]]+VERSION[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)[[:space:]]*$/\1/p' \ + "${root}/CMakeLists.txt")" +if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error::no project VERSION in CMakeLists.txt" >&2 + exit 1 +fi + +if [[ "${1:-}" == --version ]]; then + printf '%s\n' "${version}" + exit 0 +fi + +tag="${1:?usage: check_release_tag.sh }" +main_ref="${2:?usage: check_release_tag.sh }" + +if [[ "${tag}" != "v${version}" ]]; then + echo "::error::tag ${tag} does not match CMakeLists.txt VERSION ${version}" >&2 + exit 1 +fi +if ! git merge-base --is-ancestor HEAD "${main_ref}"; then + echo "::error::${tag} points at a commit that is not on ${main_ref}" >&2 + exit 1 +fi diff --git a/tests/native_packaging_test.sh b/tests/native_packaging_test.sh index b7cd0cc1..8270c84d 100755 --- a/tests/native_packaging_test.sh +++ b/tests/native_packaging_test.sh @@ -107,8 +107,12 @@ grep -Fq 'git describe' "${AUR_PKGBUILD}" || Fail 'AUR VCS package does not version from the release tag' grep -Fq 'git describe' "${AUR_WORKFLOW}" || Fail 'AUR workflow does not version from the release tag' +GATE_SCRIPT="$(realpath -- "${ROOT}/scripts/check_release_tag.sh")" +readonly GATE_SCRIPT +cmake_version="$(cd "${ROOT}" && bash "${GATE_SCRIPT}" --version)" || + Fail 'release gate cannot read the CMake project VERSION' for pkgbuild in "${PKGBUILD}" "${AUR_STABLE_PKGBUILD}" "${AUR_BIN_PKGBUILD}"; do - grep -Fqx 'pkgver=0.5.7' "${pkgbuild}" || + grep -Fqx "pkgver=${cmake_version}" "${pkgbuild}" || Fail "package version does not match the release being prepared: ${pkgbuild}" done @@ -268,6 +272,27 @@ VersionGit tag continuous [[ "$(VersionIn main)" == 0.0.0 ]] || Fail 'a branch does not give the placeholder version' +GateIn() { + (cd "${version_repo}" && bash "${GATE_SCRIPT}" "$@") >/dev/null 2>&1 +} +printf 'project(Nightcap\n VERSION 0.4.0\n LANGUAGES CXX\n)\n' \ + >"${version_repo}/CMakeLists.txt" +VersionGit add CMakeLists.txt +VersionGit commit --quiet -m bump +VersionGit update-ref refs/heads/released HEAD +GateIn v0.4.0 released || + Fail 'release gate refuses a tag that matches the CMake VERSION on main' +! GateIn v0.4.1 released || + Fail 'release gate accepts a tag that does not match the CMake VERSION' +VersionGit commit --quiet --allow-empty -m unmerged +! GateIn v0.4.0 released || + Fail 'release gate accepts a commit that is not on main' +grep -Fq -- 'scripts/check_release_tag.sh "$GITHUB_REF_NAME" origin/main' \ + "${RELEASE_WORKFLOW}" || + Fail 'release workflow does not run the release gate' +[[ "$(grep -Fcx -- ' needs: [gate]' "${RELEASE_WORKFLOW}")" == 2 ]] || + Fail 'release build and Flatpak jobs do not both wait for the release gate' + grep -Fq 'Ubuntu 26.04+' "${README}" || Fail 'README has no Ubuntu source dependency guide' grep -Fq 'Arch Linux' "${README}" ||