feat: Add pytest integration (#25) #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # This workflow is used to publish the Python SDK to PyPI. | |
| # It is triggered by a tag push, and will only publish if the tag is valid. | |
| # The tag must match the format py-sdk-v*.*.* | |
| # | |
| name: Publish Python SDK | |
| on: | |
| push: | |
| tags: | |
| - "py-sdk-v*.*.*" # Trigger on version tags like py-sdk-v0.1.0, py-sdk-v1.2.3, etc. | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| outputs: | |
| release_tag: ${{ steps.set_release_tag.outputs.release_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for checking branch | |
| - name: Set release tag | |
| id: set_release_tag | |
| # ensure the tag is valid (matches code, is on main, etc) | |
| run: | | |
| RELEASE_TAG=${GITHUB_REF#refs/tags/} | |
| echo "Using tag: $RELEASE_TAG" | |
| ./py/scripts/validate-release-tag.sh "$RELEASE_TAG" | |
| echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV | |
| echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT | |
| build-and-publish: | |
| needs: validate | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: write | |
| id-token: write # Required for PyPI trusted publishing | |
| env: | |
| RELEASE_TAG: ${{ needs.validate.outputs.release_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for changelog generation | |
| - name: Set up mise | |
| uses: jdx/mise-action@v3 | |
| with: | |
| cache: true | |
| experimental: true | |
| install_args: [email protected] | |
| - name: Build and verify | |
| run: | | |
| mise exec [email protected] -- make -C py install-dev verify-build | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-sdk-dist | |
| path: py/dist/ | |
| retention-days: 5 | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: py/dist/ | |
| # Create GitHub Release | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| VERSION="${RELEASE_TAG#py-sdk-v}" | |
| RELEASE_NOTES=$(.github/scripts/generate-release-notes.sh "${{ env.RELEASE_TAG }}" "py/") | |
| echo "notes<<EOF" >> $GITHUB_OUTPUT | |
| echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| echo "release_name=Python SDK v${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: actions/github-script@v7 | |
| env: | |
| RELEASE_NOTES: ${{ steps.release_notes.outputs.notes }} | |
| RELEASE_NAME: ${{ steps.release_notes.outputs.release_name }} | |
| with: | |
| script: | | |
| await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: process.env.RELEASE_TAG, | |
| name: process.env.RELEASE_NAME, | |
| body: process.env.RELEASE_NOTES, | |
| draft: false, | |
| prerelease: false | |
| }); | |
| notify-success: | |
| needs: [validate, build-and-publish] | |
| if: always() && needs.build-and-publish.result == 'success' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| TAG="${{ github.ref_name }}" | |
| VERSION="${TAG#py-sdk-v}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Post to Slack on success | |
| uses: slackapi/[email protected] | |
| with: | |
| method: chat.postMessage | |
| token: ${{ secrets.SLACK_BOT_TOKEN }} | |
| payload: | | |
| channel: C0ABHT0SWA2 | |
| text: "✅ Python SDK v${{ steps.version.outputs.version }} published" | |
| blocks: | |
| - type: "header" | |
| text: | |
| type: "plain_text" | |
| text: "✅ Python SDK Published" | |
| - type: "section" | |
| text: | |
| type: "mrkdwn" | |
| text: "*Version:* ${{ steps.version.outputs.version }}\n*Package:* <https://pypi.org/project/braintrust/|braintrust>\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run>" | |
| notify-failure: | |
| needs: [validate, build-and-publish] | |
| if: always() && (needs.validate.result == 'failure' || needs.build-and-publish.result == 'failure') | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Post to Slack on failure | |
| uses: slackapi/[email protected] | |
| with: | |
| method: chat.postMessage | |
| token: ${{ secrets.SLACK_BOT_TOKEN }} | |
| payload: | | |
| channel: C0ABHT0SWA2 | |
| text: "🚨 Python SDK release failed" | |
| blocks: | |
| - type: "header" | |
| text: | |
| type: "plain_text" | |
| text: "🚨 Python SDK Release Failed" | |
| - type: "section" | |
| text: | |
| type: "mrkdwn" | |
| text: "*Tag:* ${{ github.ref_name }}\n*Commit:* ${{ github.sha }}\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run>" |