CI: experimental release replaces itself via BlueGit replace (job token only)
@@ -4,9 +4,11 @@
4
4
# - Only on branch experimental/tspl2; fixed tag experimental-tspl2 (never X.Y.Z).
5
5
# - There is always at most one such release: an existing one is deleted
6
6
# (with its tag and assets) before the new one is created.
7
# - Uses CI_JOB_TOKEN to create. BlueGit only lets user tokens delete releases,
8
# so replacing needs EXPERIMENTAL_RELEASE_TOKEN; without it the job fails
9
# when the release already exists (it never creates a second one).
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.
10
12
# - No AUR, no other secrets.
11
13
set -euo pipefail
12
14
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"
@@ -21,28 +23,11 @@ for f in dist/posprint-experimental-linux-x86_64.tar.gz dist/posprint-experiment
21
23
test -s "$f" || { echo "Missing artifact $f" >&2; exit 1; }
22
24
done
23
25
24
remote="${CI_PROJECT_URL:-${CI_API_URL%/api/v1}/$CI_PROJECT_PATH}.git"
25
exists=0
26
if [[ -n "$(git ls-remote --tags "$remote" "refs/tags/$TAG" 2>/dev/null || true)" ]]; then exists=1; fi
27
if [[ -n "$(git ls-remote --tags origin "refs/tags/$TAG" 2>/dev/null || true)" ]]; then exists=1; fi
28
29
if [[ $exists == 1 ]]; then
30
if [[ -z "${EXPERIMENTAL_RELEASE_TOKEN:-}" ]]; then
31
echo "Release $TAG already exists and EXPERIMENTAL_RELEASE_TOKEN is not set; not creating a second release." >&2
32
exit 1
33
fi
34
echo "Replacing existing release $TAG"
35
code="$(curl -sS -o /dev/null -w '%{http_code}' -X DELETE \
36
"$CI_API_URL/projects/$CI_PROJECT_PATH/releases/$TAG?delete_tag=true" \
37
-H "Authorization: Bearer $EXPERIMENTAL_RELEASE_TOKEN")" || code=000
38
[[ "$code" == 2* || "$code" == 404 ]] || { echo "Delete returned HTTP $code" >&2; exit 1; }
39
fi
40
41
26
asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; }
42
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)"
43
28
short="${CI_COMMIT_SHA:0:8}"
44
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."
45
body="$(printf '{"tag":"%s","commit":"%s","name":"%s","body":"%s","assets":[%s]}' "$TAG" "$CI_COMMIT_SHA" "Experimental: TSPL2 labelprinters (${v})" "$desc" "$assets")"
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")"
46
31
echo "Experimental release $TAG ($v) on $CI_COMMIT_SHA"
47
32
resp="$(mktemp)"
48
33
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \
@@ -4,9 +4,11 @@4
# - Only on branch experimental/tspl2; fixed tag experimental-tspl2 (never X.Y.Z).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 deleted5
# - There is always at most one such release: an existing one is deleted6
# (with its tag and assets) before the new one is created.6
# (with its tag and assets) before the new one is created.7
# - Uses CI_JOB_TOKEN to create. BlueGit only lets user tokens delete releases,7
# - Uses only CI_JOB_TOKEN. An existing release is replaced by BlueGit itself8
# so replacing needs EXPERIMENTAL_RELEASE_TOKEN; without it the job fails8
# ("replace": true): old release, assets and tag go, the new one takes the9
# when the release already exists (it never creates a second one).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. Without11
# replace the API would answer 409, so a second release is never created.10
# - No AUR, no other secrets.12
# - No AUR, no other secrets.11
set -euo pipefail13
set -euo pipefail12
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"14
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"@@ -21,28 +23,11 @@ for f in dist/posprint-experimental-linux-x86_64.tar.gz dist/posprint-experiment21
test -s "$f" || { echo "Missing artifact $f" >&2; exit 1; }23
test -s "$f" || { echo "Missing artifact $f" >&2; exit 1; }22
done24
done23
25
24
remote="${CI_PROJECT_URL:-${CI_API_URL%/api/v1}/$CI_PROJECT_PATH}.git"25
exists=026
if [[ -n "$(git ls-remote --tags "$remote" "refs/tags/$TAG" 2>/dev/null || true)" ]]; then exists=1; fi27
if [[ -n "$(git ls-remote --tags origin "refs/tags/$TAG" 2>/dev/null || true)" ]]; then exists=1; fi28
29
if [[ $exists == 1 ]]; then30
if [[ -z "${EXPERIMENTAL_RELEASE_TOKEN:-}" ]]; then31
echo "Release $TAG already exists and EXPERIMENTAL_RELEASE_TOKEN is not set; not creating a second release." >&232
exit 133
fi34
echo "Replacing existing release $TAG"35
code="$(curl -sS -o /dev/null -w '%{http_code}' -X DELETE \36
"$CI_API_URL/projects/$CI_PROJECT_PATH/releases/$TAG?delete_tag=true" \37
-H "Authorization: Bearer $EXPERIMENTAL_RELEASE_TOKEN")" || code=00038
[[ "$code" == 2* || "$code" == 404 ]] || { echo "Delete returned HTTP $code" >&2; exit 1; }39
fi40
41
asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; }26
asset() { printf '{"job":"%s","path":"%s","name":"%s"}' "$1" "$2" "$3"; }42
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)"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)"43
short="${CI_COMMIT_SHA:0:8}"28
short="${CI_COMMIT_SHA:0:8}"44
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."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."45
body="$(printf '{"tag":"%s","commit":"%s","name":"%s","body":"%s","assets":[%s]}' "$TAG" "$CI_COMMIT_SHA" "Experimental: TSPL2 labelprinters (${v})" "$desc" "$assets")"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")"46
echo "Experimental release $TAG ($v) on $CI_COMMIT_SHA"31
echo "Experimental release $TAG ($v) on $CI_COMMIT_SHA"47
resp="$(mktemp)"32
resp="$(mktemp)"48
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \33
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" \