publish_python.yml•3.3 kB
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
name: Publish Python Package
on:
  workflow_dispatch:
    inputs:
      project_type:
        description: Type of project
        type: choice
        default: package
        required: true
        options:
          - packages
          - plugins
      project_name:
        description: Project name publishing to Pypi
        type: choice
        default: genkit
        required: true
        options:
          - genkit
          - compat-oai
          - dev-local-vectorstore
          - firebase
          - flask
          - google-cloud
          - google-genai
          - ollama
          - vertex-ai
jobs:
  python_build:
    name: Python build packages
    runs-on: ubuntu-latest
    env:
      PATH: ${{ github.workspace }}/.cargo/bin:${{ github.workspace }}/.local/bin:/usr/local/bin:/usr/bin:/bin
    strategy:
      matrix:
        python-version:
          - "3.12"
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y build-essential curl libffi-dev
      # Install rust for packages that requires it
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - name: Install toml-cli
        run: cargo install toml-cli
      - name: Install uv and setup Python version
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          python-version: ${{ matrix.python-version }}
      - name: Install Python dependencies
        run: |
          cd py/${{ github.event.inputs.project_type }}/${{ github.event.inputs.project_name }}
          uv pip install -e .[dev,test,docs]
          uv pip install twine toml
      - name: Build package and validate pypi
        run: |
          cd py
          PROJECT_NAME=${{ github.event.inputs.project_name }} PROJECT_TYPE=${{ github.event.inputs.project_type }}  ./bin/publish_pypi.sh
      - name: Upload build packages
        uses: actions/upload-artifact@v4
        with:
          name: dist
          path: py/dist/
  pypi_publish:
    name: Upload to PyPI
    needs: [python_build]
    runs-on: ubuntu-latest
    environment:
      # change to publish or similar in productive CI
      name: pypi_github_publishing
    permissions:
      id-token: write
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          name: dist
          path: py/dist/
      - name: Publish distribution to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          verbose: true
          packages-dir: py/dist/