From 766292a1c376a302d9ac1b3ead53d92958550a53 Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Fri, 4 Dec 2026 12:23:31 +0100 Subject: [PATCH] ci(release): run the build and both releases from a Gitea workflow The official build and its two publications were started by hand, so a VERSION bump could stay unpublished indefinitely. Touching VERSION on Main now starts the workflow, which asks release.sh whether the version line actually changed, then builds and opens the Gitea and GitHub releases with the ISO attached. --- .gitea/workflows/release.yml | 83 ++++++++++++++++++++++++++++++++++++ release.sh | 50 ++++++++++++++++++++-- 2 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..8764453 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,83 @@ +name: Release + +# Publishes a new version line: official build, then the release on Gitea and +# on GitHub with the ISO attached. +# +# Triggered when VERSION changes on Main (an intermediate commit that touches +# other files as well does not fire it), and manually from the Actions tab. +on: + push: + branches: [Main] + paths: + - VERSION + workflow_dispatch: + inputs: + variant: + description: "Variante de l'ISO (cli, kde, gnome…)" + required: false + default: cli + force: + description: "Publier même sans changement de ligne de version" + type: boolean + default: false + +# One release at a time: a build holds root, loop devices and ~20 min. +concurrency: + group: release + cancel-in-progress: false + +jobs: + release: + # mkarchiso needs an Arch host (pacman, chroot, loop mounts) and root, so + # the build machine itself must be the runner. It has to be registered + # with these labels and allow passwordless sudo. + runs-on: [self-hosted, arch] + timeout-minutes: 180 + + steps: + - name: Récupérer le dépôt avec ses tags + uses: actions/checkout@v4 + with: + # The version-line rule reads the released tags. + fetch-depth: 0 + + - name: Faut-il publier ? + id: check + env: + FORCE: ${{ inputs.force }} + run: | + if [ "${FORCE}" = "true" ]; then + ./release.sh --check --force + else + ./release.sh --check + fi + + - name: Pré-vol du runner + if: steps.check.outputs.publish == 'true' + run: | + for c in bash curl jq git sudo; do + command -v "${c}" >/dev/null 2>&1 \ + || { echo "::error::${c} absent du runner"; exit 1; } + done + sudo -n true 2>/dev/null \ + || { echo "::error::sudo sans mot de passe requis (mkarchiso tourne en root)"; exit 1; } + + - name: Build officiel et publication + if: steps.check.outputs.publish == 'true' + env: + # Gitea Actions fournit GITHUB_TOKEN (token du dépôt) : il suffit + # quand il peut écrire les releases. Sinon, secrets.FWS_GITEA_TOKEN. + GITEA_TOKEN: ${{ secrets.FWS_GITEA_TOKEN || secrets.GITHUB_TOKEN }} + # PAT GitHub avec le droit de créer des releases sur fws-linux/ISO. + GITHUB_TOKEN: ${{ secrets.FWS_GITHUB_TOKEN }} + VARIANT: ${{ inputs.variant || 'cli' }} + run: ./release.sh --variant "${VARIANT}" + + - name: Résumé + if: steps.check.outputs.publish == 'true' + run: | + { + echo "### FWS $(cat VERSION)" + echo "" + echo "ISO : $(ls -1t out/v*/v*/*.iso 2>/dev/null | head -1)" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/release.sh b/release.sh index c7a5b3b..1f98629 100755 --- a/release.sh +++ b/release.sh @@ -46,6 +46,7 @@ VARIANT="" SKIP_BUILD=0 DRY_RUN=0 FORCE=0 +CHECK=0 usage() { cat <<'EOF' @@ -55,6 +56,9 @@ Usage : ./release.sh [options] --skip-build Réutilise l'ISO déjà présente dans out/ (retry d'upload). --force Publie même sans changement de ligne de version. --dry-run N'exécute ni le build ni les appels réseau ; montre le plan. + --check Décide seulement s'il faut publier (code retour 0 dans tous + les cas ; 'publish=true|false' écrit dans $GITHUB_OUTPUT). + Mode utilisé par le workflow .gitea/workflows/release.yml. -h, --help Cette aide. Environnement : @@ -71,6 +75,7 @@ while [ $# -gt 0 ]; do --skip-build) SKIP_BUILD=1; shift ;; --force) FORCE=1; shift ;; --dry-run) DRY_RUN=1; shift ;; + --check) CHECK=1; shift ;; -h|--help) usage; exit 0 ;; *) die "Option inconnue : $1 (voir --help)." ;; esac @@ -99,14 +104,32 @@ elif [ "$PREV_VERSION" = "$VERSION" ] && [ "$FORCE" -eq 0 ]; then MODE="retry" info "Version $VERSION déjà taguée — reprise (release mise à jour, asset manquant réenvoyé)." elif [ "${PREV_VERSION%.*}" = "${MAJOR}.${MINOR}" ] && [ "$FORCE" -eq 0 ]; then + # Not an error: the workflow calls --check on every VERSION change and + # must still get an explicit publish=false here. + MODE="skip" info "VERSION $VERSION reste sur la ligne ${MAJOR}.${MINOR} (dernier tag : $PREV_VERSION)." echo " Une release n'est publiée qu'au changement de ligne (0.8.* → 0.9.*). --force pour publier quand même." - exit 0 + [ "$CHECK" -eq 1 ] || exit 0 +elif [ "${PREV_VERSION%.*}" = "${MAJOR}.${MINOR}" ]; then + MODE="release" + info "Publication forcée sur la ligne ${MAJOR}.${MINOR} (version publiée : $VERSION)." else MODE="release" info "Nouvelle ligne de version : ${PREV_VERSION%.*} → ${MAJOR}.${MINOR} (version publiée : $VERSION)." fi +# The workflow asks here and nowhere else, so the rule lives in one place. +if [ "$CHECK" -eq 1 ]; then + if [ "$MODE" = "release" ] || [ "$MODE" = "retry" ]; then + PUBLISH=true + else + PUBLISH=false + fi + echo "publish=$PUBLISH" + [ -z "${GITHUB_OUTPUT:-}" ] || echo "publish=$PUBLISH" >> "$GITHUB_OUTPUT" + exit 0 +fi + # ─── Contrôles locaux ──────────────────────────────────────────────────────── for cmd in git curl jq; do command -v "$cmd" >/dev/null 2>&1 \ @@ -117,7 +140,9 @@ done # The release tag is created remotely from target_commitish, so HEAD must # already exist on the remote: tagging an unpushed commit fails at the API. -if [ "$DRY_RUN" -eq 0 ]; then +# In CI the workflow is triggered by the pushed commit itself, and a shallow +# runner checkout has no usable origin/Main to compare against. +if [ "$DRY_RUN" -eq 0 ] && [ -z "${CI:-}" ] && [ -z "${GITHUB_ACTIONS:-}" ]; then info "Vérification que HEAD est publié sur origin/Main…" git -C "$WORK_DIR" fetch -q origin Main 2>/dev/null || warn "git fetch impossible (réseau ?)." if git -C "$WORK_DIR" rev-parse -q --verify origin/Main >/dev/null; then @@ -193,6 +218,22 @@ preflight_forges() { die "GitHub : le token n'a pas le droit d'écrire sur $GH_REPO." fi success "GitHub accessible." + + # The GitHub repo mirrors releases only: its history is unrelated to this + # one, so the built commit may not exist there. The release API rejects an + # unknown target_commitish, so the tag is left on GitHub's default branch + # when ours is absent (the ISO asset is what users download either way). + request -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + "$GH_API/repos/$GH_REPO/commits/$HEAD_SHA" + if [ "$HTTP_CODE" = "200" ]; then + GH_TARGET="$HEAD_SHA" + success "GitHub : le commit $HEAD_SHA y est présent, le tag le pointera." + else + GH_TARGET="" + warn "GitHub : commit $HEAD_SHA absent du dépôt — le tag y suivra sa branche par défaut." + fi } if [ "$DRY_RUN" -eq 1 ]; then @@ -386,9 +427,10 @@ publish_github() { || { pub_err "GitHub : mise à jour de la release impossible (HTTP $HTTP_CODE) — $(echo "$HTTP_BODY" | head -c 200)"; return 1; } else local payload - payload="$(jq -n --arg tag "$TAG" --arg target "$HEAD_SHA" \ + payload="$(jq -n --arg tag "$TAG" --arg target "${GH_TARGET:-}" \ --arg name "FWS $VERSION" --arg body "$BODY" \ - '{tag_name:$tag, target_commitish:$target, name:$name, body:$body, draft:false, prerelease:false}')" + '{tag_name:$tag, name:$name, body:$body, draft:false, prerelease:false} + + (if $target != "" then {target_commitish:$target} else {} end)')" gh_api POST "/repos/$GH_REPO/releases" \ -H 'Content-Type: application/json' --data-binary "$payload" [ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "200" ] \