From 70eed9c3f91c4a6171ef8b8d8a5d8f8de5f49ba4 Mon Sep 17 00:00:00 2001 From: Max Ostrowski Date: Thu, 8 Feb 2024 14:57:51 +0100 Subject: [PATCH 1/2] create CD files for auto publishing on [test.]pypi.org --- .github/workflows/buildwheel.yml | 43 ++++++++++++++++++++++ .github/workflows/ci-test.yml | 5 +++ .github/workflows/publish-to-pypi.yml | 25 +++++++++++++ .github/workflows/publish-to-test-pypi.yml | 27 ++++++++++++++ DEVELOPMENT.md | 13 +++++++ 5 files changed, 113 insertions(+) create mode 100644 .github/workflows/buildwheel.yml create mode 100644 .github/workflows/publish-to-pypi.yml create mode 100644 .github/workflows/publish-to-test-pypi.yml create mode 100644 DEVELOPMENT.md diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml new file mode 100644 index 0000000..083ac43 --- /dev/null +++ b/.github/workflows/buildwheel.yml @@ -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/ diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5accb48..335e1c4 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -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 diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..d5f3baf --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -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 diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml new file mode 100644 index 0000000..08c0a82 --- /dev/null +++ b/.github/workflows/publish-to-test-pypi.yml @@ -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/ diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..29f849f --- /dev/null +++ b/DEVELOPMENT.md @@ -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) + From 2eaac77d6d713e50105ff66430e19d93fdc6d929 Mon Sep 17 00:00:00 2001 From: Max Ostrowski Date: Thu, 8 Feb 2024 14:59:13 +0100 Subject: [PATCH 2/2] correct syntax --- .github/workflows/publish-to-pypi.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index d5f3baf..590ea36 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,7 +1,6 @@ name: Publish to Pypi on: - on: push: tags: - v*.*.*