CI Pipeline #84
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: Publish to PyPI | |
| on: | |
| release: | |
| types: [created] | |
| workflow_run: | |
| workflows: | |
| - Update PCI Database | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi-prod | |
| url: https://pypi.org/p/torchruntime | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build wheel pytest toml requests | |
| - name: Check PyPI version | |
| id: check-version | |
| run: | | |
| # Read version from pyproject.toml | |
| TOML_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | |
| # Get latest PyPI version using PyPI JSON API | |
| PYPI_VERSION=$(python -c "import requests; print(requests.get('https://pypi.org/pypi/torchruntime/json').json()['info']['version'])") | |
| echo "Local version: $TOML_VERSION" | |
| echo "PyPI version: $PYPI_VERSION" | |
| if [ "$TOML_VERSION" = "$PYPI_VERSION" ]; then | |
| echo "Versions match. Skipping publish." | |
| echo "publish=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Versions differ. Proceeding with publish." | |
| echo "publish=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Copy tests | |
| if: steps.check-version.outputs.publish == 'true' | |
| run: | | |
| cp -R tests torchruntime/ | |
| - name: Build package | |
| if: steps.check-version.outputs.publish == 'true' | |
| run: python -m build | |
| - name: Install and test the package | |
| if: steps.check-version.outputs.publish == 'true' | |
| run: | | |
| mkdir /tmp/install-test | |
| cp dist/*.whl /tmp/install-test | |
| cd /tmp/install-test | |
| pip install *.whl | |
| pip show torchruntime | |
| python -m torchruntime --help # test invocation | |
| pytest --pyargs torchruntime # run tests | |
| - name: Publish to PyPI | |
| if: steps.check-version.outputs.publish == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| # repository-url: https://test.pypi.org/legacy/ | |
| verbose: true |