Skip to content

Commit f235f3f

Browse files
authored
Another attempt at including all tags in the changelog
1 parent 3e9edb6 commit f235f3f

1 file changed

Lines changed: 32 additions & 27 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
- name: Generate changelog
107107
run: |
108108
changelog=""
109-
109+
110110
# Get tags newest to oldest
111111
tags=($(git tag --sort=-version:refname))
112112
@@ -117,8 +117,10 @@ jobs:
117117
else
118118
untagged_commits=$(git --no-pager log --format="%s (%an) [%h]")
119119
fi
120-
121-
future_tag="$( awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json )"
120+
121+
# Get future version from package.json
122+
future_tag="$(awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json)"
123+
122124
if [ -n "$untagged_commits" ]; then
123125
tag_log="### ${future_tag}\n"
124126
while IFS= read -r commit; do
@@ -127,32 +129,35 @@ jobs:
127129
changelog="${tag_log}\n${changelog}"
128130
fi
129131
130-
# Loop over all tags, newest to oldest
132+
# Loop from i=0 to i <= tags.length (YES, intentionally +1)
131133
for ((i=0; i<=${#tags[@]}; i++)); do
132134
current="${tags[$i]}"
133-
next=""
134-
135-
if (( i <= ${#tags[@]} - 1 )); then
136-
next="${tags[$((i+1))]}"
137-
commits=$(git --no-pager log --format="%s (%an) [%h]" "${next}..${current}")
138-
else
139-
echo "TAG (current) = (${current})"
140-
commits=$(git --no-pager log --format="%s (%an) [%h]" "${current}")
141-
fi
142-
143-
if [ -n "$commits" ]; then
144-
tag_log="### ${current}\n"
145-
while IFS= read -r commit; do
146-
tag_log+="- ${commit}\n"
147-
done <<< "$commits"
148-
changelog="${changelog}\n${tag_log}"
149-
fi
150-
done
151-
152-
changelog="# Changelog\n${changelog}"
153-
154-
echo -e "$changelog"
155-
printf '%b' "$changelog" > CHANGELOG.md
135+
next="${tags[$((i+1))]}"
136+
137+
# Skip if current is empty (e.g., i == len)
138+
if [ -z "$current" ]; then
139+
continue
140+
fi
141+
142+
if [ -n "$next" ]; then
143+
commits=$(git --no-pager log --format="%s (%an) [%h]" "${next}..${current}")
144+
else
145+
# last tag (oldest), no previous one
146+
commits=$(git --no-pager log --format="%s (%an) [%h]" "${current}")
147+
fi
148+
149+
if [ -n "$commits" ]; then
150+
tag_log="### ${current}\n"
151+
while IFS= read -r commit; do
152+
tag_log+="- ${commit}\n"
153+
done <<< "$commits"
154+
changelog="${changelog}\n${tag_log}"
155+
fi
156+
done
157+
158+
changelog="# Changelog\n${changelog}"
159+
echo -e "$changelog"
160+
printf '%b' "$changelog" > CHANGELOG.md
156161
- name: Upload new changelog
157162
uses: actions/upload-artifact@v4
158163
with:

0 commit comments

Comments
 (0)