Skip to content

commit

commit #28

name: Increment Version
concurrency: automated-release
on:
push:
branches:
- dev
workflow_dispatch:
jobs:
increment_version:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: python -m pip install packaging
- name: Get current tag
id: get_current_tag
run: |
CURRENT_TAG=$(git tag --sort=-creatordate | head -n 1)
echo "Current tag: ${CURRENT_TAG}"
echo "current_tag=${CURRENT_TAG}" >> $GITHUB_OUTPUT
- name: Generate new version
id: generate_version
# Outputs a new version number in the format of 'new_version=1.0.0'
run: |
NEW_VERSION=$(python ./.github/scripts/bump-version.py)
echo "New version: ${NEW_VERSION}"
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Update setup.py version
run: |
NEW_VERSION=${{ steps.generate_version.outputs.new_version }}
sed -i "s/version='.*'/version='${NEW_VERSION}'/" setup.py
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git add setup.py
git commit -m "Update setup.py version to ${NEW_VERSION}"
- name: Create Tag
id: create_tag
run: |
NEW_TAG="v${{ steps.generate_version.outputs.new_version }}"
git tag -a "${NEW_TAG}" -m "Release ${NEW_TAG}"
git push origin "${NEW_TAG}"
- name: Generate commit message list
id: generate_commit_message_list
run: |
# Get commit messages since last release in bullet point format
COMMIT_MESSAGES=$(git log --pretty=format:"- %s" "${{ steps.get_current_tag.outputs.current_tag }}..HEAD" | grep -vE "#patch|#minor|#major")
# URL encode newlines to %0A for GitHub Actions output compatibility
COMMIT_MESSAGES="${COMMIT_MESSAGES//$'\n'/%0A}"
# Prepend header to the commit messages, URL encoding the newlines
COMMIT_MESSAGES="Whats changed since last release%0A%0A${COMMIT_MESSAGES}"
echo "Commit messages: ${COMMIT_MESSAGES//%0A/$'\n'}"
echo "commit_messages<<EOF" >> $GITHUB_OUTPUT
echo -e "${COMMIT_MESSAGES//%0A/$'\n'}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create release
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create_tag.outputs.new_tag }}
release_name: Release ${{ steps.create_tag.outputs.new_tag }}
body: ${{ steps.generate_commit_message_list.outputs.commit_messages }}
draft: false
prerelease: false