Skip to content

ci: improve version bump workflow to handle no new commits #41

ci: improve version bump workflow to handle no new commits

ci: improve version bump workflow to handle no new commits #41

Workflow file for this run

name: Bump version and Create Release
on:
push:
branches:
- main
jobs:
test:
uses: ./.github/workflows/ci.yml
bump-version-and-release:
needs: test
if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }}
runs-on: ubuntu-latest
name: "Bump version, create changelog, and release"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install commitizen
- name: Bump version and create changelog
id: cz
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
output=$(cz bump --yes || echo "NO_BUMP")
if [[ $output == *"NO_BUMP"* ]]; then
echo "No new version to bump. Using current version."
version=$(cz version --project)
else
version=$(echo "$output" | grep -oP '(?<=tag: v).*')
fi
echo "version=$version" >> $GITHUB_OUTPUT
changelog=$(cz changelog || echo "No changes")
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$changelog" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Generate release notes
id: release_notes
run: |
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "# Release v${{ steps.cz.outputs.version }}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "## What's Changed" >> $GITHUB_OUTPUT
echo "${{ steps.cz.outputs.changelog }}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "## Full Changelog" >> $GITHUB_OUTPUT
echo "[Compare with previous release](https://github.com/${{ github.repository }}/compare/v$(git describe --tags --abbrev=0 HEAD^)...v${{ steps.cz.outputs.version }})" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
branch: ${{ github.ref }}
tags: true
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
tag_name: v${{ steps.cz.outputs.version }}
release_name: Release ${{ steps.cz.outputs.version }}
body: ${{ steps.release_notes.outputs.notes }}
draft: false
prerelease: false