|
1 | 1 | # This workflow will |
| 2 | +# - will be triggered on each commit |
| 3 | +# - based on commit prefix will be created patch, minor, major release using `uv` |
2 | 4 | # - Find the latest version tag based on the commit history |
3 | 5 | # - Create a git tag for the new version |
4 | 6 | # - Update the version number in pyproject.toml based on the commit history |
5 | 7 | # - Upload the package to PyPI |
6 | 8 | # - Create a release on GitHub |
7 | 9 |
|
8 | 10 | # 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/ |
11 | 12 |
|
12 | | -name: Release |
| 13 | +name: Version & Release on Commit Prefix |
13 | 14 | on: |
14 | 15 | workflow_run: |
15 | | - workflows: ["test"] |
| 16 | + workflows: [ "test" ] |
16 | 17 | types: |
17 | 18 | - completed |
| 19 | + push: |
| 20 | + branches: |
| 21 | + - main |
| 22 | + |
18 | 23 | jobs: |
19 | | - release: |
| 24 | + bump_and_release: |
20 | 25 | runs-on: ubuntu-latest |
21 | 26 | concurrency: release |
| 27 | + environment: |
| 28 | + name: pypi |
22 | 29 | 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 |
24 | 32 |
|
25 | | - if: ${{ github.ref == 'refs/heads/main' && github.event.workflow_run.conclusion == 'success'}} |
26 | 33 | steps: |
27 | | - - uses: actions/checkout@v3 |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v5 |
28 | 36 | with: |
29 | 37 | fetch-depth: 0 |
30 | | - token: ${{ secrets.RELEASE }} |
31 | 38 |
|
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 }}' |
0 commit comments