Add GHA workflow to publish server to PyPI #3
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: Agent Memory Server CI | |
| on: | |
| push: | |
| branches: [main] | |
| tags: | |
| - 'server/v*.*.*' | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| test: | |
| name: Test and build (Python 3.12) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v3 | |
| - name: Install dependencies | |
| run: uv sync --all-extras | |
| - name: Install agent-memory-client (editable) | |
| run: uv pip install -e ./agent-memory-client | |
| - name: Lint with Ruff | |
| run: uv run ruff check | |
| - name: Check formatting with Ruff formatter | |
| run: uv run ruff format --check | |
| - name: Run tests | |
| run: uv run pytest --run-api-tests | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| - name: Build package | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| python -m build | |
| publish-testpypi: | |
| name: Publish to TestPyPI | |
| needs: test | |
| if: startsWith(github.ref, 'refs/tags/server/') && contains(github.ref, '-test') | |
| runs-on: ubuntu-latest | |
| environment: testpypi | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish package to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| packages-dir: dist/ | |
| publish-pypi: | |
| name: Publish to PyPI | |
| needs: test | |
| if: startsWith(github.ref, 'refs/tags/server/') && !contains(github.ref, '-test') | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish package to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ | |
| # Tag Format Guide: | |
| # - For TestPyPI (testing): server/v1.0.0-test | |
| # - For PyPI (production): server/v1.0.0 | |
| # | |
| # Use the script: python scripts/tag_and_push_server.py --test (for TestPyPI) | |
| # python scripts/tag_and_push_server.py (for PyPI) | |
| # | |
| # This workflow uses PyPI Trusted Publishing (OIDC). Ensure the project is configured | |
| # on PyPI to trust this GitHub repository before releasing. |