Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions rust/scripts/ci/generate-workspace-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,78 @@ should_include_workspace() {
return 1
}

# Map from conventional commit scope to workspace path
declare -A SCOPE_TO_WORKSPACE=(
["relayer"]="agents/relayer"
["validator"]="agents/validator"
["scraper"]="agents/scraper"
["lander"]="lander"
["cosmos"]="chains/hyperlane-cosmos"
["ethereum"]="chains/hyperlane-ethereum"
["sealevel"]="chains/hyperlane-sealevel"
["fuel"]="chains/hyperlane-fuel"
["starknet"]="chains/hyperlane-starknet"
["aleo"]="chains/hyperlane-aleo"
)

# Note: matched_workspaces is reset each iteration; declared here for clarity
declare -A matched_workspaces

# Get all commits in the range (filter to rust/main directory)
git log --no-merges --format="%H" $COMMIT_RANGE -- rust/main | while read -r commit_hash; do
# Get commit message
commit_msg=$(git log -1 --format="%s" "$commit_hash")

# Check if commit message has an explicit scope like feat(relayer): or fix(validator):
# This takes priority over file-based detection
explicit_scope=""
if [[ "$commit_msg" =~ ^[a-z]+\(([a-z]+)\): ]]; then
scope="${BASH_REMATCH[1]}"
if [ -n "${SCOPE_TO_WORKSPACE[$scope]:-}" ]; then
explicit_scope="${SCOPE_TO_WORKSPACE[$scope]}"
fi
fi

# Get files changed in this commit (within rust/main)
files=$(git diff-tree --no-commit-id --name-only -r "$commit_hash" -- rust/main)

# Categorize based on workspace membership
workspace=""
for file in $files; do
# Strip rust/main/ prefix if present
file=$(echo "$file" | sed 's|^rust/main/||')

# Check which workspace this file belongs to
for member in $WORKSPACE_MEMBERS; do
if [[ "$file" =~ ^"$member"(/|$) ]]; then
workspace="$member"
break 2 # Break both loops
fi
# A commit can belong to multiple workspaces if it touches files in each
# Clear the array from any previous iteration (declare -A doesn't reset existing arrays)
matched_workspaces=()

if [ -n "$explicit_scope" ]; then
# If explicit scope in commit message, use only that workspace
matched_workspaces["$explicit_scope"]=1
else
# Otherwise, detect workspaces from changed files
for file in $files; do
# Strip rust/main/ prefix if present
file=$(echo "$file" | sed 's|^rust/main/||')

# Check which workspace this file belongs to
for member in $WORKSPACE_MEMBERS; do
if [[ "$file" =~ ^"$member"(/|$) ]]; then
matched_workspaces["$member"]=1
break # Break inner loop only - file matched, check next file
fi
done
done
done
fi

# Default to "other" if no workspace found
if [ -z "$workspace" ]; then
workspace="other"
# If no workspaces matched, categorize as "other"
if [ ${#matched_workspaces[@]} -eq 0 ]; then
matched_workspaces["other"]=1
fi

# Sanitize workspace name for file system (replace / with __)
workspace_file=$(echo "$workspace" | tr '/' '_')
# Store commit in ALL matched workspace category files
for workspace in "${!matched_workspaces[@]}"; do
# Sanitize workspace name for file system (replace / with __)
workspace_file=$(echo "$workspace" | tr '/' '_')

# Store commit in workspace category file (just message, PR# already in message)
echo "$commit_msg" >> "$TEMP_DIR/$workspace_file"
# Store commit in workspace category file (just message, PR# already in message)
echo "$commit_msg" >> "$TEMP_DIR/$workspace_file"
done
done

# Function to generate changelog for a specific workspace
Expand Down
Loading