From d31f0153702e054eb80b78294fa569e849be779f Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Fri, 21 Feb 2025 09:52:11 +0100 Subject: [PATCH] Fix PyPi publishing (#42) --- .github/workflows/publish.yml | 42 +++++++++++++++++++++++++++-------- pyproject.toml | 10 ++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1d8dcb9..fdbe65b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,34 +1,58 @@ name: Publish to PyPI on: - push: - tags: - - 'v*' + workflow_run: + workflows: + - Invariant testing CI + types: + - completed + branches: + - v* jobs: pypi-publish: name: Upload release to PyPI - runs-on: ubuntu-latest + runs-on: ubuntu-latest environment: pypi-package + if: ${{ github.event.workflow_run.conclusion == 'success' && github.ref_type == 'tag' }} steps: - uses: actions/checkout@v4 - + - name: Set up Python 3.12.2 uses: actions/setup-python@v3 with: python-version: "3.12.2" - + - name: Setup dependencies run: | python -m pip install --upgrade pip - pip install poetry + pip install poetry==2.1.1 poetry install + - name: Build package + run: | + poetry build + + # Install invariant package in a virtual environment for testing + - name: Create virtual environment and install package + run: | + python -m venv venv + source venv/bin/activate + pip install dist/*.whl + + # Make sure the tests pass when the package is built and installed + - name: Run tests + env: + OPENAI_API_KEY: ${{ secrets.INVARIANT_TESTING_OPENAI_KEY }} + run: | + source venv/bin/activate + python -m pytest invariant/tests/ + - name: Set PyPI credentials run: | poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} - + - name: Publish to PyPI run: | - poetry publish --build \ No newline at end of file + poetry publish --dist-dir dist diff --git a/pyproject.toml b/pyproject.toml index c9aa062..e27e27d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,11 +54,5 @@ testpaths = ["invariant/tests"] invariant = "invariant.__main__:main" [build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" - -[tool.hatch.metadata] -allow-direct-references = true - -[tool.hatch.build.targets.wheel] -packages = ["invariant"] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"