Skip to content

Commit

Permalink
Update publish workflow to use Trusted Publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Stormheg committed Nov 16, 2023
1 parent 3a54c75 commit 2cec24c
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

name: Publish to PyPI
on:
release:
types: [created]
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
types: [released]
workflow_dispatch:

jobs:
deploy:
test:
uses: ./.github/workflows/ci.yml

build:
needs: ['test']
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
pip install build
- name: Build package distributions
run: python -m build

- uses: actions/upload-artifact@v3
with:
path: ./dist

# https://docs.pypi.org/trusted-publishers/using-a-publisher/
pypi-publish:
needs: ['build']
environment: 'publish'

name: Upload release to PyPI
runs-on: ubuntu-latest
permissions:
# Mandatory for trusted publishing
id-token: write
steps:
- uses: actions/download-artifact@v3

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifact/
print-hash: true

0 comments on commit 2cec24c

Please sign in to comment.