Debian Codegraph @

.github/workflows/pypi-release.yml

raw
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
10 # TODO: smoke test wheels and sdist
11 # TODO: add changelog to release text body
12
13 # WARNING: this is designed only for packages building as pure Python wheels
14
15 on:
16 workflow_dispatch:
17 push:
18 tags:
19 - "v*.*.*"
20
21 jobs:
22 build-pypi-distribs:
23 name: Build and publish library to PyPI
24 runs-on: ubuntu-24.04
25
26 steps:
27 - uses: actions/checkout@v4
28 - name: Set up Python
29 uses: actions/setup-python@v4
30 with:
31 python-version: 3.9
32
33 - name: Install pypa/build
34 run: python -m pip install build --user
35
36 - name: Build a binary wheel and a source tarball
37 run: python -m build --sdist --wheel --outdir dist/
38
39 - name: Upload built archives
40 uses: actions/upload-artifact@v3
41 with:
42 name: pypi_archives
43 path: dist/*
44
45
46 create-gh-release:
47 # Sets permissions of the GITHUB_TOKEN to allow release upload
48 permissions:
49 contents: write
50 name: Create GH release
51 needs:
52 - build-pypi-distribs
53 runs-on: ubuntu-24.04
54
55 steps:
56 - name: Download built archives
57 uses: actions/download-artifact@v3
58 with:
59 name: pypi_archives
60 path: dist
61
62 - name: Create GH release
63 uses: softprops/action-gh-release@v1
64 with:
65 draft: true
66 files: dist/*
67
68
69 create-pypi-release:
70 name: Create PyPI release
71 needs:
72 - create-gh-release
73 runs-on: ubuntu-24.04
74
75 steps:
76 - name: Download built archives
77 uses: actions/download-artifact@v3
78 with:
79 name: pypi_archives
80 path: dist
81
82 - name: Publish to PyPI
83 if: startsWith(github.ref, 'refs/tags')
84 uses: pypa/gh-action-pypi-publish@release/v1
85 with:
86 password: ${{ secrets.PYPI_API_TOKEN }}