Skip to content

Commit

Permalink
Create changelog.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosalmi authored Jun 27, 2024
1 parent c024ec2 commit 2b08045
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Generate changelog

on:
push:
paths:
- 'setup_disabled.py' # Only trigger when setup.py is changed
branches:
- main # Adjust to the branches you want to trigger releases
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9' # Use the Python version you are targeting

- name: Extract version from setup.py
id: extract_version
run: |
VERSION=$(python -c "import re; version_line = next(line for line in open('setup.py') if line.strip().startswith('version=')); print(re.search(r'version=[\"\\']([^\"\\']+)[\"\\']', version_line).group(1))")
echo "VERSION=$VERSION" >> $GITHUB_ENV
shell: bash

- name: Get previous setup.py commit
id: previous_commit
run: |
echo "Finding previous setup.py commit..."
PREV_COMMIT=$(git log -2 --pretty=format:"%H" -- setup.py | tail -n 1)
echo "PREV_COMMIT=${PREV_COMMIT}" >> $GITHUB_ENV
echo "Previous setup.py commit: ${PREV_COMMIT}"
- name: Generate changelog
id: changelog
run: |
PREV_COMMIT=${{ env.PREV_COMMIT }}
CURRENT_VERSION=${{ env.VERSION }}
echo "Generating changelog from $PREV_COMMIT to HEAD"
if [ -n "$PREV_COMMIT" ]; then
git log $PREV_COMMIT..HEAD --pretty=format:"- %s" > changelog.txt
else
git log HEAD --pretty=format:"- %s" > changelog.txt
fi
echo "## Version $CURRENT_VERSION - $(date +'%Y-%m-%d')" > CHANGELOG.md
cat changelog.txt >> CHANGELOG.md
echo "" >> CHANGELOG.md
cat CHANGELOG.md
- name: Commit and push changelog
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
git add CHANGELOG.md
git commit -m "Update changelog for version ${{ env.VERSION }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 2b08045

Please sign in to comment.