Skip to content

Commit

Permalink
Use GitHub Action Trusted Publisher for PyPI publishing (#68)
Browse files Browse the repository at this point in the history
Use GitHub Action Trusted Publisher for PyPI publishing

- Separate push_to_pypi job into two jobs: build and push_to_pypi
- Use publish workflow file from current feature branch rather than main branch
- Do not use tox in publish workflow to build and upload package
- Remove twine dependency
- Remove references to PyPI secrets
  • Loading branch information
rbrazinskas authored Mar 18, 2024
1 parent 2e72484 commit 7a1c8a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
44 changes: 27 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
name: Upload to PyPI and publish documentation
name: Upload package to PyPI and publish documentation

on:
release:
types: [published]
workflow_dispatch:
workflow_call:
secrets:
PYPI_USER:
required: true
PYPI_PASSWORD:
required: true

jobs:
push_to_pypi:
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -26,15 +21,30 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev,cicd]"
- name: Build and publish
run: |
tox -e build
python -m twine check dist/*
python -m twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
python -m pip install build==1.0.3
- name: Build distribution
run: python -m build
- name: Store distribution packages
uses: actions/upload-artifact@v4
with:
name: dist
path: ./dist

push_to_pypi:
runs-on: ubuntu-latest
needs:
- build
environment:
name: pypi
url: https://pypi.org/p/iqm-cortex-cli
permissions:
id-token: write

steps:
- name: Download distribution packages
uses: actions/download-artifact@v4
- name: Publish distribution packages to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish_docs:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -83,7 +93,7 @@ jobs:
pip-licenses --format=confluence --with-urls > licenses.txt
cat -n licenses.txt | sort -uk2 | sort -n | cut -f2- > tmp && mv tmp licenses.txt # remove duplicate lines
- name: Upload license information artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dependencies-licenses
path: licenses.txt
5 changes: 1 addition & 4 deletions .github/workflows/tag_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,4 @@ jobs:
# created by the above job create_tag_and_release. Here we trigger the said workflow manually.
trigger_publishing:
needs: create_tag_and_release
uses: iqm-finland/cortex-cli/.github/workflows/publish.yml@main
secrets:
PYPI_USER: ${{ secrets.PYPI_USER }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
uses: ./.github/workflows/publish.yml
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 5.10
============

* Use GitHub Action as a Trusted Publisher to publish packages to PyPI. `#68 <https://github.com/iqm-finland/cortex-cli/pull/68>`_

Version 5.9
===========

Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ docs = [
"sphinx == 7.2.6",
"sphinx-book-theme == 1.1.2",
]
cicd = [
"twine == 4.0.2"
]

[project.scripts]
cortex = "iqm.cortex_cli.cortex_cli:cortex_cli"
Expand Down

0 comments on commit 7a1c8a3

Please sign in to comment.