publish-pypi #12
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-pypi | |
| on: | |
| workflow_run: | |
| workflows: ["semantic-release"] | |
| types: [completed] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag to publish (e.g. v0.4.35)" | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| if: > | |
| (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || | |
| (github.event_name == 'workflow_dispatch') | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout with tags | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve TAG | |
| id: tag | |
| shell: bash | |
| run: | | |
| if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then | |
| TAG="${{ github.event.inputs.tag }}" | |
| else | |
| git fetch --tags --force | |
| TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)" | |
| fi | |
| echo "TAG=$TAG" | tee -a "$GITHUB_ENV" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Build sdist & wheel | |
| run: | | |
| python -m pip install -U pip build | |
| python -m build | |
| - name: Publish to PyPI via OIDC | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist | |
| skip-existing: true | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Compute lowercase image tag | |
| id: img | |
| shell: bash | |
| run: | | |
| OWNER_LC="${GITHUB_REPOSITORY_OWNER,,}" | |
| REPO_LC="$(basename "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')" | |
| echo "IMAGE_TAG=ghcr.io/${OWNER_LC}/${REPO_LC}:${TAG}" | tee -a "$GITHUB_ENV" | |
| - name: Build & Push image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ env.IMAGE_TAG }} | |
| platforms: linux/amd64 |