Skip to content

Commit b89850f

Browse files
wesmclaude
andcommitted
feat: add release.sh and update changelog.sh
Add release script that generates an AI-written changelog, shows it for approval, then creates an annotated tag and pushes it to trigger the release workflow. Update changelog.sh to support agent selection (codex/claude), start_tag parameter, JSON output mode, and filtered error output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1ec94a1 commit b89850f

File tree

2 files changed

+147
-25
lines changed

2 files changed

+147
-25
lines changed

scripts/changelog.sh

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
#!/bin/bash
2-
# Generate a changelog since the last release using codex
3-
# Usage: ./scripts/changelog.sh [version] [extra_instructions]
2+
# Generate a changelog since the last release using an AI agent
3+
# Usage: ./scripts/changelog.sh [version] [start_tag] [extra_instructions]
4+
# Set CHANGELOG_AGENT=claude to use claude instead of codex (default)
45
# If version is not provided, uses "NEXT" as placeholder
6+
# If start_tag is "-" or empty, auto-detects the previous tag
57

6-
set -e
8+
set -euo pipefail
79

810
VERSION="${1:-NEXT}"
9-
EXTRA_INSTRUCTIONS="$2"
10-
11-
# Find the previous tag
12-
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
13-
if [ -z "$PREV_TAG" ]; then
14-
# No previous tag - include all commits including root
15-
echo "No previous release found. Generating changelog for all commits..." >&2
16-
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
17-
# Use empty tree to diff against for full history
18-
EMPTY_TREE=$(git hash-object -t tree /dev/null)
19-
DIFF_STAT=$(git diff --stat "$EMPTY_TREE" HEAD)
11+
START_TAG="${2:-}"
12+
EXTRA_INSTRUCTIONS="${3:-}"
13+
AGENT="${CHANGELOG_AGENT:-codex}"
14+
15+
# Determine the starting point
16+
if [ -n "$START_TAG" ] && [ "$START_TAG" != "-" ]; then
17+
RANGE="$START_TAG..HEAD"
18+
echo "Generating changelog from $START_TAG to HEAD..." >&2
2019
else
21-
RANGE="$PREV_TAG..HEAD"
22-
echo "Generating changelog from $PREV_TAG to HEAD..." >&2
23-
COMMITS=$(git log $RANGE --pretty=format:"- %s (%h)" --no-merges)
24-
DIFF_STAT=$(git diff --stat $RANGE)
20+
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
21+
if [ -z "$PREV_TAG" ]; then
22+
FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD)
23+
RANGE="$FIRST_COMMIT..HEAD"
24+
echo "No previous release found. Generating changelog for all commits..." >&2
25+
else
26+
RANGE="$PREV_TAG..HEAD"
27+
echo "Generating changelog from $PREV_TAG to HEAD..." >&2
28+
fi
2529
fi
2630

31+
COMMITS=$(git log $RANGE --pretty=format:"- %s (%h)" --no-merges)
32+
DIFF_STAT=$(git diff --stat $RANGE)
33+
2734
if [ -z "$COMMITS" ]; then
28-
echo "No commits since $PREV_TAG" >&2
35+
echo "No commits since last release" >&2
2936
exit 0
3037
fi
3138

32-
# Use codex to generate the changelog
33-
echo "Using codex to generate changelog..." >&2
39+
echo "Using $AGENT to generate changelog..." >&2
3440

3541
TMPFILE=$(mktemp)
36-
trap 'rm -f "$TMPFILE"' EXIT
42+
PROMPTFILE=$(mktemp)
43+
ERRFILE=$(mktemp)
44+
trap 'rm -f "$TMPFILE" "$PROMPTFILE" "$ERRFILE"' EXIT
3745

38-
codex exec --skip-git-repo-check --sandbox read-only -c reasoning_effort=high -o "$TMPFILE" - >/dev/null <<EOF
46+
cat > "$PROMPTFILE" <<EOF
3947
You are generating a changelog for agentsview version $VERSION.
4048
4149
IMPORTANT: Do NOT use any tools. Do NOT run any shell commands. Do NOT search or read any files.
@@ -44,7 +52,7 @@ All the information you need is provided below. Simply analyze the commit messag
4452
Here are the commits since the last release:
4553
$COMMITS
4654
47-
Here's the diff summary:
55+
Here is the diff summary:
4856
$DIFF_STAT
4957
5058
Please generate a concise, user-focused changelog. Group changes into sections like:
@@ -57,8 +65,49 @@ Keep descriptions brief (one line each). Use present tense.
5765
Do NOT mention bugs that were introduced and fixed within this same release cycle.
5866
${EXTRA_INSTRUCTIONS:+
5967
60-
Additional context: $EXTRA_INSTRUCTIONS}
68+
When writing the changelog, look for these features or improvements in the commit log above: $EXTRA_INSTRUCTIONS
69+
Do NOT search files, read code, or do any analysis outside of the commit log provided above.}
6170
Output ONLY the changelog content, no preamble.
6271
EOF
6372

73+
AGENT_EXIT=0
74+
case "$AGENT" in
75+
codex)
76+
CODEX_RUST_LOG="${CHANGELOG_CODEX_RUST_LOG:-${RUST_LOG:-error,codex_core::rollout::list=off}}"
77+
set +e
78+
RUST_LOG="$CODEX_RUST_LOG" codex exec --json --skip-git-repo-check --sandbox read-only -c reasoning_effort=high -o "$TMPFILE" - >/dev/null < "$PROMPTFILE" 2>"$ERRFILE"
79+
AGENT_EXIT=$?
80+
set -e
81+
;;
82+
claude)
83+
set +e
84+
claude --print < "$PROMPTFILE" > "$TMPFILE" 2>"$ERRFILE"
85+
AGENT_EXIT=$?
86+
set -e
87+
;;
88+
*)
89+
echo "Error: unknown CHANGELOG_AGENT '$AGENT' (expected 'codex' or 'claude')" >&2
90+
exit 1
91+
;;
92+
esac
93+
94+
if [ "$AGENT_EXIT" -ne 0 ] || [ ! -s "$TMPFILE" ]; then
95+
echo "Error: $AGENT failed to generate changelog." >&2
96+
if [ "${CHANGELOG_DEBUG:-0}" = "1" ]; then
97+
cat "$ERRFILE" >&2
98+
else
99+
FILTERED_ERR=$(grep -E -v 'rollout path for thread|failed to record rollout items: failed to queue rollout items: channel closed|^mcp startup: no servers$|^WARNING: proceeding, even though we could not update PATH:' "$ERRFILE" || true)
100+
if [ -n "$FILTERED_ERR" ]; then
101+
echo "$FILTERED_ERR" >&2
102+
else
103+
echo "Set CHANGELOG_DEBUG=1 to print full agent logs." >&2
104+
fi
105+
fi
106+
exit 1
107+
fi
108+
109+
if [ "${CHANGELOG_DEBUG:-0}" = "1" ] && [ -s "$ERRFILE" ]; then
110+
cat "$ERRFILE" >&2
111+
fi
112+
64113
cat "$TMPFILE"

scripts/release.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
6+
VERSION="$1"
7+
EXTRA_INSTRUCTIONS="${2:-}"
8+
9+
if [ -z "$VERSION" ]; then
10+
echo "Usage: $0 <version> [extra_instructions]"
11+
echo "Example: $0 0.2.0"
12+
echo "Example: $0 0.2.0 \"Focus on analytics improvements\""
13+
exit 1
14+
fi
15+
16+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
17+
echo "Error: Version must be in format X.Y.Z (e.g., 0.2.0)"
18+
exit 1
19+
fi
20+
21+
TAG="v$VERSION"
22+
23+
if git rev-parse "$TAG" >/dev/null 2>&1; then
24+
echo "Error: Tag $TAG already exists"
25+
exit 1
26+
fi
27+
28+
if ! git diff-index --quiet HEAD --; then
29+
echo "Error: You have uncommitted changes. Please commit or stash them first."
30+
exit 1
31+
fi
32+
33+
if ! command -v gh &> /dev/null; then
34+
echo "Error: gh CLI is required. Install from https://cli.github.com/"
35+
exit 1
36+
fi
37+
38+
# Generate changelog
39+
CHANGELOG_FILE=$(mktemp)
40+
trap 'rm -f "$CHANGELOG_FILE"' EXIT
41+
42+
"$SCRIPT_DIR/changelog.sh" "$VERSION" "-" "$EXTRA_INSTRUCTIONS" > "$CHANGELOG_FILE"
43+
44+
echo ""
45+
echo "=========================================="
46+
echo "PROPOSED CHANGELOG FOR $TAG"
47+
echo "=========================================="
48+
cat "$CHANGELOG_FILE"
49+
echo ""
50+
echo "=========================================="
51+
echo ""
52+
53+
read -p "Accept this changelog and create release $TAG? [y/N] " -n 1 -r
54+
echo ""
55+
56+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
57+
echo "Release cancelled."
58+
exit 0
59+
fi
60+
61+
echo "Creating tag $TAG..."
62+
git tag -a "$TAG" -m "Release $VERSION
63+
64+
$(cat $CHANGELOG_FILE)"
65+
66+
echo "Pushing tag to origin..."
67+
git push origin "$TAG"
68+
69+
echo ""
70+
echo "Release $TAG created and pushed successfully!"
71+
echo "GitHub Actions will build and publish the release."
72+
echo ""
73+
echo "GitHub release URL: https://github.com/wesm/agentsview/releases/tag/$TAG"

0 commit comments

Comments
 (0)