Publish to PyPI #74
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: | |
| workflow_dispatch: | |
| inputs: | |
| test_publish: | |
| description: "Publish to test PyPI" | |
| type: boolean | |
| default: true | |
| push: | |
| branches: | |
| - "main" | |
| paths: | |
| - "cloud_fusion/__init__.py" | |
| pull_request: | |
| branches: | |
| - "main" | |
| concurrency: publish | |
| env: | |
| TEST_PUBLISH: ${{ inputs.test_publish && inputs.test_publish || github.event_name == 'pull_request' }} | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| name: Publish | |
| permissions: | |
| contents: write | |
| id-token: write | |
| environment: | |
| name: "pypi" | |
| url: "https://${{ env.TEST_PUBLISH == 'true' && 'test.' || '' }}pypi.org/project/cloud-fusion" | |
| steps: | |
| - name: Checkout 🔔 | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v10.0.0 | |
| with: | |
| resolution-strategy: "lowest" | |
| - name: Package Info | |
| id: package_info | |
| run: | | |
| current_version=$(sed -nE "s/^__version__ = ['\"]([^'\"]+)['\"].*$/\1/p" cloud_fusion/__init__.py) | |
| if [[ "${{ env.TEST_PUBLISH }}" == "true" ]]; then | |
| updated_version="${current_version}.${{ github.run_number }}" | |
| sed -i -E "s|(__version__\s+=\s['\"])${current_version}(['\"])|\1${updated_version}\2|g" cloud_fusion/__init__.py | |
| current_version="${updated_version}" | |
| fi | |
| echo "::notice file=cloud_fusion/__init__.py::version=${current_version}" | |
| echo "version=${current_version}" >> "$GITHUB_OUTPUT" | |
| - name: Add git tag | |
| if: ${{ env.TEST_PUBLISH == 'false' }} | |
| run: | | |
| tag="v${{ steps.package_info.outputs.version }}" | |
| git tag ${tag} | |
| git push origin ${tag} | |
| - name: Build | |
| run: uv build | |
| - name: Publish release distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: ${{ env.TEST_PUBLISH == 'true' && 'https://test.pypi.org/legacy/' || '' }} |