Skip to content

Commit f5982b3

Browse files
committed
Improve release creation and publishing
The CI now also creates a draft release Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent e3a925a commit f5982b3

File tree

1 file changed

+70
-20
lines changed

1 file changed

+70
-20
lines changed

.github/workflows/pypi-release.yml

+70-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,82 @@
1-
name: Release library as a PyPI wheel and sdist on tag
1+
name: Create library release archives, create a GH release and publish PyPI wheel and sdist on tag in main branch
2+
3+
4+
# This is executed automatically on a tag in the main branch
5+
6+
# Summary of the steps:
7+
# - build wheels and sdist
8+
# - upload wheels and sdist to PyPI
9+
# - create gh-release and upload wheels and dists there
210

311
on:
4-
release:
5-
types: [created]
12+
workflow_dispatch:
13+
push:
14+
tags:
15+
- "v*.*.*"
616

717
jobs:
8-
build-and-publish-to-pypi:
18+
build-pypi-distribs:
919
name: Build and publish library to PyPI
1020
runs-on: ubuntu-24.04
21+
1122
steps:
12-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v4
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: 3.12
1328

14-
- name: Set up Python
15-
uses: actions/setup-python@v5
16-
with:
17-
python-version: 3.12
29+
- name: Install pypa/build and twine
30+
run: python -m pip install --user --upgrade build twine packaging pip setuptools
1831

19-
- name: Install pypa/build and twine
20-
run: python -m pip install --user --upgrade build twine packaging pip setuptools
32+
- name: Build a binary wheel and a source tarball
33+
run: python -m build --sdist --wheel --outdir dist/
2134

22-
- name: Build a binary wheel and a source tarball
23-
run: python -m build --sdist --wheel --outdir dist/ .
35+
- name: Validate wheel and sdis for Pypi
36+
run: python -m twine check dist/*
37+
38+
- name: Upload built archives
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: pypi_archives
42+
path: dist/*
43+
44+
45+
create-gh-release:
46+
name: Create GH release
47+
needs:
48+
- build-pypi-distribs
49+
runs-on: ubuntu-24.04
2450

25-
- name: Check wheel and sdist with twine
26-
run: python -m twine check dist/*
51+
steps:
52+
- name: Download built archives
53+
uses: actions/download-artifact@v4
54+
with:
55+
name: pypi_archives
56+
path: dist
57+
58+
- name: Create GH release
59+
uses: softprops/action-gh-release@v2
60+
with:
61+
draft: true
62+
files: dist/*
63+
64+
65+
create-pypi-release:
66+
name: Create PyPI release
67+
needs:
68+
- create-gh-release
69+
runs-on: ubuntu-24.04
70+
71+
steps:
72+
- name: Download built archives
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: pypi_archives
76+
path: dist
2777

28-
- name: Publish distribution to PyPI
29-
if: startsWith(github.ref, 'refs/tags')
30-
uses: pypa/gh-action-pypi-publish@release/v1
31-
with:
32-
password: ${{ secrets.PYPI_API_TOKEN }}
78+
- name: Publish to PyPI
79+
if: startsWith(github.ref, 'refs/tags')
80+
uses: pypa/gh-action-pypi-publish@release/v1
81+
with:
82+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)