| 1 | #!/usr/bin/env bash |
| 2 | # Publish a BlueGit release for the tag that started this pipeline. |
| 3 | # |
| 4 | # Syntax checked against docs/CI.md and timfa/posprint scripts/ci/release.sh: |
| 5 | # POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" |
| 6 | # Authorization: Bearer $CI_JOB_TOKEN |
| 7 | # assets: {job, path, name} where path is an artifact of a successful job |
| 8 | # in this pipeline. |
| 9 | # |
| 10 | # Verified limit (timfa/bluegit internal/server/ops_ci.go opPublishRelease and |
| 11 | # release_replace.go checkReplace): if the tag already exists the API returns |
| 12 | # HTTP 409 unless replace=true, and replace=true is rejected with HTTP 403 on |
| 13 | # a tag pipeline. A pipeline started by pushing the tag therefore cannot |
| 14 | # attach these artifacts to that same tag. The script still performs the |
| 15 | # documented call and fails when the response is not 2xx. It does not send |
| 16 | # replace=true, and it does not invent a second tag. |
| 17 | set -euo pipefail |
| 18 | |
| 19 | : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" "${CI_COMMIT_TAG:?}" |
| 20 | |
| 21 | root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 22 | cd "$root" |
| 23 | version="$(bash scripts/ci/package-version.sh)" |
| 24 | |
| 25 | echo "BlueGit release API creates the git tag." >&2 |
| 26 | echo "This pipeline already runs on tag ${CI_COMMIT_TAG}, so today's API returns 409 (tag exists)." >&2 |
| 27 | echo "replace=true is refused on a tag pipeline (403). No second tag is created." >&2 |
| 28 | |
| 29 | asset() { |
| 30 | printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3" |
| 31 | } |
| 32 | |
| 33 | assets="$(asset package:appimage dist/paperdoll-renderer-x86_64.AppImage "paperdoll-renderer-${version}-x86_64.AppImage")" |
| 34 | assets="${assets},$(asset package:ubuntu dist/paperdoll-renderer_amd64.deb "paperdoll-renderer_${version}_amd64.deb")" |
| 35 | assets="${assets},$(asset package:arch dist/paperdoll-renderer-x86_64.pkg.tar.zst "paperdoll-renderer-${version}-1-x86_64.pkg.tar.zst")" |
| 36 | assets="${assets},$(asset package:windows dist/paperdoll-renderer-windows-x86_64.zip "paperdoll-renderer-${version}-windows-x86_64.zip")" |
| 37 | assets="${assets},$(asset verify:packages dist/SHA256SUMS "paperdoll-renderer-${version}-SHA256SUMS")" |
| 38 | |
| 39 | body="Paperdoll Renderer ${version}.\\n\\nFoundation shell only. Import, skeletal animation, paperdoll rendering and the 2D preview are not in this build.\\n\\n* Linux AppImage: paperdoll-renderer-${version}-x86_64.AppImage\\n* Debian/Ubuntu: paperdoll-renderer_${version}_amd64.deb\\n* Arch: paperdoll-renderer-${version}-1-x86_64.pkg.tar.zst\\n* Windows zip: paperdoll-renderer-${version}-windows-x86_64.zip\\n* SHA256SUMS" |
| 40 | |
| 41 | payload="$(printf '{"tag":"%s","commit":"%s","name":"Paperdoll Renderer %s","body":"%s","assets":[%s]}' \ |
| 42 | "$CI_COMMIT_TAG" "$CI_COMMIT_SHA" "$version" "$body" "$assets")" |
| 43 | |
| 44 | response="$(mktemp)" |
| 45 | code="$(curl -sS -o "$response" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \ |
| 46 | -H "Authorization: Bearer $CI_JOB_TOKEN" \ |
| 47 | -H "Content-Type: application/json" \ |
| 48 | -d "$payload")" || code=000 |
| 49 | cat "$response" |
| 50 | echo |
| 51 | if [[ "$code" != 2* ]]; then |
| 52 | echo "Release API returned HTTP ${code}. A 409 on this tag pipeline matches the verified BlueGit limit and is not a published release." >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | echo "release published for ${CI_COMMIT_TAG}" |