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 7442528..da2df67 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..590ea36 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,24 @@ +name: Publish to Pypi + +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 index 9c01784..d6c2b8e 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -34,6 +34,21 @@ python -m pipx install pre-commit pre-commit install ``` +## Deployment + +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) + [nox]: https://nox.thea.codes/en/stable/index.html [pipx]: https://pypa.github.io/pipx/ [pre]: https://pre-commit.com/