From a6f03e95477dfc7b2db87129b525592dd1e1b22e Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Wed, 29 Jul 2026 13:57:44 +0300 Subject: [PATCH] build(just): move release-push into a script --- justfile | 12 +-------- tools/release-push.sh | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 tools/release-push.sh diff --git a/justfile b/justfile index c9137c4f..3813bcc7 100644 --- a/justfile +++ b/justfile @@ -98,17 +98,7 @@ release-prepare version: # Maintainer use only. [group('release')] release-push version remote="origin": - git add assets/freedesktop/org.zealdocs.zeal.appdata.xml.in CMakeLists.txt - git diff --staged --quiet || git commit -m "chore: release v{{version}}" - # Annotated: `git describe` without `--tags` ignores lightweight tags, and - # the AUR zeal-git package derives its version that way. - git rev-parse -q --verify refs/tags/v{{version}} > /dev/null || git tag -a v{{version}} -m "v{{version}}" - git push {{remote}} HEAD - gh release create v{{version}} --draft --notes-file build/release-notes.md \ - --repo "$(git remote get-url {{remote}} | sed -E 's|^.*github\.com[:/]||; s|\.git$||')" - git push {{remote}} v{{version}} - @echo "Pushed v{{version}} with draft release. CI will upload artifacts." - @echo "Approve the 'release' environment to let the Windows jobs run." + bash tools/release-push.sh {{version}} {{remote}} # Delete the draft release, the remote tag, and the local tag for a version, # undoing `just release-push` so it can be run again. Refuses to delete a diff --git a/tools/release-push.sh b/tools/release-push.sh new file mode 100644 index 00000000..ae89026c --- /dev/null +++ b/tools/release-push.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# release-push.sh - Commit, tag, and push a prepared release. +# +# SPDX-FileCopyrightText: Oleg Shparber, et al. +# SPDX-License-Identifier: MIT +# +# Commits the appdata and version bump left by release-prepare.sh, pushes the +# branch, creates the draft GitHub release from the generated notes, then tags +# and pushes the tag, which starts the build CI. The commit and tag steps are +# skipped if already done, so the same version can go to a fork first and then +# be promoted to upstream. +# +# Usage: tools/release-push.sh [remote] +# + +set -euo pipefail +trap 'echo "ERROR: failed at line ${LINENO}: ${BASH_COMMAND}" >&2' ERR + +if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then + echo "Usage: $0 [remote]" >&2 + exit 2 +fi + +VERSION="$1" +REMOTE="${2:-origin}" +TAG="v${VERSION}" + +if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version: '${VERSION}'. Expected major.minor.patch (e.g. 0.9.0)." >&2 + exit 2 +fi + +repo=$(git remote get-url "$REMOTE" | sed -E 's|^.*github\.com[:/]||; s|\.git$||') + +git add assets/freedesktop/org.zealdocs.zeal.appdata.xml.in CMakeLists.txt +if git diff --staged --quiet; then + echo "Nothing to commit; ${TAG} content is already committed." +else + git commit -m "chore: release ${TAG}" +fi + +# Annotated: `git describe` without `--tags` ignores lightweight tags, and the +# AUR zeal-git package derives its version that way. +if git rev-parse -q --verify "refs/tags/${TAG}" > /dev/null; then + echo "Tag ${TAG} already exists; reusing it." +else + git tag -a "$TAG" -m "$TAG" +fi + +git push "$REMOTE" HEAD + +# Created before the tag is pushed, so the draft is in place when CI starts. +gh release create "$TAG" --draft --notes-file build/release-notes.md --repo "$repo" + +git push "$REMOTE" "$TAG" + +echo "Pushed ${TAG} to ${repo}. CI will build, upload, and publish."