Skip to content

Update ChangelogUpdate.yml #7

Update ChangelogUpdate.yml

Update ChangelogUpdate.yml #7

Workflow file for this run

name: Automated Changelog Update
on:
push:
tags:
- 'v*.*.*' # Trigger the workflow on version tags
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install yq
run: |
sudo apt-get update
sudo apt-get install -y python3-pip
pip3 install yq
- name: Fetch tags
run: git fetch --tags
- name: Check if release.yml exists
run: test -f .github/release.yml || (echo "release.yml not found" && exit 1)
- name: Get changelog
id: changelog
run: |
TAG=$(git describe --tags --abbrev=0)
GIT_LOG=$(git log $TAG..HEAD --pretty=format:"%H %s [%an]")
CHANGELOG=""
# Check if yq can parse the file
if ! yq eval '.' .github/release.yml > /dev/null 2>&1; then
echo "Error parsing release.yml"
exit 1
fi
# Read release.yml for categories
CATEGORIES=$(yq eval '.changelog.categories' .github/release.yml)
TAG=$(git describe --tags --abbrev=0)
GIT_LOG=$(git log $TAG..HEAD --pretty=format:"%H %s [%an]")
# Iterate over categories
for i in $(seq 0 $(echo "$CATEGORIES" | yq eval 'length' -)); do
TITLE=$(echo "$CATEGORIES" | yq eval ".[$i].title" -)
LABELS=$(echo "$CATEGORIES" | yq eval ".[$i].labels[]" -)
CHANGELOG="${CHANGELOG}### ${TITLE}\n"
# Get log entries for each label
for LABEL in $LABELS; do
LOG_ENTRIES=$(echo "$GIT_LOG" | grep -i "$LABEL")
if [ -n "$LOG_ENTRIES" ]; then
CHANGELOG="${CHANGELOG}${LOG_ENTRIES}\n"
fi
done
done
# Escape special characters
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
CHANGELOG="${CHANGELOG//'#'/''}"
echo "::set-output name=content::$CHANGELOG"
- name: Display changelog
run: echo "${{ steps.changelog.outputs.content }}"
- name: Update changelog
run: |
NEW_CHANGELOG="${{ steps.changelog.outputs.content }}"
sed -i '/## Semantic Versioning/{:a;n;/##/!ba;i\\n'"${NEW_CHANGELOG}"'\\n' changelog.md
cat changelog.md
- name: Commit and push changelog update
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add changelog.md
git commit -m "Update changelog for release ${{ github.ref }}"
git push origin main