Skip to content

Add pypi token as input secret to workflow #1

Add pypi token as input secret to workflow

Add pypi token as input secret to workflow #1

name: Build python package, create github release and publish to pypi
on:
workflow_call:
inputs:
run-environments:
description: List of OS to run test on
type: string
default: '["ubuntu-22.04", "macos-latest", "windows-latest"]'
python-versions:
description: Python versions to test
type: string
default: '["3.11"]'
secrets:
GITHUB_TOKEN:

Check failure on line 15 in .github/workflows/pypi_build_and_publish.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/pypi_build_and_publish.yml

Invalid workflow file

secret name `GITHUB_TOKEN` within `workflow_call` can not be used since it would collide with system reserved name
required: true
jobs:
build:
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(inputs.python-versions) }}
os: ${{ fromJSON(inputs.run-environments) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install the project dependencies
run: |
python -m pip install -e . wheel
- name: Build Packages
run: python setup.py sdist bdist_wheel
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
overwrite: true
publish-pypi:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
permissions:
id-token: write
runs-on: ubuntu-22.04
needs:
- build
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
github-release:
name: Sign Pyhon distribution and upload it as GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs:
- build
- publish-pypi
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'