| 1 | #!/usr/bin/env bash |
| 2 | # Create the BlueGit release on CI_COMMIT_SHA with the build artifacts as |
| 3 | # assets. The release API creates the tag itself (bare version, e.g. 0.5.9). |
| 4 | set -euo pipefail |
| 5 | : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" |
| 6 | cd "$(dirname "$0")/../.." |
| 7 | v="$(cat artifacts/version.txt)" |
| 8 | [[ "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Invalid version: $v" >&2; exit 1; } |
| 9 | now="$(bash scripts/ci/next-version.sh)" |
| 10 | [[ "$now" == "$v" ]] || { echo "Version $v is already taken (next is $now). Rerun the pipeline." >&2; exit 1; } |
| 11 | asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; } |
| 12 | assets="$(asset build:linux-deb "dist/posprint_${v}-1_amd64.deb" "posprint_${v}-1_amd64.deb"),$(asset build:linux-arch "dist/posprint-${v}-1-x86_64.pkg.tar.zst" "posprint-${v}-1-x86_64.pkg.tar.zst"),$(asset build:linux-arch "dist/posprint-${v}-x86_64.tar.gz" "posprint-${v}-x86_64.tar.gz"),$(asset build:windows dist/posprint.exe posprint.exe)" |
| 13 | desc='* Debian/Ubuntu: posprint_<version>-1_amd64.deb\n* Arch: posprint-<version>-1-x86_64.pkg.tar.zst\n* Linux binary tarball (AUR posprint-bin): posprint-<version>-x86_64.tar.gz\n* Windows: posprint.exe\n\nAUR: posprint, posprint-bin.' |
| 14 | body="$(printf '{"tag":"%s","commit":"%s","name":"posprint %s","body":"%s","assets":[%s]}' "$v" "$CI_COMMIT_SHA" "$v" "$desc" "$assets")" |
| 15 | echo "Release $v on $CI_COMMIT_SHA" |
| 16 | resp="$(mktemp)" |
| 17 | code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \ |
| 18 | -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000 |
| 19 | cat "$resp"; echo |
| 20 | [[ "$code" == 2* ]] || { echo "Release API returned HTTP $code" >&2; exit 1; } |