Skip to content

Commit b649e6f

Browse files
authored
ci: New release workflow (#3448)
* add sematic release * add main release * fix: update action * merge semantic with release * run release after tests passed * add benchmark to minor releases
1 parent 179702e commit b649e6f

File tree

2 files changed

+109
-45
lines changed

2 files changed

+109
-45
lines changed

.github/workflows/release.yml

Lines changed: 109 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,131 @@
11
# This workflow will
2+
# - will be triggered on each commit
3+
# - based on commit prefix will be created patch, minor, major release using `uv`
24
# - Find the latest version tag based on the commit history
35
# - Create a git tag for the new version
46
# - Update the version number in pyproject.toml based on the commit history
57
# - Upload the package to PyPI
68
# - Create a release on GitHub
79

810
# This workflow required the following secrets to be set:
9-
# - a GitHub personal access token with the `repo` scope called `RELEASE`
10-
# - and that you setup trusted publishing using PyPI as described here: https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
11+
# repo setup trusted publishing using PyPI as described here: https://docs.pypi.org/trusted-publishers/
1112

12-
name: Release
13+
name: Version & Release on Commit Prefix
1314
on:
1415
workflow_run:
15-
workflows: ["test"]
16+
workflows: [ "test" ]
1617
types:
1718
- completed
19+
push:
20+
branches:
21+
- main
22+
1823
jobs:
19-
release:
24+
bump_and_release:
2025
runs-on: ubuntu-latest
2126
concurrency: release
27+
environment:
28+
name: pypi
2229
permissions:
23-
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing using PyPI
30+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing using PyPI
31+
contents: write # for updating pyproject
2432

25-
if: ${{ github.ref == 'refs/heads/main' && github.event.workflow_run.conclusion == 'success'}}
2633
steps:
27-
- uses: actions/checkout@v3
34+
- name: Checkout code
35+
uses: actions/checkout@v5
2836
with:
2937
fetch-depth: 0
30-
token: ${{ secrets.RELEASE }}
3138

32-
- name: Python Semantic Release
33-
id: release
34-
uses: python-semantic-release/[email protected]
35-
with:
36-
github_token: ${{ secrets.RELEASE }}
37-
changelog: "false"
38-
39-
- name: Publish package distributions to PyPI
40-
uses: pypa/gh-action-pypi-publish@release/v1
41-
if: steps.release.outputs.released == 'true'
42-
# This action supports PyPI's trusted publishing implementation, which allows authentication to PyPI without a manually
43-
# configured API token or username/password combination. To perform trusted publishing with this action, your project's
44-
# publisher must already be configured on PyPI.
45-
46-
- name: Publish package distributions to GitHub Releases
47-
uses: python-semantic-release/[email protected]
48-
if: steps.release.outputs.released == 'true'
49-
with:
50-
github_token: ${{ secrets.RELEASE }}
39+
- name: Get last commit message
40+
id: last_commit
41+
run: |
42+
msg=$(git log -1 --pretty=%B)
43+
echo "commit message: '$msg'"
44+
{
45+
echo "msg<<EOF"
46+
echo "$msg"
47+
echo "EOF"
48+
} >> "$GITHUB_OUTPUT"
49+
50+
- name: Determine bump type
51+
id: bump_type
52+
run: |
53+
msg="${{ steps.last_commit.outputs.msg }}"
54+
low=$(echo "$msg" | tr '[:upper:]' '[:lower:]')
55+
echo "lowercase message: '$low'"
56+
57+
bump="none"
58+
if [[ $low == breaking:* ]]; then
59+
bump="major"
60+
elif [[ $low == feat:* ]] || [[ $low == benchmark:* ]]; then
61+
bump="minor"
62+
elif [[ $low == fix:* ]] || [[ $low == dataset:* ]] || [[ $low == model:* ]]; then
63+
bump="patch"
64+
fi
65+
66+
echo "bump=$bump" >> "$GITHUB_OUTPUT"
67+
echo "Determined bump type: $bump"
68+
69+
- name: Exit if no bump
70+
if: ${{ steps.bump_type.outputs.bump == 'none' }}
71+
run: |
72+
echo "No recognized prefix for version bump. Exiting."
73+
exit 0
74+
75+
- name: Install uv
76+
uses: astral-sh/setup-uv@v6
77+
78+
- name: Bump version
79+
id: version_bump
80+
run: |
81+
echo "Running uv version --bump ${{ steps.bump_type.outputs.bump }}"
82+
uv version --bump "${{ steps.bump_type.outputs.bump }}"
83+
84+
# Capture the new version (second token from `uv version`)
85+
ver=$(uv version | awk '{print $2}')
86+
echo "New version detected: $ver"
87+
echo "new_version=$ver" >> "$GITHUB_OUTPUT"
88+
89+
- name: Commit version bump and tag
90+
env:
91+
GITHUB_TOKEN: ${{ github.token }}
92+
run: |
93+
git config user.name "github-actions[bot]"
94+
git config user.email "github-actions[bot]@users.noreply.github.com"
95+
96+
git add pyproject.toml
97+
git commit -m "chore: bump version to ${{ steps.version_bump.outputs.new_version }}" || echo "No changes to commit."
98+
99+
# push changes and tag safely
100+
git push origin HEAD:main
101+
102+
- name: Create GitHub Release
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
run: |
106+
tag="v${{ steps.version_bump.outputs.new_version }}"
107+
echo "Creating release for tag $tag"
108+
gh release create "$tag" --generate-notes --repo "${{ github.repository }}"
109+
110+
- name: Build
111+
run: uv build
112+
113+
# Check that basic features work and we didn't miss to include crucial files
114+
- name: Smoke test (wheel)
115+
run: uv run --isolated --no-project --with dist/*.whl python -c "import mteb"
116+
- name: Smoke test (source distribution)
117+
run: uv run --isolated --no-project --with dist/*.tar.gz python -c "import mteb"
118+
119+
- name: Publish
120+
run: uv publish
121+
122+
- name: Upload artifacts to Release
123+
env:
124+
GITHUB_TOKEN: ${{ github.token }}
125+
# Upload to GitHub Release using the `gh` CLI.
126+
# `dist/` contains the built packages, and the
127+
# sigstore-produced signatures and certificates.
128+
run: >-
129+
gh release upload
130+
'${{ github.ref_name }}' dist/**
131+
--repo '${{ github.repository }}'

pyproject.toml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,23 +251,6 @@ convention = "google"
251251
mypy-init-return = true
252252
suppress-none-returning = true
253253

254-
[tool.semantic_release]
255-
branch = "main"
256-
version_toml = ["pyproject.toml:project.version"]
257-
build_command = "python -m pip install build; python -m build"
258-
tag_format = "{version}"
259-
260-
[tool.semantic_release.commit_parser_options]
261-
major_tags = ["breaking"]
262-
minor_tags = ["minor", "feat"]
263-
patch_tags = [
264-
"patch",
265-
"fix",
266-
"perf",
267-
"model",
268-
"dataset",
269-
]
270-
271254
[tool.pytest.ini_options]
272255
addopts = """
273256
--reruns 3

0 commit comments

Comments
 (0)