1- name : Build Python distributions and publish on PyPI
1+ name : Build Python distributions, publish on PyPI, and create a GH release
22
33on :
44 workflow_dispatch :
55 push :
66 tags :
77 - " v*.*.*"
88
9+ env :
10+ PYPI_PROJECT_URL : " https://pypi.org/p/scancodeio"
11+
912jobs :
10- build-and-publish :
11- name : Build and publish library to PyPI
13+ build-python-dist :
14+ name : Build Python distributions
1215 runs-on : ubuntu-24.04
16+ permissions :
17+ contents : read
1318
1419 steps :
1520 - name : Checkout repository
@@ -23,26 +28,61 @@ jobs:
2328 python-version : 3.14
2429
2530 - name : Install pypa/build
26- run : python -m pip install build==1.4.0 --user
31+ run : python -m pip install build --user
2732
2833 - name : Build a binary wheel and a source tarball
29- run : python -m build --sdist --wheel --outdir dist/ .
34+ run : python -m build --sdist --wheel --outdir dist/
3035
31- - name : Publish to PyPI
32- if : startsWith(github.ref, 'refs/tags')
33- uses : pypa/gh-action-pypi-publish@release/v1
36+ - name : Upload package distributions as GitHub workflow artifacts
37+ uses : actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
3438 with :
35- password : ${{ secrets.PYPI_API_TOKEN }}
39+ name : python-package-distributions
40+ path : dist/
3641
37- - name : Upload built archives
38- uses : actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
42+ # Only set the id-token: write permission in the job that does publishing, not globally.
43+ # Also, separate building from publishing — this makes sure that any scripts
44+ # maliciously injected into the build or test environment won't be able to elevate
45+ # privileges while flying under the radar.
46+ pypi-publish :
47+ name : Upload package distributions to PyPI
48+ if : startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
49+ needs :
50+ - build-python-dist
51+ runs-on : ubuntu-24.04
52+ environment :
53+ name : pypi
54+ url : ${{ env.PYPI_PROJECT_URL }}
55+ permissions :
56+ id-token : write # IMPORTANT: this permission is mandatory for trusted publishing
57+
58+ steps :
59+ - name : Download package distributions
60+ uses : actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
61+ with :
62+ name : python-package-distributions
63+ path : dist/
64+
65+ - name : Publish to PyPI
66+ uses : pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
67+
68+ create-gh-release :
69+ name : Create GitHub release
70+ needs :
71+ - build-python-dist
72+ runs-on : ubuntu-24.04
73+ permissions :
74+ contents : write
75+
76+ steps :
77+ - name : Download package distributions
78+ uses : actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
3979 with :
40- name : pypi_archives
41- path : dist/*
80+ name : python-package-distributions
81+ path : dist/
4282
43- - name : Create a GitHub release
44- uses : softprops/action-gh-release@v2
83+ - name : Create GH release
84+ uses : softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
4585 with :
46- generate_release_notes : true
4786 draft : false
87+ generate_release_notes : true
4888 files : dist/*
0 commit comments