| 1 | #!/usr/bin/env bash |
| 2 | # Tag-pipeline publish step (design.md, "v0.1.0 release" decision). |
| 3 | # |
| 4 | # Publishes the release for the tag that started this pipeline with |
| 5 | # POST $CI_API_URL/repos/{owner}/{repo}/releases/{tag}/assets — BlueGit's |
| 6 | # create-only route for an existing tag: an existing release is HTTP 409, it |
| 7 | # never creates, moves or deletes the tag, and the assets are artifacts of |
| 8 | # successful jobs of this same pipeline. `replace` is never sent and the |
| 9 | # tag-creating route POST .../releases is never called. |
| 10 | set -euo pipefail |
| 11 | |
| 12 | : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" "${CI_COMMIT_TAG:?}" |
| 13 | |
| 14 | root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 15 | cd "$root" |
| 16 | version="$(bash scripts/ci/package-version.sh)" |
| 17 | tag="$CI_COMMIT_TAG" |
| 18 | [[ "$tag" == "v$version" ]] || { echo "tag $tag does not match package version $version" >&2; exit 1; } |
| 19 | |
| 20 | b="paperdoll-renderer-${tag}" |
| 21 | asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; } |
| 22 | assets="$(asset package:appimage dist/paperdoll-renderer-x86_64.AppImage "${b}-x86_64.AppImage"),$(asset package:ubuntu dist/paperdoll-renderer_amd64.deb "${b}-amd64.deb"),$(asset package:arch dist/paperdoll-renderer-x86_64.pkg.tar.zst "${b}-x86_64.pkg.tar.zst"),$(asset package:windows dist/paperdoll-renderer-windows-x86_64.zip "${b}-windows-x86_64.zip"),$(asset verify:packages dist/SHA256SUMS "${b}-SHA256SUMS.txt")" |
| 23 | # JSON-escaped already (\n, no double quotes inside). |
| 24 | desc="Paperdoll Renderer ${version}.\n\n* Linux AppImage (portable).\n* Debian/Ubuntu .deb: /usr/bin/paperdoll-renderer, desktop entry, icons, .ppd MIME type.\n* Arch .pkg.tar.zst, built from packaging/arch/PKGBUILD. AUR: paperdoll-renderer-bin.\n* Windows zip (x86_64, MinGW build).\n* SHA256SUMS of the package files.\n\nThe default starter bodies are Animated walking Male Base Mesh and Animated Female Base Mesh by assetfactory (Sketchfab Standard licence); see THIRD_PARTY_NOTICES.md." |
| 25 | body="$(printf '{"name":"Paperdoll Renderer %s","body":"%s","assets":[%s]}' "$tag" "$desc" "$assets")" |
| 26 | |
| 27 | echo "Release $tag on $CI_COMMIT_SHA (existing tag, create-only)" |
| 28 | resp="$(mktemp)" |
| 29 | code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST \ |
| 30 | "$CI_API_URL/repos/$CI_PROJECT_PATH/releases/$tag/assets" \ |
| 31 | -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000 |
| 32 | cat "$resp"; echo |
| 33 | if [[ "$code" != 2* ]]; then |
| 34 | echo "release API returned HTTP $code (see response above)" >&2 |
| 35 | exit 1 |
| 36 | fi |