BlueGit

timfa posprint

Files

posprint / scripts / ci / experimental-release.sh

experimental-release.sh

experimental-release.sh 3.4 KiB Download Raw
1#!/usr/bin/env bash
2# Publish the single "Experimental" BlueGit release for experimental/tspl2.
3#
4# - Only on branch experimental/tspl2; fixed tag experimental-tspl2 (never X.Y.Z).
5# - There is always at most one such release: an existing one is deleted
6# (with its tag and assets) before the new one is created.
7# - Uses CI_JOB_TOKEN to create. BlueGit only lets user tokens delete releases,
8# so replacing needs EXPERIMENTAL_RELEASE_TOKEN; without it the job fails
9# when the release already exists (it never creates a second one).
10# - No AUR, no other secrets.
11set -euo pipefail
12: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"
13cd "$(dirname "$0")/../.."
14TAG="experimental-tspl2"
15BRANCH="experimental/tspl2"
16[[ "${CI_COMMIT_BRANCH:-}" == "$BRANCH" ]] || { echo "Refusing: experimental release only from $BRANCH (got '${CI_COMMIT_BRANCH:-}')" >&2; exit 1; }
17[[ ! "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Refusing: version-like tag" >&2; exit 1; }
18v="$(cat artifacts/version.txt)"
19[[ "$v" == *-tspl2.* ]] || { echo "Refusing: not an experimental version: $v" >&2; exit 1; }
20for f in dist/posprint-experimental-linux-x86_64.tar.gz dist/posprint-experimental-windows-x86_64.exe; do
21 test -s "$f" || { echo "Missing artifact $f" >&2; exit 1; }
22done
23
24remote="${CI_PROJECT_URL:-${CI_API_URL%/api/v1}/$CI_PROJECT_PATH}.git"
25exists=0
26if [[ -n "$(git ls-remote --tags "$remote" "refs/tags/$TAG" 2>/dev/null || true)" ]]; then exists=1; fi
27if [[ -n "$(git ls-remote --tags origin "refs/tags/$TAG" 2>/dev/null || true)" ]]; then exists=1; fi
28
29if [[ $exists == 1 ]]; then
30 if [[ -z "${EXPERIMENTAL_RELEASE_TOKEN:-}" ]]; then
31 echo "Release $TAG already exists and EXPERIMENTAL_RELEASE_TOKEN is not set; not creating a second release." >&2
32 exit 1
33 fi
34 echo "Replacing existing release $TAG"
35 code="$(curl -sS -o /dev/null -w '%{http_code}' -X DELETE \
36 "$CI_API_URL/projects/$CI_PROJECT_PATH/releases/$TAG?delete_tag=true" \
37 -H "Authorization: Bearer $EXPERIMENTAL_RELEASE_TOKEN")" || code=000
38 [[ "$code" == 2* || "$code" == 404 ]] || { echo "Delete returned HTTP $code" >&2; exit 1; }
39fi
40
41asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; }
42assets="$(asset exp:build:linux dist/posprint-experimental-linux-x86_64.tar.gz posprint-experimental-linux-x86_64.tar.gz),$(asset exp:build:windows dist/posprint-experimental-windows-x86_64.exe posprint-experimental-windows-x86_64.exe)"
43short="${CI_COMMIT_SHA:0:8}"
44desc="EXPERIMENTAL / PRERELEASE - niet stabiel, niet in AUR.\n\nVersie ${v} van branch ${BRANCH} (commit ${short}).\nTSPL/TSPL2-labelprinters (getest op opmaak, nog niet fysiek): protocol wordt automatisch herkend; labelformaat per printermodel.\n\n* Linux x86_64: posprint-experimental-linux-x86_64.tar.gz\n* Windows x86_64: posprint-experimental-windows-x86_64.exe\n\nDeze release wordt bij elke pipeline op ${BRANCH} vervangen."
45body="$(printf '{"tag":"%s","commit":"%s","name":"%s","body":"%s","assets":[%s]}' "$TAG" "$CI_COMMIT_SHA" "Experimental: TSPL2 labelprinters (${v})" "$desc" "$assets")"
46echo "Experimental release $TAG ($v) on $CI_COMMIT_SHA"
47resp="$(mktemp)"
48code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \
49 -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000
50cat "$resp"; echo
51[[ "$code" == 2* ]] || { echo "Release API returned HTTP $code" >&2; exit 1; }