Skip to content

Commit 83f679b

Browse files
committed
fix: release.sh now triggers release-pr if no PR exists (full e2e)
The script was passive — it only merged an existing PR. Now it's active: if no release PR is open, it triggers release-plz release-pr via workflow_dispatch, waits for the job to complete, then merges the freshly created PR + promotes to main. One command handles the full pipeline: no PR → trigger release-pr → wait → merge PR → promote to main → CI publishes
1 parent 6d0b402 commit 83f679b

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

scripts/release.sh

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# scripts/release.sh — ship the next katgpt-core version. One command.
33
#
44
# What it does (from develop):
5-
# 1. Finds the open release-plz PR (auto-created by CI on each develop push)
6-
# 2. Auto-merges it into develop (merge commit, never squash)
5+
# 1. If no release PR is open, triggers release-plz to create one (and waits)
6+
# 2. Merges the release PR into develop (merge commit, never squash)
77
# 3. Promotes develop → main (fast-forward)
88
# 4. CI auto-publishes katgpt-core to crates.io on the main push
99
#
@@ -13,8 +13,6 @@
1313
#
1414
# Prerequisites (one-time):
1515
# brew install gh && gh auth login
16-
#
17-
# See README.md § "Releasing & Deploying" for the full flow.
1816
set -euo pipefail
1917

2018
# ── Subcommand: --publish (manual CI publish trigger from main) ────────
@@ -39,12 +37,37 @@ BRANCH="$(git branch --show-current)"
3937
command -v gh >/dev/null 2>&1 || { echo "error: brew install gh" >&2; exit 1; }
4038
gh auth status >/dev/null 2>&1 || { echo "error: gh auth login" >&2; exit 1; }
4139

42-
# Find the open release-plz PR (branch starts with "release-plz-")
43-
PR_JSON="$(gh pr list --state open --json number,title,headRefName \
44-
--jq '[.[] | select(.headRefName | startswith("release-plz"))] | .[0] // empty')"
40+
# Push any unpushed develop commits (so release-plz sees the latest)
41+
git push origin develop 2>/dev/null || true
42+
43+
find_release_pr() {
44+
gh pr list --state open --json number,title,headRefName \
45+
--jq '[.[] | select(.headRefName | startswith("release-plz"))] | .[0] // empty'
46+
}
47+
48+
# ── Step 1: ensure a release PR exists ─────────────────────────────────
49+
PR_JSON="$(find_release_pr)"
4550

4651
if [[ -z "$PR_JSON" ]]; then
47-
echo "ℹ no open release PR. Commit a feat:/fix: on develop to trigger one." >&2
52+
echo "→ no open release PR. Triggering release-plz release-pr..."
53+
gh workflow run release-plz.yml --ref develop -f command=release-pr
54+
55+
# Wait for the run to register, then watch it
56+
sleep 5
57+
RUN_ID="$(gh run list --workflow=release-plz.yml --branch=develop \
58+
--event=workflow_dispatch --limit=1 --json databaseId --jq '.[0].databaseId')"
59+
60+
if [[ -n "$RUN_ID" ]]; then
61+
echo "→ waiting for release-pr job (run #$RUN_ID)..."
62+
gh run watch "$RUN_ID" --exit-status
63+
fi
64+
65+
# Re-check for the PR
66+
PR_JSON="$(find_release_pr)"
67+
fi
68+
69+
if [[ -z "$PR_JSON" ]] || [[ "$PR_JSON" == "null" ]]; then
70+
echo "ℹ nothing to release — no version-worthy changes since last release." >&2
4871
exit 0
4972
fi
5073

@@ -53,14 +76,14 @@ PR_TITLE="$(printf '%s' "$PR_JSON" | jq -r '.title')"
5376

5477
echo "→ found release PR #$PR_NUMBER: $PR_TITLE"
5578

56-
# Merge the PR into develop (merge commit — release-plz needs it for detection)
79+
# ── Step 2: merge the PR (merge commit, not squash) ───────────────────
5780
echo "→ merging PR #$PR_NUMBER into develop..."
5881
gh pr merge "$PR_NUMBER" --merge --delete-branch
5982

60-
# Pull the merged develop
83+
# ── Step 3: pull the merged develop ───────────────────────────────────
6184
git pull origin develop
6285

63-
# Promote develop → main
86+
# ── Step 4: promote develop → main ────────────────────────────────────
6487
echo "→ promoting develop → main..."
6588
git checkout main
6689
git pull origin main

0 commit comments

Comments
 (0)