Skip to content

feat: add action for releasing to PyPI #15

feat: add action for releasing to PyPI

feat: add action for releasing to PyPI #15

Workflow file for this run

name: PyPI Release
on:
pull_request:
# test only, must publish on tag creation only
branches: [ "main" ]
push:
tags:
- 'v*' # Triggers on version tags
jobs:
release:
name: Publish on PyPI
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Build
run: |
pip install build &&
python -m build
# - name: Get OIDC Token
# id: get-token
# run: |
# pip install id &&
# python -c "import os, id; print(f'''OIDC_TOKEN={id.detect_credential(audience='testpypi')}''')" >> $GITHUB_OUTPUT
- name: Publish
run: |
pip install id twine &&
oidc_token=$(python -m id testpypi)
resp=$(curl -X POST https://test.pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
api_token=$(jq -r '.token' <<< "${resp}")
twine upload --verbose --username __token__ --password ${api_token} --repository testpypi dist/*