From 856ad8f8a6257ef312c9c4bb8323c0ebd49c6f43 Mon Sep 17 00:00:00 2001 From: Fangyin Cheng Date: Thu, 20 Mar 2025 15:01:46 +0800 Subject: [PATCH] ci(pypi): publish to pypi --- .github/workflows/python-publish.yml | 49 ++++++++++++++++++---------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index a957917d6..2735c238f 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -17,6 +17,17 @@ on: description: 'Package version (e.g. 0.7.0rc0)' required: true type: string + publish_to_testpypi: + description: 'Publish to TestPyPI' + required: false + type: boolean + default: false + publish_to_pypi: + description: 'Publish to PyPI' + required: false + type: boolean + default: false + permissions: contents: read @@ -24,18 +35,18 @@ jobs: deploy: name: python runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v4 - + - name: Install uv uses: astral-sh/setup-uv@v5 - + - name: "Set up Python" uses: actions/setup-python@v5 with: python-version-file: ".python-version" - + - name: Update version run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then @@ -47,29 +58,31 @@ jobs: else echo "Prepping package for release" fi + - name: Install the project run: uv sync --all-packages --dev - + - name: Build package using Make run: | make build ls dist/ - + - name: Upload wheel as artifact uses: actions/upload-artifact@v4 with: name: dist-packages path: dist/* retention-days: 7 - - # - name: Publish package to TestPyPI - # uses: pypa/gh-action-pypi-publish@release/v1 - # with: - # password: ${{ secrets.TEST_PYPI_API_TOKEN }} - # repository-url: https://test.pypi.org/legacy/ - - # - name: Publish package distributions to PyPI - # uses: pypa/gh-action-pypi-publish@release/v1 - # with: - # password: ${{ secrets.PYPI_API_TOKEN }} - \ No newline at end of file + + - name: Publish package to TestPyPI + if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish_to_testpypi == true }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ + + - name: Publish package distributions to PyPI + if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish_to_pypi == true) }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file