Skip to content

Commit a7c0349

Browse files
committed
add pypi
1 parent 1c5e972 commit a7c0349

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

.github/workflows/python-publish.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
2+
name: send into pip
3+
4+
on: push
5+
6+
jobs:
7+
build:
8+
name: Build distribution 📦
9+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.x"
20+
- name: Install pypa/build
21+
run: >-
22+
python3 -m
23+
pip install
24+
build
25+
--user
26+
- name: Build a binary wheel and a source tarball
27+
run: python3 -m build
28+
- name: Store the distribution packages
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: python-package-distributions
32+
path: dist/
33+
34+
publish-to-pypi:
35+
name: >-
36+
Publish Python 🐍 distribution 📦 to PyPI
37+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
38+
needs:
39+
- build
40+
runs-on: ubuntu-latest
41+
environment:
42+
name: pypi
43+
url: https://pypi.org/p/torchzero # Replace <package-name> with your PyPI project name
44+
permissions:
45+
id-token: write # IMPORTANT: mandatory for trusted publishing
46+
47+
steps:
48+
- name: Download all the dists
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
- name: Publish distribution 📦 to PyPI
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
56+
github-release:
57+
name: >-
58+
Sign the Python 🐍 distribution 📦 with Sigstore
59+
and upload them to GitHub Release
60+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
61+
needs:
62+
- publish-to-pypi
63+
runs-on: ubuntu-latest
64+
65+
permissions:
66+
contents: write # IMPORTANT: mandatory for making GitHub Releases
67+
id-token: write # IMPORTANT: mandatory for sigstore
68+
69+
steps:
70+
- name: Download all the dists
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: python-package-distributions
74+
path: dist/
75+
- name: Sign the dists with Sigstore
76+
uses: sigstore/gh-action-sigstore-python@v3.0.0
77+
with:
78+
inputs: >-
79+
./dist/*.tar.gz
80+
./dist/*.whl
81+
- name: Create GitHub Release
82+
env:
83+
GITHUB_TOKEN: ${{ github.token }}
84+
run: >-
85+
gh release create
86+
"$GITHUB_REF_NAME"
87+
--repo "$GITHUB_REPOSITORY"
88+
--notes ""
89+
- name: Upload artifact signatures to GitHub Release
90+
env:
91+
GITHUB_TOKEN: ${{ github.token }}
92+
# Upload to GitHub Release using the `gh` CLI.
93+
# `dist/` contains the built packages, and the
94+
# sigstore-produced signatures and certificates.
95+
run: >-
96+
gh release upload
97+
"$GITHUB_REF_NAME" dist/**
98+
--repo "$GITHUB_REPOSITORY"
99+
100+
publish-to-testpypi:
101+
name: Publish Python 🐍 distribution 📦 to TestPyPI
102+
needs:
103+
- build
104+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
105+
runs-on: ubuntu-latest
106+
107+
environment:
108+
name: testpypi
109+
url: https://test.pypi.org/p/torchzero
110+
111+
permissions:
112+
id-token: write # IMPORTANT: mandatory for trusted publishing
113+
114+
steps:
115+
- name: Download all the dists
116+
uses: actions/download-artifact@v4
117+
with:
118+
name: python-package-distributions
119+
path: dist/
120+
- name: Publish distribution 📦 to TestPyPI
121+
uses: pypa/gh-action-pypi-publish@release/v1
122+
with:
123+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)