Publish to PyPI #1
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
| # Copyright 2026 Datastrato, Inc. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| name: Publish to PyPI | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to publish (required for testpypi, e.g. 0.1.0.dev1). Ignored for pypi." | |
| required: false | |
| type: string | |
| environment: | |
| description: "Target PyPI environment" | |
| required: true | |
| type: choice | |
| default: "pypi" | |
| options: | |
| - "pypi" | |
| - "testpypi" | |
| ref: | |
| description: "Branch or tag to publish from (e.g. main, v0.1.0). Defaults to the branch selected above." | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: ${{ github.event.inputs.environment }} | |
| url: ${{ github.event.inputs.environment == 'pypi' && 'https://pypi.org/project/adp-sdk/' || 'https://test.pypi.org/project/adp-sdk/' }} | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.ref || github.ref }} | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Set up Python | |
| run: uv python install 3.13 | |
| - name: Resolve version | |
| run: | | |
| if [ "${{ github.event.inputs.environment }}" = "testpypi" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [ -z "${VERSION}" ]; then | |
| echo "Error: version input is required when publishing to testpypi" | |
| exit 1 | |
| fi | |
| echo "Patching pyproject.toml with version: ${VERSION}" | |
| sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" pyproject.toml | |
| else | |
| VERSION=$(uv run python -c "import tomllib; f=open('pyproject.toml','rb'); d=tomllib.load(f); print(d['project']['version'])") | |
| echo "Publishing version from pyproject.toml: ${VERSION}" | |
| fi | |
| - name: Build | |
| run: uv build --no-sources | |
| - name: Smoke test | |
| run: uv run --isolated --no-project --with "$(ls dist/*.whl)" -- python -c "import adp_sdk; print(adp_sdk.__version__)" | |
| - name: Publish | |
| run: | | |
| if [ "${{ github.event.inputs.environment }}" = "testpypi" ]; then | |
| uv publish --index testpypi | |
| else | |
| uv publish | |
| fi |