ci(release.yaml): use python-semantic-release instead of bump-my-version

This commit is contained in:
2024-09-25 18:02:07 +02:00
parent 26c46c680b
commit ab993698fe

View File

@@ -3,20 +3,37 @@ name: Bump version
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
bump_type:
type: choice
description: 'Type of bump'
required: true
options:
- 'patch'
- 'minor'
- 'major'
- 'pre_l'
- 'pre_n'
short_description: short_description:
type: string type: string
description: 'Short description of the release' description: 'Short description of the release'
required: false
auto_bump:
type: boolean
description: 'Auto bump version?'
required: true required: true
bump_type:
type: choice
description: 'Bump type'
required: true
options:
- 'major'
- 'minor'
- 'patch'
- 'prerelease'
as_pre_release:
type: boolean
description: 'As pre-release?'
required: true
prerelease_type:
type: choice
description: 'Pre-release label'
required: true
options:
- 'dev'
- 'alpha'
- 'beta'
- 'rc'
- 'post'
env: env:
GH_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }}
@@ -30,58 +47,86 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV
- name: 🔀 checkout - name: 🔀 checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
token: "${{ env.GH_TOKEN }}" token: "${{ env.GH_TOKEN }}"
- name: 🐍 python - name: 🐍 python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.x' python-version: '3.x'
cache: pip
- name: 📦 setup pdm - name: 📦 setup pdm
uses: pdm-project/setup-pdm@v4 uses: pdm-project/setup-pdm@v4
with: with:
cache: true cache: true
- name: 📦 install dependencies - name: 📦 install dependencies
run: pdm install run: |
pdm install
- name: configure git - name: configure git
run: | run: |
git config --global user.name "github-actions[bot]" git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: 📦 bump version
id: bump_version - name: 📦 bump version (auto)
if: ${{ github.event.inputs.auto_bump == 'true' }}
run: | run: |
bump-my-version ${{ github.event.inputs.bump_type }} if [ "${{ github.event.inputs.as_pre_release }}" == "true" ]; then
echo "BUMPED_VERSION=$(cat ${{ github.event.repository.name }}/__init__.py | grep __version__ | cut -d '"' -f 2)" >> $GITHUB_ENV pdm run semantic-release version --no-changelog --no-commit --no-push --as-prerelease --prerelease-token ${{ github.event.inputs.prerelease_type }}
else
pdm run semantic-release version --no-changelog --no-commit --no-push
fi
- name: 📦 bump version (manual)
if: ${{ github.event.inputs.auto_bump == 'false' }}
run: |
if [ "${{ github.event.inputs.as_pre_release }}" == "true" ]; then
pdm run semantic-release version --no-changelog --no-commit --no-push --${{ github.event.inputs.bump_type }} --as-prerelease --prerelease-token ${{ github.event.inputs.prerelease_type }}
else
pdm run semantic-release version --no-changelog --no-commit --no-push --${{ github.event.inputs.bump_type }}
fi
- name: 📦 get new version
id: get_version
run: echo "BUMPED_VERSION=$(cat ${{ github.event.repository.name }}/__init__.py | grep __version__ | cut -d '"' -f 2)" >> $GITHUB_OUTPUT
- name: 📝 create changelog - name: 📝 create changelog
run: | run: |
git-cliff -s header --unreleased -t ${{ steps.bump_version.outputs.BUMPED_VERSION }} > release_body.md pdm run git-cliff -s header -l > release_body.md
echo "Changes:" && cat release_body.md echo "Changes:" && cat release_body.md
git-cliff -t ${{ steps.bump_version.outputs.BUMPED_VERSION }} > CHANGELOG.md pdm run git-cliff > CHANGELOG.md
- name: 📤 push changes - name: 📤 push changes
run: | run: |
git add CHANGELOG.md ${{ github.event.repository.name }}/__init__.py git add CHANGELOG.md ${{ github.event.repository.name }}/__init__.py
git commit -m "chore(release): ${{ steps.bump_version.outputs.BUMPED_VERSION }}" git commit -m "chore(release): ${{ steps.get_version.outputs.BUMPED_VERSION }}"
git push origin main git push origin main
- name: create release - name: create release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
env: env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with: with:
name: ${{ github.event.repository.name }} ${{ steps.bump_version.outputs.BUMPED_VERSION }} - ${{ github.event.inputs.bump_type }} name: ${{ github.event.repository.name }} ${{ steps.get_version.outputs.BUMPED_VERSION }} - ${{ github.event.inputs.short_description }}
tag_name: ${{ steps.bump_version.outputs.BUMPED_VERSION }} tag_name: ${{ steps.get_version.outputs.BUMPED_VERSION }}
body_path: release_body.md body_path: release_body.md
prerelease: ${{ github.event.inputs.bump_type == 'pre_l' || github.event.inputs.bump_type == 'pre_n' }} prerelease: ${{ github.event.inputs.as_pre_release }}
discussion_category_name: 'Announcements' discussion_category_name: 'Announcements'
- name: 🧹 cleanup - name: 🧹 cleanup
run: | run: |
rm release_body.md rm release_body.md
- name: 📤 merge into develop - name: 📤 merge into develop
run: | run: |
git checkout develop git checkout develop
git merge main --no-ff git merge main --no-ff
git push origin develop git push origin develop
- name: ✅ done - name: ✅ done
run: echo "done" run: echo "done"