Skip to content

Publish Python SDK to TestPyPI #3

Publish Python SDK to TestPyPI

Publish Python SDK to TestPyPI #3

#
# This workflow is used to publish the Python SDK to TestPyPI. You do not need to upgrade the
# version number to use this. Only upgrade the version number when you are ready to publish to
# PyPI. The script will automatically add an "rc" suffix to the version number for test.pypi.org
# releases, so you can push a version number to test.pypi.org multiple times.
#
name: Publish Python SDK to TestPyPI
on:
workflow_dispatch:
inputs:
ref:
description: "Publish the given Git ref to test.pypi.org (branch, tag, or commit SHA)"
required: true
type: string
default: "main"
jobs:
build-and-publish-test:
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
id-token: write # Required for PyPI trusted publishing
outputs:
version: ${{ steps.get_version.outputs.version }}
env:
PYPI_REPO: testpypi
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref }}
- name: Set up mise
uses: jdx/mise-action@v3
with:
cache: true
experimental: true
install_args: python@3.13
- name: Install build dependencies
run: |
mise exec python@3.13 -- make -C py install-dev
- name: Build and verify
run: |
mise exec python@3.13 -- make -C py verify-build
- name: Get version from built wheel
id: get_version
run: |
WHEEL=$(ls py/dist/*.whl | head -n 1)
VERSION=$(echo "$WHEEL" | sed -n 's/.*braintrust-\([^-]*\)-.*/\1/p')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: py/dist/
notify-success:
needs: build-and-publish-test
if: success()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Post to Slack on success
uses: slackapi/slack-github-action@v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: C0ABHT0SWA2
text: "🧪 Python SDK pre-release v${{ needs.build-and-publish-test.outputs.version }} published to TestPyPI"
blocks:
- type: "header"
text:
type: "plain_text"
text: "🧪 Python SDK Pre-release Published"
- type: "section"
text:
type: "mrkdwn"
text: "*Version:* ${{ needs.build-and-publish-test.outputs.version }}\n*Ref:* ${{ github.event.inputs.ref }}\n*Install:* `pip install -i https://test.pypi.org/simple/ braintrust==${{ needs.build-and-publish-test.outputs.version }}`\n*Package:* <https://test.pypi.org/project/braintrust/|braintrust (TestPyPI)>\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run>"
notify-failure:
needs: build-and-publish-test
if: failure()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Post to Slack on failure
uses: slackapi/slack-github-action@v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: C0ABHT0SWA2
text: "🚨 Python SDK TestPyPI release failed"
blocks:
- type: "header"
text:
type: "plain_text"
text: "🚨 Python SDK TestPyPI Release Failed"
- type: "section"
text:
type: "mrkdwn"
text: "*Ref:* ${{ github.event.inputs.ref }}\n*Commit:* ${{ github.sha }}\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run>"