Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use github as trusted publisher on PyPI #124

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions .github/workflows/poetry-publish.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
name: Publish on Pypi
# Workflow following resources at:
# - https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-pypi
# - https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives
# Jobs are split to prevent unneccessary priviledge elevation through write permissions during building.

name: Build and publish on Pypi

on:
release:
types: [published]
branches: [main]

permissions:
contents: read

jobs:
build:
run-tests:
uses: ./.github/workflows/poetry-pytest.yml
secrets: inherit

release-build:
name: Build python wheels
needs:
- run-tests
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4
# https://github.com/JRubics/poetry-publish
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.17
- name: Set up Python
# https://github.com/actions/setup-python
uses: actions/setup-python@v5.1.1
with:
python-version: "3.12"

- name: Install Poetry
run: |
pip install poetry

- name: Build source and wheel archives
run: poetry build

- name: Upload distributions
# https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
name: release-dists
path: dist/

pypi-publish:
name: Upload release to PyPI
needs:
- release-build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/gimie
permissions:
id-token: write
# IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Retrieve release distributions
# https://github.com/actions/download-artifact
uses: actions/download-artifact@v4.1.8
with:
name: release-dists
path: dist/
- name: Publish package distributions to PyPI
# https://github.com/pypa/gh-action-pypi-publish
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion .github/workflows/poetry-pytest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tests

on: [push]
on: [push, workflow_call]

jobs:

Expand Down
67 changes: 59 additions & 8 deletions .github/workflows/poetry-test-publish.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
name: Publish on Pypi Test
# Workflow following resources at:
# - https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-pypi
# - https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives
# Jobs are split to prevent unneccessary priviledge elevation through write permissions during building.

name: Build and publish on Pypi Test

on:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
run-tests:
uses: ./.github/workflows/poetry-pytest.yml
secrets: inherit

test-build:
name: Build python wheels
needs:
- run-tests
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4
- name: Build and publish to pypi
# https://github.com/JRubics/poetry-publish
uses: JRubics/poetry-publish@v1.17
- name: Set up Python
# https://github.com/actions/setup-python
uses: actions/setup-python@v5.1.1
with:
python-version: "3.12"

- name: Install Poetry
run: |
pip install poetry

- name: Build source and wheel archives
run: poetry build

- name: Upload distributions
# https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
pypi_token: ${{ secrets.PYPI_TEST_API_TOKEN }}
repository_name: "testpypi"
repository_url: "https://test.pypi.org/legacy/"
name: test-dists
path: dist/

pypi-test-publish:
name: Upload release to PyPI Test
needs:
- test-build
runs-on: ubuntu-latest
environment:
name: test-pypi
url: https://test.pypi.org/p/gimie
permissions:
id-token: write
# IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Retrieve release distributions
# https://github.com/actions/download-artifact
uses: actions/download-artifact@v4.1.8
with:
name: test-dists
path: dist/
- name: Publish package distributions to TestPyPI
# https://github.com/pypa/gh-action-pypi-publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
Loading