From 0afc0e71bdcbc1a8ea4291d89252211cdb6376d8 Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 01:50:39 +0100 Subject: [PATCH 1/6] build: update build system to use hatchling --- pyproject.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d6504f9d9..aa7db86b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["setuptools>=61.0", "wheel"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "agentops" @@ -154,5 +154,9 @@ exclude = [ "tests/core_manual_tests", ] -[tool.setuptools] +[tool.hatch.build.targets.wheel] packages = ["agentops"] + +[tool.hatch.metadata] +allow-direct-references = true + From 0ce68d88609ddbd10f98a908670895fcfcf75a04 Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 02:17:40 +0100 Subject: [PATCH 2/6] ci: modernize package publishing workflow with UV - Replace setuptools/hatch with UV for building and publishing - Add manual testing options via workflow_dispatch: - dry-run: Test without publishing - testpypi: Test publish to TestPyPI - build-only: Test just the build step - Add safety measures: - Environment-specific configurations - Delays before publishing - Clear warning messages - Add GitHub CLI usage examples in comments - Enable trusted publishing --- .github/workflows/python-publish.yml | 74 ++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bdaab28a4..7161aa004 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,6 +1,20 @@ # This workflow will upload a Python Package using Twine when a release is created # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries +# To run this workflow manually using GitHub CLI: +# Test build only: +# gh workflow run "Upload Python Package" --ref main --field test_mode=build-only +# +# Test with dry run (no actual publish): +# gh workflow run "Upload Python Package" --ref main --field test_mode=dry-run +# +# Test publish to TestPyPI (requires TEST_PYPI_API_TOKEN secret): +# gh workflow run "Upload Python Package" --ref main --field test_mode=testpypi +# +# To check workflow status: +# gh run list --workflow "Upload Python Package" +# gh run view + # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support @@ -11,29 +25,59 @@ name: Upload Python Package on: release: types: [published] + workflow_dispatch: + inputs: + test_mode: + description: 'Test mode (dry-run, testpypi, build-only)' + required: true + default: 'dry-run' + type: choice + options: + - dry-run + - testpypi + - build-only permissions: contents: read + id-token: write # Required for trusted publishing jobs: deploy: - runs-on: ubuntu-latest - + environment: + name: ${{ github.event_name == 'release' && 'pypi' || 'test' }} + url: ${{ github.event_name == 'release' && 'https://pypi.org/p/agentops' || 'https://test.pypi.org/p/agentops' }} steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + + - name: Setup UV + uses: astral-sh/setup-uv@v5 with: python-version: '3.x' - - name: Install dependencies + + - name: Build and publish + env: + PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} + uv pip install build + uv build + + # Extra safety check + if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.test_mode }}" == "testpypi" ]]; then + echo "⚠️ Publishing to TestPyPI..." + sleep 5 # Give time to cancel if needed + fi + + if [[ "${{ github.event.inputs.test_mode }}" == "dry-run" ]]; then + echo "🔍 Performing dry run..." + uv publish --dry-run + elif [[ "${{ github.event.inputs.test_mode }}" == "testpypi" ]]; then + uv publish --repository https://test.pypi.org/legacy/ --token $TEST_PYPI_TOKEN + elif [[ "${{ github.event.inputs.test_mode }}" == "build-only" ]]; then + echo "✅ Build completed successfully. Skipping publish." + elif [[ "${{ github.event_name }}" == "release" ]]; then + echo "⚠️ Publishing to PyPI in 10 seconds... (Ctrl+C to cancel)" + sleep 10 + uv publish --token $PYPI_TOKEN + fi From ba3250f0d131899c167ec26bd0a2db20fb884f8a Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 02:52:07 +0100 Subject: [PATCH 3/6] ci(python-publish): cache glob, explicit py version --- .github/workflows/python-publish.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 7161aa004..3998eac7f 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -8,18 +8,13 @@ # Test with dry run (no actual publish): # gh workflow run "Upload Python Package" --ref main --field test_mode=dry-run # -# Test publish to TestPyPI (requires TEST_PYPI_API_TOKEN secret): +# Test publish to TestPyPI (requires TEST_PYPI_API_TOKEN): # gh workflow run "Upload Python Package" --ref main --field test_mode=testpypi # # To check workflow status: # gh run list --workflow "Upload Python Package" # gh run view -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - name: Upload Python Package on: @@ -49,11 +44,14 @@ jobs: url: ${{ github.event_name == 'release' && 'https://pypi.org/p/agentops' || 'https://test.pypi.org/p/agentops' }} steps: - uses: actions/checkout@v4 - + - name: Setup UV uses: astral-sh/setup-uv@v5 with: - python-version: '3.x' + python-version: "3.11" # Specify exact version + cache-dependency-glob: | + **/pyproject.toml + **/requirements*.txt - name: Build and publish env: From 23a2293067d0087dfc92ab515795b2519b193f87 Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 02:57:09 +0100 Subject: [PATCH 4/6] chore: update version to 0.3.23 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index aa7db86b5..f43de816e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "agentops" -version = "0.3.22" +version = "0.3.23" authors = [ { name="Alex Reibman", email="areibman@gmail.com" }, { name="Shawn Qiu", email="siyangqiu@gmail.com" }, From 8c5d17c60b4e7a64a343eceb44b534aace7655a7 Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 03:00:19 +0100 Subject: [PATCH 5/6] fix `uv publish` syntax Changed --repository to --publish-url for TestPyPI Changed --dry-run to --check-url for dry run mode (this will check if the package exists but won't upload) Left the build-only mode unchanged as it was working correctly Left the release mode with just --token as it uses the default PyPI URL Signed-off-by: Teo --- .github/workflows/python-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 3998eac7f..88d3506e3 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -69,9 +69,9 @@ jobs: if [[ "${{ github.event.inputs.test_mode }}" == "dry-run" ]]; then echo "🔍 Performing dry run..." - uv publish --dry-run + uv publish --check-url https://pypi.org/pypi elif [[ "${{ github.event.inputs.test_mode }}" == "testpypi" ]]; then - uv publish --repository https://test.pypi.org/legacy/ --token $TEST_PYPI_TOKEN + uv publish --publish-url https://test.pypi.org/legacy/ --token $TEST_PYPI_TOKEN elif [[ "${{ github.event.inputs.test_mode }}" == "build-only" ]]; then echo "✅ Build completed successfully. Skipping publish." elif [[ "${{ github.event_name }}" == "release" ]]; then From fa1ecd8ecf0392ee72345680d19381e89e02377d Mon Sep 17 00:00:00 2001 From: Teo Date: Sun, 12 Jan 2025 03:03:23 +0100 Subject: [PATCH 6/6] build: exclude unwanted globs from release --- pyproject.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index f43de816e..93a511788 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -157,6 +157,22 @@ exclude = [ [tool.hatch.build.targets.wheel] packages = ["agentops"] +[tool.hatch.build] +exclude = [ + "docs/*", + "examples/*", + "tests/*", + ".github/*", + "*.gif", + "*.png", + "dist/*", + "build/*", + ".pytest_cache", + ".ruff_cache", + "__pycache__", + "*.pyc" +] + [tool.hatch.metadata] allow-direct-references = true