@@ -106,50 +106,53 @@ jobs:
106106 - name : Generate changelog
107107 run : |
108108 changelog=""
109+
110+ # Get tags newest to oldest
111+ tags=($(git tag --sort=-version:refname))
112+
113+ # Untagged commits after latest tag
114+ if [ "${#tags[@]}" -gt 0 ]; then
115+ latest_tag="${tags[0]}"
116+ untagged_commits=$(git --no-pager log --format="%s (%an) [%h]" "${latest_tag}..HEAD")
117+ else
118+ untagged_commits=$(git --no-pager log --format="%s (%an) [%h]")
119+ fi
109120
110- # Get all tags in ascending order
111- tags=($( git tag --sort=version:refname ))
112-
113- # Loop through tags to generate the changelog
114- for ((i=0; i<${#tags[@]}; i++)); do
115- current_tag="${tags[$i]}"
116- previous_tag=""
117- tag_log=""
118-
119- if [ -z "${current_tag}" ]; then
120- continue
121- fi
122-
123- # Determine the previous tag if not the first tag
124- if (( i > 0 )); then
125- previous_tag="${tags[$((i-1))]}"
126- fi
127-
128- # Generate the header for the current tag
129- tag_log="### ${current_tag}\n"
130-
131- # Get the commits between the current tag and the previous tag
132- if [ -n "$previous_tag" ]; then
133- commits=$(git log --format="%s (%an) [%h]" "${previous_tag}..${current_tag}")
134- else
135- # If no previous tag, include all commits up to the first tag
136- commits=$(git log --format="%s (%an) [%h]" "${current_tag}")
137- fi
138-
139- # Add commits to the changelog, one per line
121+ future_tag="$( awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json )"
122+ if [ -n "$untagged_commits" ]; then
123+ tag_log="### ${future_tag}\n"
140124 while IFS= read -r commit; do
141125 tag_log+="- ${commit}\n"
142- done <<< "${commits}"
143-
126+ done <<< "$untagged_commits"
144127 changelog="${tag_log}\n${changelog}"
128+ fi
129+
130+ # Loop over all tags, newest to oldest
131+ for ((i=0; i<=${#tags[@]}; i++)); do
132+ 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
145150 done
146-
147- changelog="# Changelog\n\n${changelog}"
148-
149- echo -e "${changelog}"
150-
151- # You can now use the variable $changelog elsewhere in your script
152- printf '%b' "${changelog}" > CHANGELOG.md
151+
152+ changelog="# Changelog\n${changelog}"
153+
154+ echo -e "$changelog"
155+ printf '%b' "$changelog" > CHANGELOG.md
153156 - name : Upload new changelog
154157 uses : actions/upload-artifact@v4
155158 with :
0 commit comments