Skip to content

Commit 7c2c56e

Browse files
committed
action to upload to pypi
1 parent ad1f38a commit 7c2c56e

File tree

1 file changed

+69
-46
lines changed

1 file changed

+69
-46
lines changed

.github/workflows/publish.yml

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,92 @@
1-
name: Build and Publish
1+
name: Publish to PyPI
22

33
on:
44
release:
55
types: [published]
6-
workflow_dispatch:
6+
workflow_dispatch:
7+
8+
permissions:
9+
id-token: write
710

811
jobs:
9-
build:
12+
build-wheels:
1013
name: Build wheels on ${{ matrix.os }}
1114
runs-on: ${{ matrix.os }}
1215
strategy:
1316
matrix:
1417
os: [ubuntu-latest, windows-latest, macos-latest]
1518

1619
steps:
17-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.10'
26+
27+
- name: Install Rust
28+
uses: dtolnay/rust-toolchain@stable
1829

19-
- name: Set up Python
20-
uses: actions/setup-python@v4
21-
with:
22-
python-version: '3.11'
30+
- name: Install maturin
31+
run: pip install maturin
2332

24-
- name: Set up Rust
25-
uses: actions-rs/toolchain@v1
26-
with:
27-
toolchain: stable
28-
override: true
33+
- name: Build wheels
34+
run: maturin build --release --out dist --find-interpreter
2935

30-
- name: Install maturin
31-
run: pip install maturin
36+
- name: Upload wheels
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: wheels-${{ matrix.os }}
40+
path: dist
41+
42+
build-sdist:
43+
name: Build source distribution
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
3247

33-
- name: Build wheels
34-
run: maturin build --release --out dist
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: '3.10'
3552

36-
- name: Upload wheels
37-
uses: actions/upload-artifact@v4
38-
with:
39-
name: wheels-${{ matrix.os }}
40-
path: dist/
53+
- name: Install Rust
54+
uses: dtolnay/rust-toolchain@stable
55+
56+
- name: Install maturin
57+
run: pip install maturin
58+
59+
- name: Build sdist
60+
run: maturin sdist --out dist
61+
62+
- name: Upload sdist
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: sdist
66+
path: dist
4167

4268
publish:
4369
name: Publish to PyPI
44-
needs: build
70+
needs: [build-wheels, build-sdist]
4571
runs-on: ubuntu-latest
46-
if: github.event_name == 'release' && github.event.action == 'published'
47-
72+
environment:
73+
name: pypi
74+
url: https://pypi.org/p/externkit
75+
permissions:
76+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
77+
4878
steps:
49-
- name: Download all wheels
50-
uses: actions/download-artifact@v4
51-
with:
52-
path: dist/
53-
pattern: wheels-*
54-
merge-multiple: true
55-
56-
- name: Flatten wheels directory
57-
run: |
58-
mkdir -p wheels
59-
find dist/ -name "*.whl" -exec cp {} wheels/ \;
60-
find dist/ -name "*.tar.gz" -exec cp {} wheels/ \;
61-
ls -la wheels/
62-
63-
- name: Publish to PyPI
64-
uses: PyO3/maturin-action@v1
65-
with:
66-
command: upload
67-
args: --skip-existing wheels/*
68-
env:
69-
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
79+
- name: Download all artifacts
80+
uses: actions/download-artifact@v4
81+
with:
82+
pattern: '*'
83+
path: dist
84+
merge-multiple: true
85+
86+
- name: Publish to PyPI
87+
uses: pypa/gh-action-pypi-publish@release/v1
88+
with:
89+
# Using trusted publishing - no API token needed!
90+
# Make sure you've configured trusted publishing on PyPI:
91+
# https://docs.pypi.org/trusted-publishers/
92+
verbose: true

0 commit comments

Comments
 (0)