Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 19 additions & 60 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: release

on:
push:
branches:
- main
workflow_dispatch:
inputs:
release-version:
Expand All @@ -27,11 +24,13 @@ jobs:
test:
uses: ./.github/workflows/test.yaml

check-version:
# Only run version check for manual releases
if: github.event_name == 'workflow_dispatch' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
check-semver:
# Do not release if not triggered from the default branch
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)

runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout the code
uses: actions/checkout@v4
Expand Down Expand Up @@ -60,9 +59,8 @@ jobs:
exit 1

release:
needs: test
# For manual releases, also need version check
if: always() && needs.test.result == 'success' && (needs.check-version.result == 'success' || needs.check-version.result == 'skipped')
needs: [test, check-semver]

runs-on: ubuntu-latest
timeout-minutes: 30

Expand All @@ -81,52 +79,6 @@ jobs:
- name: Install the project
run: uv sync --frozen --all-groups --python 3.12

- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "version=${{ inputs.release-version }}" >> $GITHUB_OUTPUT
else
# For automatic releases, use semantic versioning
# Get the latest tag
latest_tag=$(git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $latest_tag"

# Check commit messages for version bump type
commits=$(git log ${latest_tag}..HEAD --pretty=format:"%s")
echo "Commits since last tag:"
echo "$commits"

# Determine version bump based on conventional commits
if echo "$commits" | grep -q "^feat\|^BREAKING CHANGE"; then
# Minor version bump for features
new_version=$(echo $latest_tag | sed 's/v//' | awk -F. '{print "v" ($1"."($2+1)".0")}')
elif echo "$commits" | grep -q "^fix\|^perf"; then
# Patch version bump for fixes
new_version=$(echo $latest_tag | sed 's/v//' | awk -F. '{print "v" $1"."$2"."($3+1)}')
else
echo "No version-bumping commits found, skipping release"
exit 0
fi

echo "version=$new_version" >> $GITHUB_OUTPUT
fi

- name: Update version in pyproject.toml
run: |
version="${{ steps.version.outputs.version }}"
# Remove 'v' prefix if present
version=${version#v}

# Update version in pyproject.toml
sed -i "s/version = \"[^\"]*\"/version = \"$version\"/" pyproject.toml

# Commit the version change
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: bump version to $version" || echo "No changes to commit"

- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v5
Expand All @@ -136,14 +88,21 @@ jobs:

- name: Create and push git tag
run: |
version="${{ steps.version.outputs.version }}"
# Configure git
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"

# Tag the release
git tag -a "$version" -m "Release version $version"
git tag -a "${{ inputs.release-version }}" -m "Release version ${{ inputs.release-version }}"

# Checkout the git tag
git checkout "${{ inputs.release-version }}"

# Push the changes and tags
# Push the modified changelogs
git push origin main
git push origin "$version"

# Push the tags
git push origin "${{ inputs.release-version }}"

- name: Build the wheel and sdist
run: uv build
Expand All @@ -157,5 +116,5 @@ jobs:
- name: Create GitHub Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
with:
tag_name: ${{ steps.version.outputs.version }}
tag_name: ${{ inputs.release-version }}
body: ${{steps.github_release.outputs.changelog}}