|
| 1 | +name: Release on Main Merge |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + new_version: ${{ steps.bump_tag.outputs.new_version }} |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Install Python |
| 21 | + uses: actions/setup-python@v4 |
| 22 | + with: |
| 23 | + python-version: 3.11 |
| 24 | + |
| 25 | + - name: Get latest version |
| 26 | + id: get_version |
| 27 | + run: | |
| 28 | + version=$(curl -s https://pypi.org/pypi/judgeval/json | jq -r .info.version) |
| 29 | + echo "latest_version=$version" >> $GITHUB_OUTPUT |
| 30 | +
|
| 31 | + - name: Bump version and create new tag |
| 32 | + id: bump_tag |
| 33 | + run: | |
| 34 | + latest_version=${{ steps.get_version.outputs.latest_version }} |
| 35 | + echo "Latest version: $latest_version" |
| 36 | +
|
| 37 | + # Extract version numbers |
| 38 | + IFS='.' read -r major minor patch <<< "$latest_version" |
| 39 | +
|
| 40 | + # Bump patch version |
| 41 | + patch=$((patch + 1)) |
| 42 | + new_version="$major.$minor.$patch" |
| 43 | +
|
| 44 | + echo "New version: $new_version" |
| 45 | + echo "new_version=$new_version" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + git config user.name "github-actions" |
| 48 | + git config user.email "github-actions@github.com" |
| 49 | + git tag v$new_version |
| 50 | + git push origin v$new_version |
| 51 | +
|
| 52 | + - name: Create GitHub release |
| 53 | + uses: softprops/action-gh-release@v2 |
| 54 | + with: |
| 55 | + tag_name: v${{ steps.bump_tag.outputs.new_version }} |
| 56 | + generate_release_notes: true |
| 57 | + body: | |
| 58 | + You can find this package release on PyPI: https://pypi.org/project/judgeval/${{ steps.bump_tag.outputs.new_version }}/ |
| 59 | + env: |
| 60 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Bump pyproject.toml version |
| 63 | + run: | |
| 64 | + python update_version.py ${{ steps.bump_tag.outputs.new_version }} |
| 65 | +
|
| 66 | + - name: Build PyPI package |
| 67 | + run: | |
| 68 | + python -m pip install --upgrade build |
| 69 | + python -m build |
| 70 | +
|
| 71 | + - name: Create PyPI release |
| 72 | + run: | |
| 73 | + python -m pip install --upgrade twine |
| 74 | + python -m twine upload --repository pypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} dist/* |
| 75 | +
|
| 76 | + cleanup: |
| 77 | + needs: release |
| 78 | + if: failure() |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: Checkout code |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Authenticate GitHub CLI |
| 85 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token |
| 86 | + |
| 87 | + - name: Delete tag and release |
| 88 | + run: | |
| 89 | + gh release delete v${{ needs.release.outputs.new_version }} --yes |
| 90 | + git push --delete origin v${{ needs.release.outputs.new_version }} |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments