Skip to content

Commit

Permalink
create CD files for auto publishing on [test.]pypi.org
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOstrowski committed Feb 8, 2024
1 parent 0c319d9 commit 70eed9c
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/buildwheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build Wheel and source tarball
on:
# Creates a reusable workflow
workflow_call:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
test:
uses: ./.github/workflows/ci-test.yml
build-and-upload:
name: Build and upload
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python3 -m
build
--sdist
--wheel
--outdir dist/
.
- name: Upload binary wheel
uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/
5 changes: 5 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Run CI tests

on:
# Creates a reusable workflow
workflow_call:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Runs the workflow when adding to the main branch
push:
branches:
- main
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish to Pypi

on:
on:
push:
tags:
- v*.*.*

jobs:
build:
uses: ./.github/workflows/buildwheel.yml
pypi-publish:
name: Publish to PyPI
needs: [build]
permissions:
id-token: write
environment: release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: wheel
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
27 changes: 27 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to TestPypi

on:
# Creates a reusable workflow
workflow_call:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
uses: ./.github/workflows/buildwheel.yml
test-publish:
name: Publish to TestPyPI
needs: [build]
permissions:
id-token: write
environment: test-release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: wheel
path: dist
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
13 changes: 13 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To be able to release this project on [test.]pypi.org please follow these instructions:

Long version:
https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
TL;DR
- create a github environmnent (Github->Your Project->Settings->Environments) with the safety regulations you prefer, e.g. restriction
to a fixed set of branches like "test_release" or manual confirmation
This step is important to prevent other people from releasing new versions on accident
- create a [test.]pypi.org account (enable 2fa)
- create a project with the same name
- add the formerly created github environment
- run the respective CI scripts either manually (test.pypi.org) or by tagging a release version (pypi.org)

0 comments on commit 70eed9c

Please sign in to comment.