Skip to content

Commit

Permalink
Fix: Fixed changelogs, I hope
Browse files Browse the repository at this point in the history
  • Loading branch information
louanfontenele committed Dec 29, 2024
1 parent 77f126a commit 78dc7a8
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions .github/scripts/generate-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,80 @@ CHANGELOG_FILE="CHANGELOG.md"
LATEST_TAG=${previous_tag:-"N/A"}
NEW_TAG=${current_tag:-"N/A"}

# Initialize changelog sections
FEATURES=""
FIXES=""
UPDATES=""
REMOVES=""

# Initialize changelog
if [ "$LATEST_TAG" == "N/A" ]; then
echo "No previous tag found. Initial release."
LATEST_TAG=""
fi

# Create or update the changelog
echo "## 🚀 Release $NEW_TAG 🎉" > $CHANGELOG_FILE
echo "" >> $CHANGELOG_FILE
echo "🚀 **Release $NEW_TAG**" > $CHANGELOG_FILE
echo "### What's Changed" >> $CHANGELOG_FILE
echo "" >> $CHANGELOG_FILE

# Log commits and classify by prefix
git log --pretty=format:"%s" $LATEST_TAG..HEAD | while read -r line; do
if [[ $line == Feature:* ]]; then
FEATURES+="- ${line#Feature: }\n"
elif [[ $line == Fix:* ]]; then
FIXES+="- ${line#Fix: }\n"
elif [[ $line == Update:* ]]; then
UPDATES+="- ${line#Update: }\n"
elif [[ $line == Remove:* ]]; then
REMOVES+="- ${line#Remove: }\n"
fi
done
# Initialize sections for each type of change
FEATURES=""
FIXES=""
UPDATES=""
REMOVES=""

# Fetch commit history and categorize
if [ -n "$LATEST_TAG" ]; then
COMMITS=$(git log --pretty=format:"%s" $LATEST_TAG..HEAD)
else
COMMITS=$(git log --pretty=format:"%s" HEAD)
fi

# Populate changelog with fallback if sections are empty
echo "### 🌟 Features" >> $CHANGELOG_FILE
# Loop through each commit and categorize
while IFS= read -r line; do
case "$line" in
*"Feature:"* | *"feat:"* | *"Add:"*)
FEATURES+="- ${line#*: }\n"
;;
*"Fix:"* | *"fix:"* | *"Bug:"* | *"Patch:"*)
FIXES+="- ${line#*: }\n"
;;
*"Update:"* | *"update:"* | *"Improvement:"*)
UPDATES+="- ${line#*: }\n"
;;
*"Remove:"* | *"remove:"* | *"Delete:"*)
REMOVES+="- ${line#*: }\n"
;;
esac
done <<< "$COMMITS"

# Append categorized sections
if [ -n "$FEATURES" ]; then
echo "🌟 **Features**" >> $CHANGELOG_FILE
echo -e "$FEATURES" >> $CHANGELOG_FILE
else
echo "🌟 **Features**" >> $CHANGELOG_FILE
echo "- _*No new features*_ " >> $CHANGELOG_FILE
fi

echo "" >> $CHANGELOG_FILE

echo "### 🐛 Fixes" >> $CHANGELOG_FILE
if [ -n "$FIXES" ]; then
echo "🐛 **Fixes**" >> $CHANGELOG_FILE
echo -e "$FIXES" >> $CHANGELOG_FILE
else
echo "🐛 **Fixes**" >> $CHANGELOG_FILE
echo "- _*No bug fixes*_ " >> $CHANGELOG_FILE
fi

echo "" >> $CHANGELOG_FILE

echo "### 🔄 Updates" >> $CHANGELOG_FILE
if [ -n "$UPDATES" ]; then
echo "🔄 **Updates**" >> $CHANGELOG_FILE
echo -e "$UPDATES" >> $CHANGELOG_FILE
else
echo "🔄 **Updates**" >> $CHANGELOG_FILE
echo "- _*No updates*_ " >> $CHANGELOG_FILE
fi

echo "" >> $CHANGELOG_FILE

echo "### 🗑️ Removes" >> $CHANGELOG_FILE
if [ -n "$REMOVES" ]; then
echo "🗑️ **Removes**" >> $CHANGELOG_FILE
echo -e "$REMOVES" >> $CHANGELOG_FILE
else
echo "🗑️ **Removes**" >> $CHANGELOG_FILE
echo "- _*Nothing removed*_ " >> $CHANGELOG_FILE
fi

# Add full commit history link
REPO_URL="https://github.com/${GITHUB_REPOSITORY}/compare/"
echo "" >> $CHANGELOG_FILE
echo "**Full commit history:** [Compare Changes](${REPO_URL}${LATEST_TAG}...${NEW_TAG})" >> $CHANGELOG_FILE
echo "**Full commit history:** [Compare Changes](https://github.com/${GITHUB_REPOSITORY}/compare/${LATEST_TAG}...${NEW_TAG})" >> $CHANGELOG_FILE

0 comments on commit 78dc7a8

Please sign in to comment.