changelog #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: changelog | |
on: | |
workflow_run: | |
workflows: | |
- "Build and Release AnymeX" # Name of the triggering workflow | |
types: | |
- completed | |
workflow_dispatch: # Allow manual triggering of this workflow | |
jobs: | |
notify: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Clear existing CHANGELOG.md | |
- name: Clear CHANGELOG.md | |
run: | | |
echo ""> CHANGELOG.md | |
echo "" >> CHANGELOG.md | |
- name: Get previous tag | |
id: get_prev_tag | |
run: | | |
echo "Getting the previous tag..." | |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
echo "Previous tag retrieved: $PREV_TAG" | |
if [ -z "$PREV_TAG" ]; then | |
echo "No previous tag found, using the initial commit." | |
PREV_TAG=$(git rev-list --max-parents=0 HEAD) | |
fi | |
echo "prev_tag=$PREV_TAG" >> $GITHUB_ENV | |
echo "Previous tag: $PREV_TAG" | |
- name: Get commit messages between tags | |
id: get_commits | |
run: | | |
echo "Getting commit messages between tags..." | |
COMMITS=$(git log ${{ env.prev_tag }}..HEAD --pretty=format:'%h %s' | tr '\n' '|') | |
echo "Commits retrieved: $COMMITS" | |
echo "commits=$COMMITS" >> $GITHUB_ENV | |
- name: Categorize commits | |
id: categorize | |
run: | | |
echo "Categorizing commits..." | |
FEATURES="" | |
BUG_FIXES="" | |
REFACTORS="" | |
STYLE_CHANGES="" | |
PERFORMANCE="" | |
CHORES="" | |
REPO_URL="https://github.com/${{ github.repository }}" | |
IFS='|' read -ra COMMIT_LIST <<< "${{ env.commits }}" | |
echo "Commit list: ${COMMIT_LIST[@]}" | |
for LINE in "${COMMIT_LIST[@]}"; do | |
HASH=$(echo "$LINE" | awk '{print $1}') | |
MESSAGE=$(echo "$LINE" | cut -d' ' -f2-) | |
LINK="[$HASH]($REPO_URL/commit/$HASH)" | |
FORMATTED_COMMIT="* $LINK: $MESSAGE" | |
echo "Processing commit: $FORMATTED_COMMIT" | |
if [[ $MESSAGE == feat* ]]; then | |
FEATURES+="$FORMATTED_COMMIT\n" | |
elif [[ $MESSAGE == fix* || $MESSAGE == bug* || $MESSAGE == improvement* || $MESSAGE == patch* ]]; then | |
BUG_FIXES+="$FORMATTED_COMMIT\n" | |
elif [[ $MESSAGE == refactor* ]]; then | |
REFACTORS+="$FORMATTED_COMMIT\n" | |
elif [[ $MESSAGE == style* ]]; then | |
STYLE_CHANGES+="$FORMATTED_COMMIT\n" | |
elif [[ $MESSAGE == perf* ]]; then | |
PERFORMANCE+="$FORMATTED_COMMIT\n" | |
elif [[ $MESSAGE == chore* || $MESSAGE == docs* || $MESSAGE == build* || $MESSAGE == ci* ]]; then | |
CHORES+="$FORMATTED_COMMIT\n" | |
fi | |
done | |
if [ -n "$FEATURES" ]; then | |
echo "### 🎉 New Features" >> CHANGELOG.md | |
echo -e "$FEATURES" >> CHANGELOG.md | |
fi | |
if [ -n "$BUG_FIXES" ]; then | |
echo "### 🛠️ Bug Fixes & Improvements" >> CHANGELOG.md | |
echo -e "$BUG_FIXES" >> CHANGELOG.md | |
fi | |
if [ -n "$REFACTORS" ]; then | |
echo "### 🔧 Refactors" >> CHANGELOG.md | |
echo -e "$REFACTORS" >> CHANGELOG.md | |
fi | |
if [ -n "$STYLE_CHANGES" ]; then | |
echo "### 🎨 Style Changes" >> CHANGELOG.md | |
echo -e "$STYLE_CHANGES" >> CHANGELOG.md | |
fi | |
if [ -n "$PERFORMANCE" ]; then | |
echo "### 🚀 Performance Improvements" >> CHANGELOG.md | |
echo -e "$PERFORMANCE" >> CHANGELOG.md | |
fi | |
if [ -n "$CHORES" ]; then | |
echo "### 🧹 Chores & Documentation" >> CHANGELOG.md | |
echo -e "$CHORES" >> CHANGELOG.md | |
fi | |
- name: Commit and push changelog | |
run: | | |
echo "Committing and pushing changelog..." | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add CHANGELOG.md | |
git commit -m "Update changelog for version ${{ github.ref_name }}" | |
git push origin HEAD:main | |
# Step 2: Get the latest tag | |
- name: Get latest tag | |
id: get_tag | |
run: | | |
# Fetch all tags | |
git fetch --tags | |
# Get the latest tag | |
TAG=$(git describe --tags `git rev-list --tags --max-count=1`) | |
echo "latest_tag=$TAG" >> $GITHUB_ENV | |
# Step 4: Run release action with the latest tag | |
- name: Create or Update Release | |
uses: ncipollo/release-action@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
bodyFile: CHANGELOG.md | |
tag: ${{ env.latest_tag }} # Use the latest tag | |
allowUpdates: true |