@@ -79,63 +79,96 @@ jobs:
7979 BASE_VERSION="${{ inputs.base_version }}"
8080 if [[ -z "$BASE_VERSION" ]]; then
8181 # Find the last version tag
82- BASE_VERSION=$(git tag --sort=-version:refname | grep "^v" | head -1)
82+ BASE_VERSION=$(git tag --sort=-version:refname | grep "^v" | head -1 || echo "")
83+ fi
84+
85+ # Add 'v' prefix if not present
86+ if [[ -n "$BASE_VERSION" ]] && [[ ! "$BASE_VERSION" =~ ^v ]]; then
87+ BASE_VERSION="v$BASE_VERSION"
8388 fi
8489
8590 if [[ -n "$BASE_VERSION" ]]; then
86- echo "::notice::Generating changelog from $BASE_VERSION to HEAD"
87-
88- # Get commits since base version
89- COMMITS=$(git log --pretty=format:"- %s" "${BASE_VERSION}..HEAD" --no-merges)
91+ # Check if the base version tag exists
92+ if ! git rev-parse "$BASE_VERSION" >/dev/null 2>&1; then
93+ echo "::warning::Base version tag '$BASE_VERSION' not found, creating manual template"
94+ MODE="manual_template"
95+ else
96+ echo "::notice::Generating changelog from $BASE_VERSION to HEAD"
97+
98+ # Debug: Show what tags exist
99+ echo "::debug::Available tags: $(git tag --sort=-version:refname | grep '^v' | head -5 | tr '\n' ' ')"
100+
101+ # Get commits since base version
102+ COMMITS=$(git log --pretty=format:"- %s" "${BASE_VERSION}..HEAD" --no-merges 2>/dev/null || echo "")
103+
104+ # Debug: Show number of commits found
105+ COMMIT_COUNT=$(echo "$COMMITS" | grep -c "^-" || echo "0")
106+ echo "::notice::Found $COMMIT_COUNT commits since $BASE_VERSION"
90107
91- # Categorize commits
92- ADDED=""
93- CHANGED=""
94- FIXED=""
95- REMOVED=""
96- OTHER=""
97-
98- while IFS= read -r commit; do
99- if [[ $commit =~ ^-\ (Add|add|NEW|new|FEAT|feat|Feature) ]]; then
100- ADDED="${ADDED}${commit}"$'\n'
101- elif [[ $commit =~ ^-\ (Fix|fix|FIX|Bug|bug|BUG) ]]; then
102- FIXED="${FIXED}${commit}"$'\n'
103- elif [[ $commit =~ ^-\ (Update|update|Change|change|Improve|improve|Refactor|refactor) ]]; then
104- CHANGED="${CHANGED}${commit}"$'\n'
105- elif [[ $commit =~ ^-\ (Remove|remove|Delete|delete|Drop|drop) ]]; then
106- REMOVED="${REMOVED}${commit}"$'\n'
107- else
108- OTHER="${OTHER}${commit}"$'\n'
108+ # Categorize commits
109+ ADDED=""
110+ CHANGED=""
111+ FIXED=""
112+ REMOVED=""
113+ OTHER=""
114+
115+ if [[ -n "$COMMITS" ]]; then
116+ while IFS= read -r commit; do
117+ if [[ -n "$commit" ]]; then
118+ if [[ $commit =~ (Add|add|NEW|new|FEAT|feat|Feature) ]]; then
119+ ADDED="${ADDED}${commit}"$'\n'
120+ elif [[ $commit =~ (Fix|fix|FIX|Bug|bug|BUG) ]]; then
121+ FIXED="${FIXED}${commit}"$'\n'
122+ elif [[ $commit =~ (Update|update|Change|change|Improve|improve|Refactor|refactor) ]]; then
123+ CHANGED="${CHANGED}${commit}"$'\n'
124+ elif [[ $commit =~ (Remove|remove|Delete|delete|Drop|drop) ]]; then
125+ REMOVED="${REMOVED}${commit}"$'\n'
126+ else
127+ OTHER="${OTHER}${commit}"$'\n'
128+ fi
129+ fi
130+ done <<< "$COMMITS"
109131 fi
110- done <<< "$COMMITS"
111-
112- # Create changelog entry
113- echo "## [$VERSION] - $DATE" > changelog_entry.txt
114- echo "" >> changelog_entry.txt
115132
116- if [[ -n "$ADDED$OTHER" ]]; then
117- echo "### Added" > > changelog_entry.txt
133+ # Create changelog entry
134+ echo "## [$VERSION] - $DATE" > changelog_entry.txt
118135 echo "" >> changelog_entry.txt
119- [[ -n "$ADDED" ]] && echo "$ADDED" >> changelog_entry.txt
120- [[ -n "$OTHER" ]] && echo "$OTHER" >> changelog_entry.txt
121- fi
122-
123- if [[ -n "$CHANGED" ]]; then
124- echo "### Changed" >> changelog_entry.txt
125- echo "" >> changelog_entry.txt
126- echo "$CHANGED" >> changelog_entry.txt
127- fi
128-
129- if [[ -n "$FIXED" ]]; then
130- echo "### Fixed" >> changelog_entry.txt
131- echo "" >> changelog_entry.txt
132- echo "$FIXED" >> changelog_entry.txt
133- fi
134-
135- if [[ -n "$REMOVED" ]]; then
136- echo "### Removed" >> changelog_entry.txt
137- echo "" >> changelog_entry.txt
138- echo "$REMOVED" >> changelog_entry.txt
136+
137+ # Only add sections that have content
138+ if [[ -n "$ADDED$OTHER" ]]; then
139+ echo "### Added" >> changelog_entry.txt
140+ echo "" >> changelog_entry.txt
141+ [[ -n "$ADDED" ]] && echo "$ADDED" >> changelog_entry.txt
142+ [[ -n "$OTHER" ]] && echo "$OTHER" >> changelog_entry.txt
143+ echo "" >> changelog_entry.txt
144+ fi
145+
146+ if [[ -n "$CHANGED" ]]; then
147+ echo "### Changed" >> changelog_entry.txt
148+ echo "" >> changelog_entry.txt
149+ echo "$CHANGED" >> changelog_entry.txt
150+ echo "" >> changelog_entry.txt
151+ fi
152+
153+ if [[ -n "$FIXED" ]]; then
154+ echo "### Fixed" >> changelog_entry.txt
155+ echo "" >> changelog_entry.txt
156+ echo "$FIXED" >> changelog_entry.txt
157+ echo "" >> changelog_entry.txt
158+ fi
159+
160+ if [[ -n "$REMOVED" ]]; then
161+ echo "### Removed" >> changelog_entry.txt
162+ echo "" >> changelog_entry.txt
163+ echo "$REMOVED" >> changelog_entry.txt
164+ echo "" >> changelog_entry.txt
165+ fi
166+
167+ # If no commits were found or categorized, create template
168+ if [[ ! -s changelog_entry.txt || $(wc -l < changelog_entry.txt) -le 2 ]]; then
169+ echo "::notice::No commits found or all commits were empty, creating manual template"
170+ MODE="manual_template"
171+ fi
139172 fi
140173 else
141174 echo "::warning::No base version found, creating manual template"
0 commit comments