cache #41
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: change | |
on: | |
push: | |
branches: | |
- '*' | |
jobs: | |
changelog: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate | |
run: | | |
tags=($(git tag --merged $(git rev-parse HEAD) --sort=-creatordate)) | |
lastTag="" | |
previous="" | |
if [ -f CHANGELOG.md ]; then | |
lastTag=$(grep -oP '^## \K.*' CHANGELOG.md | head -n 1) | |
previous=$lastTag | |
fi | |
echo "Previous Tag: $previous" | |
for ((i = 0; i <= ${#tags[@]}; i++)); do | |
if (( i < ${#tags[@]} )); then | |
tag=${tags[$i]} | |
else | |
tag="" | |
fi | |
if [ -n "$lastTag" ] && [ "$(echo -e "$tag\n$lastTag" | sort -V | head -n 1)" == "$tag" ]; then | |
break | |
fi | |
if [ -n "$previous" ]; then | |
echo "## $previous" >> NEW_CHANGELOG.md | |
echo "" >> NEW_CHANGELOG.md | |
if [ -n "$tag" ]; then | |
git log --pretty=format:"%B" "$tag..$previous" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md | |
else | |
git log --pretty=format:"%B" "$previous" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md | |
fi | |
echo "" >> NEW_CHANGELOG.md | |
fi | |
previous=$tag | |
done | |
if [ -f CHANGELOG.md ]; then | |
cat CHANGELOG.md >> NEW_CHANGELOG.md | |
fi | |
mv NEW_CHANGELOG.md CHANGELOG.md | |
- name: Commit | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add CHANGELOG.md | |
if ! git diff --cached --quiet; then | |
git commit -m "Update Changelog" | |
git push | |
else | |
echo "CHANGELOG.md not changed" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |