Skip to content

Commit 7ca1961

Browse files
committed
Add GitHub Actions build/publish/sign/release workflow and Python 3.12 support.
1 parent 8ee6dff commit 7ca1961

5 files changed

+105
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: build-publish-sign-release
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
jobs:
7+
call-workflow-lint-test-cover-docs:
8+
name: Call linting/testing workflow.
9+
uses: ./.github/workflows/lint-test-cover-docs.yml
10+
secrets: inherit
11+
build:
12+
name: Build package.
13+
needs:
14+
- call-workflow-lint-test-cover-docs
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Install Python.
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.11
22+
architecture: x64
23+
- name: Install pypa/build.
24+
run: python -m pip install .[publish]
25+
- name: Build a source tarball and a binary wheel.
26+
run: python -m build --sdist --wheel .
27+
- name: Store the package distributions.
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: python-package-distributions
31+
path: dist/
32+
publish:
33+
name: Publish package to PyPI.
34+
if: startsWith(github.ref, 'refs/tags/') # Publish on tag pushes.
35+
needs:
36+
- build
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: pypi
40+
url: https://pypi.org/p/rabinmiller
41+
permissions:
42+
id-token: write
43+
steps:
44+
- name: Download all the package distributions.
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: python-package-distributions
48+
path: dist/
49+
- name: Publish package to PyPI.
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
sign-release:
52+
name: Sign package distributions with Sigstore and upload them to a GitHub release.
53+
needs:
54+
- publish
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write # For GitHub.
58+
id-token: write # For Sigstore.
59+
steps:
60+
- name: Download all the package distributions.
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: python-package-distributions
64+
path: dist/
65+
- name: Sign the package distributions with Sigstore.
66+
uses: sigstore/[email protected]
67+
with:
68+
inputs: >-
69+
./dist/*.tar.gz
70+
./dist/*.whl
71+
- name: Create a GitHub release.
72+
env:
73+
GITHUB_TOKEN: ${{ github.token }}
74+
run: gh release create '${{ github.ref_name }}' --repo '${{ github.repository }}'
75+
- name: Upload package distributions and signatures/certificates to the GitHub release.
76+
env:
77+
GITHUB_TOKEN: ${{ github.token }}
78+
run: >-
79+
gh release upload
80+
'${{ github.ref_name }}' dist/**
81+
--repo '${{ github.repository }}'

.github/workflows/lint-test-cover-docs.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
name: lint-test-cover-docs
22
on:
3-
push
3+
push:
4+
branches:
5+
- '**'
6+
workflow_call: # If invoked by build-publish-sign-release workflow.
47
jobs:
58
lint_test_cover_docs:
69
runs-on: ubuntu-latest
710
strategy:
811
matrix:
9-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
10-
name: "Python ${{ matrix.python-version }}"
12+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
13+
name: Python ${{ matrix.python-version }}
1114
steps:
1215
- uses: actions/checkout@v4
1316
- name: Install Python.

.readthedocs.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ python:
1414
- docs
1515

1616
build:
17-
os: "ubuntu-22.04"
17+
os: 'ubuntu-22.04'
1818
tools:
19-
python: "3.11"
19+
python: '3.11'

README.rst

+8-25
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
egcd
33
====
44

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

97
|pypi| |readthedocs| |actions| |coveralls|
108

@@ -86,15 +84,15 @@ All installation and development dependencies are fully specified in ``pyproject
8684

8785
.. code-block:: bash
8886
89-
python -m pip install .[docs,lint]
87+
python -m pip install ".[docs,lint]"
9088
9189
Documentation
9290
^^^^^^^^^^^^^
9391
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:
9492

9593
.. code-block:: bash
9694
97-
python -m pip install .[docs]
95+
python -m pip install ".[docs]"
9896
cd docs
9997
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
10098
@@ -104,7 +102,7 @@ All unit tests are executed and their coverage is measured when using `pytest <h
104102

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

118116
.. code-block:: bash
119117
120-
python -m pip install .[lint]
118+
python -m pip install ".[lint]"
121119
python -m pylint src/egcd
122120
123121
Contributions
@@ -130,28 +128,13 @@ Beginning with version 0.1.0, the version number format for this library and the
130128

131129
Publishing
132130
^^^^^^^^^^
133-
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:
131+
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/>`__.
134132

135-
.. code-block:: bash
136-
137-
python -m pip install .[publish]
133+
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.
138134

139-
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):
135+
To publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number):
140136

141137
.. code-block:: bash
142138
143139
git tag ?.?.?
144140
git push origin ?.?.?
145-
146-
Remove any old build/distribution files. Then, package the source into a distribution archive:
147-
148-
.. code-block:: bash
149-
150-
rm -rf build dist src/*.egg-info
151-
python -m build --sdist --wheel .
152-
153-
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__:
154-
155-
.. code-block:: bash
156-
157-
python -m twine upload dist/*

pyproject.toml

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "egcd"
3-
version = "1.0.0"
3+
version = "2.0.0"
44
description = """\
55
Pure-Python extended Euclidean algorithm implementation \
66
that accepts any number of integer arguments.\
@@ -24,14 +24,17 @@ docs = [
2424
"sphinx-rtd-theme~=1.1.0"
2525
]
2626
test = [
27-
"pytest~=7.4",
28-
"pytest-cov~=4.0"
27+
"pytest~=7.4; python_version < '3.12'",
28+
"pytest~=8.2; python_version >= '3.12'",
29+
"pytest-cov~=4.1; python_version < '3.12'",
30+
"pytest-cov~=5.0; python_version >= '3.12'"
2931
]
3032
lint = [
31-
"pylint~=2.17"
33+
"pylint~=2.17.0; python_version < '3.12'",
34+
"pylint~=3.2.0; python_version >= '3.12'"
3235
]
3336
coveralls = [
34-
"coveralls~=3.3.1"
37+
"coveralls~=4.0"
3538
]
3639
publish = [
3740
"build~=0.10",

0 commit comments

Comments
 (0)