Skip to content

Commit 6e0c40b

Browse files
committed
Release: add commit changelog generator script
Add a bash script to generate markdown changelog between two git references (tags/commits) with automatic GitHub PR association. Features: - Extracts commit info using git log with custom format - Links commits to GitHub PRs via GitHub API - Supports custom repository specification The script requires GITHUB_TOKEN environment variable and jq for JSON parsing. Outputs markdown format suitable for release notes. You can see a demo case in our 2.0.0 changelog: - https://cloudberry.apache.org/releases/2.0.0-incubating
1 parent d6b001e commit 6e0c40b

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
# ======================================================================
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# ======================================================================
20+
#
21+
# Generate changelog between two git references (tags/commits)
22+
# Usage: ./generate-changelog.sh <from_ref> <to_ref> [repo_owner/repo_name]
23+
#
24+
# Examples:
25+
# ./generate-changelog.sh 1a40e1f 8178d4f
26+
# ./generate-changelog.sh v1.0.0 v1.1.0
27+
# ./generate-changelog.sh 1a40e1f 8178d4f apache/cloudberry
28+
# ./generate-changelog.sh v1.0.0 v1.1.0 apache/cloudberry
29+
#
30+
# GitHub Token Setup:
31+
# 1. Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
32+
# 2. Generate new token with 'repo' scope (for private repos) or 'public_repo' scope (for public repos)
33+
# 3. Export the token: export GITHUB_TOKEN=your_token_here
34+
35+
set -e
36+
37+
# Default values
38+
DEFAULT_REPO="apache/cloudberry"
39+
GITHUB_API_BASE="https://api.github.com"
40+
41+
# Function to display usage
42+
usage() {
43+
echo "Usage: $0 <from_ref> <to_ref> [repo_owner/repo_name]"
44+
echo ""
45+
echo "Examples:"
46+
echo " $0 1a40e1f 8178d4f"
47+
echo " $0 v1.0.0 v1.1.0"
48+
echo " $0 1a40e1f 8178d4f apache/cloudberry"
49+
echo " $0 v1.0.0 v1.1.0 apache/cloudberry"
50+
echo ""
51+
echo "Environment variables:"
52+
echo " GITHUB_TOKEN - GitHub personal access token (required)"
53+
exit 1
54+
}
55+
56+
# Check arguments
57+
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
58+
usage
59+
fi
60+
61+
FROM_REF="$1"
62+
TO_REF="$2"
63+
REPO="${3:-$DEFAULT_REPO}"
64+
65+
# Check if GITHUB_TOKEN is set
66+
if [ -z "$GITHUB_TOKEN" ]; then
67+
echo "Error: GITHUB_TOKEN environment variable is required"
68+
echo "Please set it with: export GITHUB_TOKEN=your_token_here"
69+
exit 1
70+
fi
71+
72+
# Check if jq is installed
73+
if ! command -v jq &> /dev/null; then
74+
echo "Error: jq is required but not installed"
75+
echo "Please install jq using your system's package manager"
76+
exit 1
77+
fi
78+
79+
# Count total commits first
80+
total_commits=$(git log --oneline "$FROM_REF..$TO_REF" | wc -l | tr -d ' ')
81+
82+
echo "Generating changelog for $REPO from $FROM_REF to $TO_REF..."
83+
echo "Found $total_commits commits to process"
84+
echo ""
85+
86+
# Generate changelog
87+
git log --oneline --pretty=format:"%h|%H|%s|%an" "$FROM_REF..$TO_REF" | while IFS='|' read -r short_sha full_sha subject author; do
88+
# Get PR number for this commit
89+
pr_number=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
90+
"$GITHUB_API_BASE/repos/$REPO/commits/$full_sha/pulls" | \
91+
jq -r '.[0].number // empty')
92+
93+
if [ -n "$pr_number" ]; then
94+
echo "* [\`$short_sha\`](https://github.com/$REPO/commit/$full_sha) - $subject ($author) [#$pr_number](https://github.com/$REPO/pull/$pr_number)"
95+
else
96+
echo "* [\`$short_sha\`](https://github.com/$REPO/commit/$full_sha) - $subject ($author)"
97+
fi
98+
done
99+
100+
echo ""
101+
echo "Changelog generation completed!"

0 commit comments

Comments
 (0)