From 7ca1961aefef0dea230135d411a17aae4aea158e Mon Sep 17 00:00:00 2001 From: Andrei Lapets Date: Sat, 23 Nov 2024 15:36:50 -0500 Subject: [PATCH] Add GitHub Actions build/publish/sign/release workflow and Python 3.12 support. --- .../workflows/build-publish-sign-release.yml | 81 +++++++++++++++++++ .github/workflows/lint-test-cover-docs.yml | 9 ++- .readthedocs.yaml | 4 +- README.rst | 33 ++------ pyproject.toml | 13 +-- 5 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/build-publish-sign-release.yml diff --git a/.github/workflows/build-publish-sign-release.yml b/.github/workflows/build-publish-sign-release.yml new file mode 100644 index 0000000..365744c --- /dev/null +++ b/.github/workflows/build-publish-sign-release.yml @@ -0,0 +1,81 @@ +name: build-publish-sign-release +on: + push: + tags: + - '*' +jobs: + call-workflow-lint-test-cover-docs: + name: Call linting/testing workflow. + uses: ./.github/workflows/lint-test-cover-docs.yml + secrets: inherit + build: + name: Build package. + needs: + - call-workflow-lint-test-cover-docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Python. + uses: actions/setup-python@v5 + with: + python-version: 3.11 + architecture: x64 + - name: Install pypa/build. + run: python -m pip install .[publish] + - name: Build a source tarball and a binary wheel. + run: python -m build --sdist --wheel . + - name: Store the package distributions. + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + publish: + name: Publish package to PyPI. + if: startsWith(github.ref, 'refs/tags/') # Publish on tag pushes. + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/rabinmiller + permissions: + id-token: write + steps: + - name: Download all the package distributions. + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish package to PyPI. + uses: pypa/gh-action-pypi-publish@release/v1 + sign-release: + name: Sign package distributions with Sigstore and upload them to a GitHub release. + needs: + - publish + runs-on: ubuntu-latest + permissions: + contents: write # For GitHub. + id-token: write # For Sigstore. + steps: + - name: Download all the package distributions. + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Sign the package distributions with Sigstore. + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create a GitHub release. + env: + GITHUB_TOKEN: ${{ github.token }} + run: gh release create '${{ github.ref_name }}' --repo '${{ github.repository }}' + - name: Upload package distributions and signatures/certificates to the GitHub release. + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' diff --git a/.github/workflows/lint-test-cover-docs.yml b/.github/workflows/lint-test-cover-docs.yml index f003848..9a264f7 100644 --- a/.github/workflows/lint-test-cover-docs.yml +++ b/.github/workflows/lint-test-cover-docs.yml @@ -1,13 +1,16 @@ name: lint-test-cover-docs on: - push + push: + branches: + - '**' + workflow_call: # If invoked by build-publish-sign-release workflow. jobs: lint_test_cover_docs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] - name: "Python ${{ matrix.python-version }}" + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + name: Python ${{ matrix.python-version }} steps: - uses: actions/checkout@v4 - name: Install Python. diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1adbb5a..3bb79af 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -14,6 +14,6 @@ python: - docs build: - os: "ubuntu-22.04" + os: 'ubuntu-22.04' tools: - python: "3.11" + python: '3.11' diff --git a/README.rst b/README.rst index 151627c..e2aef46 100644 --- a/README.rst +++ b/README.rst @@ -2,9 +2,7 @@ egcd ==== -Pure-Python -`extended Euclidean algorithm `__ -implementation that accepts any number of integer arguments. +Pure-Python `extended Euclidean algorithm `__ implementation that accepts any number of integer arguments. |pypi| |readthedocs| |actions| |coveralls| @@ -86,7 +84,7 @@ All installation and development dependencies are fully specified in ``pyproject .. code-block:: bash - python -m pip install .[docs,lint] + python -m pip install ".[docs,lint]" Documentation ^^^^^^^^^^^^^ @@ -94,7 +92,7 @@ The documentation can be generated automatically from the source files using `Sp .. code-block:: bash - python -m pip install .[docs] + python -m pip install ".[docs]" cd docs sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html @@ -104,7 +102,7 @@ All unit tests are executed and their coverage is measured when using `pytest `__: @@ -117,7 +115,7 @@ Style conventions are enforced using `Pylint `__: .. code-block:: bash - python -m pip install .[lint] + python -m pip install ".[lint]" python -m pylint src/egcd Contributions @@ -130,28 +128,13 @@ Beginning with version 0.1.0, the version number format for this library and the Publishing ^^^^^^^^^^ -This library can be published as a `package on PyPI `__ by a package maintainer. First, install the dependencies required for packaging and publishing: +This library can be published as a `package on PyPI `__ via the GitHub Actions workflow found in ``.github/workflows/build-publish-sign-release.yml`` that follows the `recommendations found in the Python Packaging User Guide `__. -.. code-block:: bash - - python -m pip install .[publish] +Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule `__ that activates and sets as the default all tagged versions. -Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule `__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number): +To publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number): .. code-block:: bash git tag ?.?.? git push origin ?.?.? - -Remove any old build/distribution files. Then, package the source into a distribution archive: - -.. code-block:: bash - - rm -rf build dist src/*.egg-info - python -m build --sdist --wheel . - -Finally, upload the package distribution archive to `PyPI `__: - -.. code-block:: bash - - python -m twine upload dist/* diff --git a/pyproject.toml b/pyproject.toml index 1bdb5a1..1e796c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "egcd" -version = "1.0.0" +version = "2.0.0" description = """\ Pure-Python extended Euclidean algorithm implementation \ that accepts any number of integer arguments.\ @@ -24,14 +24,17 @@ docs = [ "sphinx-rtd-theme~=1.1.0" ] test = [ - "pytest~=7.4", - "pytest-cov~=4.0" + "pytest~=7.4; python_version < '3.12'", + "pytest~=8.2; python_version >= '3.12'", + "pytest-cov~=4.1; python_version < '3.12'", + "pytest-cov~=5.0; python_version >= '3.12'" ] lint = [ - "pylint~=2.17" + "pylint~=2.17.0; python_version < '3.12'", + "pylint~=3.2.0; python_version >= '3.12'" ] coveralls = [ - "coveralls~=3.3.1" + "coveralls~=4.0" ] publish = [ "build~=0.10",