Skip to content

Update Changelog

Update Changelog #1

Workflow file for this run

name: Update Changelog
on:
workflow_dispatch:
release:
types: [published]
jobs:
update-changelog:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Update Changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create or update CHANGELOG.md with new release notes
# Install GitHub CLI
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
# Fetch all releases
gh release list --limit 100 > releases.txt
# Check if CHANGELOG.md exists, create if not
if [ ! -f CHANGELOG.md ]; then
touch CHANGELOG.md
fi
# Temporary file for new changelog
temp_changelog=$(mktemp)
# Write new releases to temp file
echo "# Changelog" > "$temp_changelog"
echo "" >> "$temp_changelog"
# Fetch details for releases not in current changelog
while read -r release_info; do
tag=$(echo "$release_info" | awk '{print $1}')
# Check if release is already in changelog
if ! grep -q "$tag" CHANGELOG.md; then
echo "## $tag" >> "$temp_changelog"
echo "" >> "$temp_changelog"
# Fetch release notes
release_notes=$(gh release view "$tag" --json body --jq .body)
# Add release notes, handling potential multiline content
echo "$release_notes" >> "$temp_changelog"
echo "" >> "$temp_changelog"
fi
done < releases.txt
# Append existing changelog content
if [ -f CHANGELOG.md ]; then
tail -n +2 CHANGELOG.md >> "$temp_changelog"
fi
# Replace old changelog
mv "$temp_changelog" CHANGELOG.md
# Commit and push changes if there are any
if [[ $(git status --porcelain) ]]; then
git config user.name github-actions
git config user.email [email protected]
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md with new release notes"
git push
fi