Skip to content

Commit 3df9c11

Browse files
committed
Add automatic release to PyPI and Github
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
1 parent 6500b29 commit 3df9c11

4 files changed

Lines changed: 179 additions & 78 deletions

File tree

.github/workflows/main.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Tests & Build
2+
3+
on:
4+
push:
5+
branches:
6+
- stable
7+
- dev
8+
tags:
9+
- v**
10+
pull_request:
11+
branches:
12+
- stable
13+
- dev
14+
15+
jobs:
16+
misc_tests:
17+
name: Misc tests
18+
container:
19+
image: fedorapython/fedora-python-tox
20+
options: --user 1001:1001
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Run tests
24+
run: tox -e ${{ matrix.tox_env }}
25+
strategy:
26+
matrix:
27+
tox_env:
28+
- lint
29+
- format
30+
- licenses
31+
- security
32+
- docs
33+
runs-on: ubuntu-latest
34+
35+
unit_tests:
36+
name: Unit tests
37+
container: fedorapython/fedora-python-tox:latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Mark the directory as safe for git
41+
run: git config --global --add safe.directory $PWD
42+
- name: Run tests
43+
run: tox -e ${{ matrix.tox_env }}
44+
strategy:
45+
matrix:
46+
tox_env:
47+
- py39-unittest
48+
- py310-unittest
49+
runs-on: ubuntu-latest
50+
51+
integration_tests:
52+
name: Integration tests
53+
steps:
54+
- uses: actions/checkout@v4
55+
- name: Install RabbitMQ
56+
uses: mer-team/rabbitmq-mng-action@v1.2
57+
with:
58+
RABBITMQ_TAG: "3-management-alpine"
59+
- name: Setup Python
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version: ${{ matrix.python }}
63+
- name: Install Tox
64+
run: pip install tox
65+
- name: Run integration tests
66+
# Run tox using the version of Python in `PATH`
67+
run: tox -e py-integration
68+
strategy:
69+
matrix:
70+
python:
71+
- "3.9"
72+
- "3.10"
73+
runs-on: ubuntu-latest
74+
75+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
76+
build:
77+
name: Build distribution 📦
78+
runs-on: ubuntu-latest
79+
needs:
80+
- misc_tests
81+
- unit_tests
82+
- integration_tests
83+
outputs:
84+
release-notes: ${{ steps.extract-changelog.outputs.markdown }}
85+
86+
steps:
87+
88+
- uses: actions/checkout@v4
89+
- name: Set up Python
90+
uses: actions/setup-python@v5
91+
with:
92+
python-version: "3.x"
93+
94+
- name: Install pypa/build
95+
run: python3 -m pip install build --user
96+
97+
- name: Build a binary wheel and a source tarball
98+
run: python3 -m build
99+
100+
- name: Store the distribution packages
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: python-package-distributions
104+
path: dist/
105+
106+
- name: Extract changelog section
107+
id: extract-changelog
108+
uses: sean0x42/markdown-extract@v2
109+
with:
110+
file: docs/release_notes.md
111+
pattern: 'v[[:digit:].]+'
112+
no-print-matched-heading: true
113+
- name: Show the changelog
114+
env:
115+
CHANGELOG: ${{ steps.extract-changelog.outputs.markdown }}
116+
run: echo "$CHANGELOG"
117+
118+
119+
publish-to-pypi:
120+
name: Publish to PyPI 🚀
121+
# only publish to PyPI on final tag pushes
122+
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'rc')
123+
needs:
124+
- build
125+
runs-on: ubuntu-latest
126+
environment:
127+
name: pypi
128+
url: https://pypi.org/p/noggin-aaa
129+
permissions:
130+
id-token: write # IMPORTANT: mandatory for trusted publishing
131+
132+
steps:
133+
- name: Download all the dists
134+
uses: actions/download-artifact@v4
135+
with:
136+
name: python-package-distributions
137+
path: dist/
138+
139+
- name: Publish distribution to PyPI
140+
uses: pypa/gh-action-pypi-publish@release/v1
141+
142+
143+
github-release:
144+
name: Create a GitHub Release 📢
145+
needs:
146+
- publish-to-pypi
147+
- build
148+
runs-on: ubuntu-latest
149+
permissions:
150+
contents: write # IMPORTANT: mandatory for making GitHub Releases
151+
id-token: write # IMPORTANT: mandatory for sigstore
152+
153+
steps:
154+
- name: Download all the dists
155+
uses: actions/download-artifact@v4
156+
with:
157+
name: python-package-distributions
158+
path: dist/
159+
160+
- name: Sign the dists with Sigstore
161+
uses: sigstore/gh-action-sigstore-python@v2.1.1
162+
with:
163+
inputs: >-
164+
./dist/*.tar.gz
165+
./dist/*.whl
166+
167+
- name: Release
168+
uses: softprops/action-gh-release@v1
169+
with:
170+
files: dist/*
171+
fail_on_unmatched_files: true
172+
body: ${{ needs.build.outputs.release-notes }}

.github/workflows/tests.yml

Lines changed: 0 additions & 71 deletions
This file was deleted.

docs/contributing.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,13 @@ Releasing
192192

193193
When cutting a new release, follow these steps:
194194

195-
#. Update the version in ``pyproject.toml``
195+
#. Update the version in ``pyproject.toml`` by running ``poetry version major|minor|patch``
196+
depending on the contents of the release.
197+
#. Run ``poetry install`` to update the package's metadata.
196198
#. Add missing authors to the release notes fragments by changing to the ``news`` directory and
197199
running the ``get-authors.py`` script, but check for duplicates and errors
198-
#. Generate the release notes by running ``poetry run towncrier`` (in the base directory)
199-
#. Adjust the release notes in ``docs/release_notes.rst``.
200+
#. Generate the release notes by running ``poetry run towncrier build`` (in the base directory)
201+
#. Adjust the release notes in ``docs/release_notes.md``.
200202
#. Generate the docs with ``tox -r -e docs`` and check them in ``docs/_build/html``.
201203
#. Commit the changes
202204
#. Push the commit to the upstream Github repository (via a PR or not).
@@ -205,9 +207,7 @@ When cutting a new release, follow these steps:
205207
#. Tag the commit with ``-s`` to generate a signed tag
206208
#. Push the commit to the upstream Github repository with ``git push``,
207209
and the new tag with ``git push --tags``
208-
#. Generate a tarball and push to PyPI with the command ``poetry publish --build``
209-
#. Create `the release on GitHub <https://github.com/fedora-infra/noggin/tags>`_ and copy the
210-
release notes in there,
210+
#. The tarball will be automatically published to PyPI, and a Github release will be created.
211211
#. Deploy and announce.
212212

213213

news/_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ reviews for this release:
6060
{% for text, values in sections[section]["author"].items() -%}
6161
- {{ text }}
6262
{% endfor -%}
63-
{%- endif -%}
63+
{%- endif %}
6464

6565
{% else -%}
6666
No significant changes.

0 commit comments

Comments
 (0)