#!/usr/bin/env bash # Create the BlueGit release on CI_COMMIT_SHA with the build artifacts as # assets. The release API creates the tag itself (bare version, e.g. 0.5.9). set -euo pipefail : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" cd "$(dirname "$0")/../.." v="$(cat artifacts/version.txt)" mkdir -p artifacts skip() { echo "No release: $1"; echo skip > artifacts/released.txt; exit 0; } # Never release twice: not when HEAD already carries a tag, and not when only # docs/CI files changed since the last version tag. git fetch -q --tags origin 2>/dev/null || true if [[ -n "$(git tag --points-at HEAD)" ]]; then skip "HEAD is already tagged ($(git tag --points-at HEAD | tr '\n' ' '))"; fi last="$(git tag -l | sed 's/^v//' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1 || true)" if [[ -n "$last" ]]; then lt="$(git tag -l "$last" "v$last" | head -n1)" changed="$(git diff --name-only "$lt" HEAD -- . ':(exclude)*.md' ':(exclude)docs/' ':(exclude)blue-ci-cd.yml' ':(exclude).gitlab-ci.yml' ':(exclude).cursor/' || true)" [[ -n "$changed" ]] || skip "only docs/CI changed since $lt" fi [[ "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Invalid version: $v" >&2; exit 1; } now="$(bash scripts/ci/next-version.sh)" [[ "$now" == "$v" ]] || { echo "Version $v is already taken (next is $now). Rerun the pipeline." >&2; exit 1; } asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; } assets="$(asset build:linux-deb dist/amd64.deb "posprint_${v}-1_amd64.deb"),$(asset build:linux-arch dist/x86_64.pkg.tar.zst "posprint-${v}-1-x86_64.pkg.tar.zst"),$(asset build:linux-arch dist/x86_64-bin.tar.gz "posprint-${v}-x86_64.tar.gz"),$(asset build:windows dist/posprint.exe posprint.exe),$(asset build:macos dist/macos-universal.zip "posprint-${v}-macos-universal.zip")" notes="" if [[ -s RELEASE_NOTES.md ]]; then notes="$(python3 -c 'import json,sys;print(json.dumps(open("RELEASE_NOTES.md").read().strip()+"\n\n")[1:-1])' 2>/dev/null || sed ':a;N;$!ba;s/\\/\\\\/g;s/"/\\"/g;s/\n/\\n/g' RELEASE_NOTES.md)\n\n"; fi desc="${notes}"'* Debian/Ubuntu: posprint_-1_amd64.deb\n* Arch: posprint--1-x86_64.pkg.tar.zst\n* Linux binary tarball (AUR posprint-bin): posprint--x86_64.tar.gz\n* Windows: posprint.exe\n* macOS (universal, niet ondertekend): posprint--macos-universal.zip\n\nAUR: posprint, posprint-bin.' body="$(printf '{"tag":"%s","commit":"%s","name":"posprint %s","body":"%s","assets":[%s]}' "$v" "$CI_COMMIT_SHA" "$v" "$desc" "$assets")" echo "Release $v on $CI_COMMIT_SHA" resp="$(mktemp)" code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \ -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000 cat "$resp"; echo [[ "$code" == 2* ]] || { echo "Release API returned HTTP $code" >&2; exit 1; } echo "$v" > artifacts/released.txt