1- # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
1+ # Adapted from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
32
4- name : " Publish to PyPI"
3+ name : Publish to PyPI
4+ on : push
5+ jobs :
56
6- on :
7- push :
8- tags :
9- - " *"
7+ build :
8+ name : Build distribution
9+ runs-on : ubuntu-latest
1010
11- permissions :
12- contents : " read"
11+ steps :
12+ - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
13+ - name : Set up Python
14+ uses : actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5
15+ with :
16+ python-version : " 3.x"
17+ - name : Install pypa/build
18+ run : python3 -m pip install build --user
19+ - name : Build a binary wheel and a source tarball
20+ run : python3 -m build
21+ - name : Store the distribution packages
22+ uses : actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4
23+ with :
24+ name : python-package-distributions
25+ path : dist/
1326
14- jobs :
15- publish :
16- name : " Publish to PyPI"
17- runs-on : " ubuntu-latest"
27+ publish-to-pypi :
28+ name : >-
29+ Publish to PyPI
30+ if : startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
31+ needs :
32+ - build
33+ runs-on : ubuntu-latest
1834 environment :
19- name : " publish"
35+ name : pypi
36+ url : https://pypi.org/p/idna # Replace <package-name> with your PyPI project name
37+ permissions :
38+ id-token : write # IMPORTANT: mandatory for trusted publishing
39+
2040 steps :
21- - name : " Checkout repository"
22- uses : " actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b"
41+ - name : Download all the dists
42+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
43+ with :
44+ name : python-package-distributions
45+ path : dist/
46+ - name : Publish distribution to PyPI
47+ uses : pypa/gh-action-pypi-publish@release/v1
2348
24- - name : " Setup Python"
25- uses : " actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5"
49+ github-release :
50+ name : Sign and upload GitHub Release
51+ needs :
52+ - publish-to-pypi
53+ runs-on : ubuntu-latest
54+
55+ permissions :
56+ contents : write # IMPORTANT: mandatory for making GitHub Releases
57+ id-token : write # IMPORTANT: mandatory for sigstore
58+
59+ steps :
60+ - name : Download the dists
61+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
2662 with :
27- python-version : " 3.x"
63+ name : python-package-distributions
64+ path : dist/
65+ - name : Sign with Sigstore
66+ uses : sigstore/gh-action-sigstore-python@v2.1.1
67+ with :
68+ inputs : >-
69+ ./dist/*.tar.gz
70+ ./dist/*.whl
71+ - name : Create GitHub Release
72+ env :
73+ GITHUB_TOKEN : ${{ github.token }}
74+ run : >-
75+ gh release create
76+ '${{ github.ref_name }}'
77+ --repo '${{ github.repository }}'
78+ --notes ""
79+ - name : Upload artifact signatures to GitHub Release
80+ env :
81+ GITHUB_TOKEN : ${{ github.token }}
82+ # Upload to GitHub Release using the `gh` CLI.
83+ # `dist/` contains the built packages, and the
84+ # sigstore-produced signatures and certificates.
85+ run : >-
86+ gh release upload
87+ '${{ github.ref_name }}' dist/**
88+ --repo '${{ github.repository }}'
89+
90+ # publish-to-testpypi:
91+ # name: Publish to Test PyPI
92+ # needs:
93+ # - build
94+ # runs-on: ubuntu-latest
95+
96+ # environment:
97+ # name: testpypi
98+ # url: https://test.pypi.org/p/idna
2899
29- - name : " Build dists"
30- run : |
31- python -m pip install build
32- python -m build
100+ # permissions:
101+ # id-token: write # IMPORTANT: mandatory for trusted publishing
33102
34- - name : " Publish to PyPI"
35- uses : " pypa/gh-action-pypi-publish@37f50c210e3d2f9450da2cd423303d6a14a6e29f"
103+ # steps:
104+ # - name: Download all the dists
105+ # uses: actions/download-artifact@v4
106+ # with:
107+ # name: python-package-distributions
108+ # path: dist/
109+ # - name: Publish distribution to TestPyPI
110+ # uses: pypa/gh-action-pypi-publish@release/v1
111+ # with:
112+ # verbose: true
113+ # print-hash: true
114+ # repository-url: https://test.pypi.org/legacy/
0 commit comments