ci: add semantic-release for automatic versioning
- python-semantic-release analyzes conventional commits - Auto-bump version (MAJOR/MINOR/PATCH) - Auto-generate CHANGELOG - Auto-create git tags - Publish on tag only
This commit is contained in:
parent
ee7c5b7933
commit
aff4017eff
@ -7,8 +7,60 @@ on:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
semantic-release:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.ref == 'refs/heads/main'
|
||||
outputs:
|
||||
new_release_version: ${{ steps.semantic.outputs['new_release_version'] }}
|
||||
new_release_published: ${{ steps.semantic.outputs['new_release_published'] }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Use system Python
|
||||
run: |
|
||||
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: uv sync --group dev
|
||||
|
||||
- name: Run semantic-release
|
||||
id: semantic
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GIT_AUTHOR_NAME: claw-bot
|
||||
GIT_AUTHOR_EMAIL: claw-bot@much-data.ru
|
||||
GIT_COMMITTER_NAME: claw-bot
|
||||
GIT_COMMITTER_EMAIL: claw-bot@much-data.ru
|
||||
run: |
|
||||
uv run semantic-release version --no-push
|
||||
NEW_VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
||||
echo "new_release_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
# Check if version changed
|
||||
if git diff --quiet pyproject.toml; then
|
||||
echo "new_release_published=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "new_release_published=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Commit and push version bump
|
||||
if: steps.semantic.outputs.new_release_published == 'true'
|
||||
run: |
|
||||
uv run semantic-release changelog
|
||||
git add pyproject.toml CHANGELOG.md
|
||||
git commit -m "chore(release): v${{ steps.semantic.outputs.new_release_version }} [skip ci]"
|
||||
git tag v${{ steps.semantic.outputs.new_release_version }}
|
||||
git push origin main --tags
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [semantic-release]
|
||||
if: github.ref == 'refs/tags/v*' || github.event_name == 'push'
|
||||
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
|
||||
@ -35,6 +35,7 @@ dev = [
|
||||
"pytest-html>=4.0.0",
|
||||
"respx>=0.20.0",
|
||||
"ruff>=0.3.0",
|
||||
"semantic-release>=24.0.0",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user