Matt/script py release #9
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
| name: Auto Publish Python SDK | |
| on: | |
| pull_request: | |
| branches: | |
| - main # Trigger on pull requests to main branch for testing | |
| push: | |
| tags: | |
| - "v*.*.*" # Trigger on version tags like v0.1.0, v1.2.3, etc. | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag to publish (e.g., v0.1.0)" | |
| required: true | |
| type: string | |
| env: | |
| CHECKOUT_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || (github.event_name == 'pull_request' && github.event.pull_request.head.sha) || github.ref }} | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| 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 | |
| ref: ${{ env.CHECKOUT_REF }} | |
| - name: Set release tag | |
| id: set_release_tag | |
| run: | | |
| # If triggered by a workflow_dispatch | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| RELEASE_TAG="${{ github.event.inputs.tag }}" | |
| echo "Using manually specified tag: $RELEASE_TAG" | |
| # If triggered by a tag push | |
| elif [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| RELEASE_TAG=${GITHUB_REF#refs/tags/} | |
| echo "Using tag: $RELEASE_TAG" | |
| else | |
| # If triggered by a PR, use the current version from the code | |
| cd py | |
| VERSION=$(bash scripts/get_version.sh) | |
| RELEASE_TAG="v$VERSION" | |
| echo "Using current version: $RELEASE_TAG" | |
| fi | |
| echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV | |
| echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT | |
| - name: Validate release tag | |
| run: | | |
| ./py/scripts/validate-release-tag.sh "$RELEASE_TAG" | |
| test: | |
| needs: validate | |
| runs-on: ubuntu-latest | |
| strategy: | |
| # As of 2024-11-08, this test takes roughly 60 seconds. There is not much benefit to fail-fast. | |
| fail-fast: false | |
| matrix: | |
| python-version: | |
| - "3.9" | |
| - "3.10" | |
| - "3.11" | |
| - "3.12" | |
| - "3.13" | |
| env: | |
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY}} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY}} | |
| RELEASE_TAG: ${{ needs.validate.outputs.release_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.CHECKOUT_REF }} | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install -e "py[all]" | |
| python -m pip install --upgrade pip setuptools build twine pylint nox pre-commit | |
| - name: Verify the code | |
| working-directory: py | |
| run: | | |
| # FIXME[matt] just linting while in ddev | |
| make lint | |
| build-and-publish: | |
| needs: [test, validate] | |
| runs-on: ubuntu-latest | |
| env: | |
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }} | |
| RELEASE_TAG: ${{ needs.validate.outputs.release_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.CHECKOUT_REF }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install -e "py[all]" | |
| python -m pip install --upgrade pip setuptools build twine pylint nox pre-commit | |
| - name: Verify, build and publish to TestPyPI | |
| working-directory: py | |
| run: | | |
| make publish-to-testpypi |