Publish to PyPI #1
This file contains 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_call: | |
inputs: | |
package: | |
description: "Choose the package to publish" | |
type: string | |
default: "dbt-athena" | |
deploy-to: | |
description: "Choose whether to publish to test or prod" | |
type: string | |
default: "prod" | |
branch: | |
description: "Choose the branch to publish" | |
type: string | |
default: "main" | |
workflow_dispatch: | |
inputs: | |
package: | |
description: "Choose the package to publish" | |
type: string | |
default: "dbt-athena" | |
deploy-to: | |
description: "Choose whether to publish to test or prod" | |
type: string | |
default: "test" | |
branch: | |
description: "Choose the branch to publish" | |
type: string | |
default: "main" | |
permissions: | |
contents: read | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ inputs.deploy-to }} | |
url: ${{ vars.PYPI_PROJECT_URL }}/${{ inputs.package }} | |
permissions: | |
# this permission is required for trusted publishing | |
# see https://github.com/marketplace/actions/pypi-publish | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.branch }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ vars.DEFAULT_PYTHON_VERSION }} | |
- uses: pypa/hatch@install | |
# hatch will build using test PyPI first and fall back to prod PyPI when deploying to test | |
# this is done via environment variables in the test environment in GitHub | |
- run: hatch build && hatch run build:check-all | |
working-directory: ./${{ inputs.package }} | |
- uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: ${{ vars.PYPI_REPOSITORY_URL }} | |
packages-dir: ${{ inputs.package }}/dist/ | |
verify: | |
runs-on: ubuntu-latest | |
needs: publish | |
# check the correct index | |
environment: | |
name: ${{ inputs.deploy-to }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.branch }} | |
- id: version | |
run: echo "version=$(hatch version)" >> $GITHUB_OUTPUT | |
working-directory: ./${{ inputs.package }} | |
- uses: nick-fields/retry@v3 | |
with: | |
timeout_seconds: 10 | |
retry_wait_seconds: 10 | |
max_attempts: 15 # 5 minutes: (10s timeout + 10s delay) * 15 attempts | |
command: wget ${{ vars.PYPI_PROJECT_URL }}/${{ inputs.package }}/${{ steps.version.outputs.version }} |