| 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 only CI_JOB_TOKEN. An existing release is replaced by BlueGit itself |
| 8 | # ("replace": true): old release, assets and tag go, the new one takes the |
| 9 | # same tag. BlueGit only allows that for a job on this (unprotected) branch, |
| 10 | # started by a maintainer, for a release a job on this branch made. Without |
| 11 | # replace the API would answer 409, so a second release is never created. |
| 12 | # - No AUR, no other secrets. |
| 13 | set -euo pipefail |
| 14 | : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" |
| 15 | cd "$(dirname "$0")/../.." |
| 16 | TAG="experimental-tspl2" |
| 17 | BRANCH="experimental/tspl2" |
| 18 | [[ "${CI_COMMIT_BRANCH:-}" == "$BRANCH" ]] || { echo "Refusing: experimental release only from $BRANCH (got '${CI_COMMIT_BRANCH:-}')" >&2; exit 1; } |
| 19 | [[ ! "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Refusing: version-like tag" >&2; exit 1; } |
| 20 | v="$(cat artifacts/version.txt)" |
| 21 | [[ "$v" == *-tspl2.* ]] || { echo "Refusing: not an experimental version: $v" >&2; exit 1; } |
| 22 | for f in dist/posprint-experimental-linux-x86_64.tar.gz dist/posprint-experimental-windows-x86_64.exe; do |
| 23 | test -s "$f" || { echo "Missing artifact $f" >&2; exit 1; } |
| 24 | done |
| 25 | |
| 26 | asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; } |
| 27 | assets="$(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)" |
| 28 | short="${CI_COMMIT_SHA:0:8}" |
| 29 | desc="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." |
| 30 | body="$(printf '{"tag":"%s","commit":"%s","name":"%s","body":"%s","replace":true,"assets":[%s]}' "$TAG" "$CI_COMMIT_SHA" "Experimental: TSPL2 labelprinters (${v})" "$desc" "$assets")" |
| 31 | echo "Experimental release $TAG ($v) on $CI_COMMIT_SHA" |
| 32 | resp="$(mktemp)" |
| 33 | code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \ |
| 34 | -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000 |
| 35 | cat "$resp"; echo |
| 36 | [[ "$code" == 2* ]] || { echo "Release API returned HTTP $code" >&2; exit 1; } |