Skip to content

Commit

Permalink
Add GitHub Actions build/publish/sign/release workflow and Python 3.1…
Browse files Browse the repository at this point in the history
…2 support.
  • Loading branch information
lapets committed Nov 23, 2024
1 parent 8ee6dff commit 7ca1961
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 35 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build-publish-sign-release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}'
9 changes: 6 additions & 3 deletions .github/workflows/lint-test-cover-docs.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ python:
- docs

build:
os: "ubuntu-22.04"
os: 'ubuntu-22.04'
tools:
python: "3.11"
python: '3.11'
33 changes: 8 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
egcd
====

Pure-Python
`extended Euclidean algorithm <https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm>`__
implementation that accepts any number of integer arguments.
Pure-Python `extended Euclidean algorithm <https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm>`__ implementation that accepts any number of integer arguments.

|pypi| |readthedocs| |actions| |coveralls|

Expand Down Expand Up @@ -86,15 +84,15 @@ 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
^^^^^^^^^^^^^
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:

.. 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
Expand All @@ -104,7 +102,7 @@ All unit tests are executed and their coverage is measured when using `pytest <h

.. code-block:: bash
python -m pip install .[test]
python -m pip install ".[test]"
python -m pytest
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:
Expand All @@ -117,7 +115,7 @@ Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:

.. code-block:: bash
python -m pip install .[lint]
python -m pip install ".[lint]"
python -m pylint src/egcd
Contributions
Expand All @@ -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 <https://pypi.org/project/egcd>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:
This library can be published as a `package on PyPI <https://pypi.org/project/egcd>`__ 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 <https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/>`__.

.. 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 <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ 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 <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ 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 <https://pypi.org>`__:

.. code-block:: bash
python -m twine upload dist/*
13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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.\
Expand All @@ -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",
Expand Down

0 comments on commit 7ca1961

Please sign in to comment.