Files
marqdo-prove/scripts/release-beta.sh
T
marqdo-prove 1a9f3a4c78
ci/woodpecker/push/main Pipeline was successful
ci/woodpecker/tag/main Pipeline was successful
ci/woodpecker/manual/contract Pipeline was successful
release: parse the Gitea repository id with JSON instead of sed (avoid nested id ambiguity)
2026-11-26 12:54:01 +08:00

156 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Beta release driver for marqdo-prove.
#
# Preconditions:
# * local gates already passed (fmt, clippy -D warnings, cargo test, and the
# dedicated Lean acceptance suite where applicable);
# * `.secrets/release.env` exists locally with the release/CI credentials
# (ignored by git; never commit or echo it).
#
# What it does:
# * verifies the version in Cargo.toml is a pre-release (<x.y.z>-beta.<n>);
# * runs the local Rust gates;
# * tags `v<version>` if missing;
# * pushes master and the tag with a transient environment credential helper;
# * idempotently activates the repository in Woodpecker;
# * creates or updates the Gitea prerelease for the tag from CHANGELOG.md.
#
# It never prints tokens, never writes credentials to disk, and never commits.
set -euo pipefail
repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$repo_root"
secrets_file=${MARQDO_RELEASE_ENV:-"$repo_root/.secrets/release.env"}
if [ ! -f "$secrets_file" ]; then
echo "error: $secrets_file is missing (local-only credentials; see docs/RELEASE.md)" >&2
exit 2
fi
# shellcheck disable=SC1090
set -a
. "$secrets_file"
set +a
: "${MARQDO_GIT_USERNAME:?missing MARQDO_GIT_USERNAME}"
: "${MARQDO_GIT_TOKEN:?missing MARQDO_GIT_TOKEN}"
: "${MARQDO_WOODPECKER_URL:?missing MARQDO_WOODPECKER_URL}"
: "${MARQDO_WOODPECKER_TOKEN:?missing MARQDO_WOODPECKER_TOKEN}"
version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -1)
case "$version" in
*-beta.*) ;;
*)
echo "error: version '$version' is not a beta pre-release; refusing to tag" >&2
exit 2
;;
esac
tag="v$version"
git_repo="https://git.cflmy.cn/cflmy/marqdo-prove.git"
gitea_api="https://git.cflmy.cn/api/v1/repos/cflmy/marqdo-prove"
# Transient credential helper: the token stays in the environment and is not
# part of the invocation argv or any stored remote URL.
helper='!f() { test "$1" = get || exit 1; echo "username=${MARQDO_GIT_USERNAME}"; echo "password=${MARQDO_GIT_TOKEN}"; }; f'
git_push() {
git -c credential.helper="$helper" push "$git_repo" "$@"
}
echo "== local gates"
cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings
cargo test --locked
echo "== git tree must be clean"
if [ -n "$(git status --porcelain)" ]; then
echo "error: working tree is dirty; commit first" >&2
git status --short >&2
exit 2
fi
echo "== tag $tag"
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
echo "tag $tag already exists locally"
else
git tag -a "$tag" -m "marqdo-prove $version (beta)"
fi
echo "== push master and $tag"
git_push HEAD:refs/heads/master
git_push "refs/tags/$tag:refs/tags/$tag"
gitea_id=$(timeout 30 curl -sS -H "Authorization: token $MARQDO_GIT_TOKEN" "$gitea_api" |
python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])' 2>/dev/null || true)
if [ -z "$gitea_id" ]; then
echo "warning: could not read the Gitea repository id; skipping Woodpecker activation" >&2
else
echo "== activate Woodpecker repository (forge_remote_id=$gitea_id, idempotent)"
timeout 60 curl -sS -o /dev/null -w "activate: HTTP %{http_code}\n" \
-X POST -H "Authorization: Bearer $MARQDO_WOODPECKER_TOKEN" \
"$MARQDO_WOODPECKER_URL/api/repos?forge_remote_id=$gitea_id" || true
fi
echo "== Gitea prerelease"
notes_file=$(mktemp)
trap 'rm -f "$notes_file"' EXIT
{
echo "Beta release of marqdo-prove \`$version\`."
echo
echo "The first real, link-driven proof pipeline is usable and independently"
echo "verified on the recorded environment, but the full stable-release gates"
echo "are not all met. See \`docs/RELEASE.md\` and \`docs/STATUS.md\` in the tag."
echo
sed -n '/^## v/,$p' CHANGELOG.md | head -90
} > "$notes_file"
python3 - "$notes_file" "$tag" "$version" "$gitea_api" <<'PY'
import json
import os
import sys
import urllib.error
import urllib.request
notes_path, tag, version, api = sys.argv[1:]
with open(notes_path, encoding="utf-8") as handle:
body = handle.read()
payload = {
"tag_name": tag,
"target_commitish": "master",
"name": f"marqdo-prove {version} (beta)",
"body": body,
"draft": False,
"prerelease": True,
}
token = os.environ["MARQDO_GIT_TOKEN"]
headers = {
"Authorization": f"token {token}",
"Content-Type": "application/json",
"Accept": "application/json",
}
created = False
request = urllib.request.Request(
f"{api}/releases",
data=json.dumps(payload).encode(),
method="POST",
headers=headers,
)
try:
with urllib.request.urlopen(request, timeout=30) as response:
data = json.load(response)
print(f"create release: HTTP {response.status} {data.get('html_url')}")
created = True
except urllib.error.HTTPError as error:
print(f"create release failed: HTTP {error.code}", file=sys.stderr)
if not created:
request = urllib.request.Request(
f"{api}/releases/tags/{tag}",
data=json.dumps(payload).encode(),
method="PATCH",
headers=headers,
)
with urllib.request.urlopen(request, timeout=30) as response:
data = json.load(response)
print(f"update release: HTTP {response.status} {data.get('html_url')}")
PY
echo "== done: $tag pushed; see docs/RELEASE.md §5 for CI details"