Skip to content

Commit f57a2a1

Browse files
committed
fix(ci): robustify changelog generation in GitHub Actions release workflow.
1 parent d120252 commit f57a2a1

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

.github/workflows/release.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,34 +79,41 @@ jobs:
7979
- name: Generate changelog
8080
id: changelog
8181
run: |
82+
set -e
8283
CURRENT_TAG="${{ steps.get_version.outputs.VERSION }}"
8384
PREVIOUS_TAG="${{ steps.previous_tag.outputs.PREVIOUS_TAG }}"
84-
85-
echo "Generating changelog from $PREVIOUS_TAG to $CURRENT_TAG"
86-
85+
86+
echo "Generating changelog from '$PREVIOUS_TAG' to '$CURRENT_TAG'"
87+
88+
# Initialize changelog
89+
CHANGELOG=""
90+
8791
# Generate changelog with proper formatting
88-
if git rev-parse --verify "$PREVIOUS_TAG" >/dev/null 2>&1; then
92+
if [ -n "$PREVIOUS_TAG" ] && git rev-parse --verify "$PREVIOUS_TAG" >/dev/null 2>&1; then
8993
# If previous tag exists, get commits between tags
90-
CHANGELOG=$(git log --pretty=format:"- %s" "$PREVIOUS_TAG..$CURRENT_TAG" | head -20)
91-
else
92-
# If previous tag doesn't exist (first commit), get all commits up to current tag
93-
CHANGELOG=$(git log --pretty=format:"- %s" "$CURRENT_TAG" | head -20)
94+
echo "Previous tag found: $PREVIOUS_TAG"
95+
CHANGELOG=$(git log --oneline "$PREVIOUS_TAG..$CURRENT_TAG" | sed 's/^[a-f0-9]* /- /' | head -20) || echo "Git log failed"
96+
elif [ -n "$CURRENT_TAG" ]; then
97+
# If previous tag doesn't exist, get all commits up to current tag
98+
echo "No previous tag found, getting all commits up to $CURRENT_TAG"
99+
CHANGELOG=$(git log --oneline "$CURRENT_TAG" | sed 's/^[a-f0-9]* /- /' | head -20) || echo "Git log failed"
94100
fi
95-
101+
96102
# If no commits found, provide default message
97103
if [ -z "$CHANGELOG" ]; then
104+
echo "No commits found, using default message"
98105
CHANGELOG="- Initial release"
99106
fi
100-
107+
101108
echo "Generated changelog:"
102109
echo "$CHANGELOG"
103-
110+
104111
# Save to multiline output
105112
{
106113
echo 'CHANGELOG<<EOF'
107114
echo "$CHANGELOG"
108115
echo 'EOF'
109-
} >> $GITHUB_OUTPUT
116+
} >> "$GITHUB_OUTPUT"
110117
shell: bash
111118

112119
- name: Create Release

0 commit comments

Comments
 (0)