Skip to content

Commit ad1f1d7

Browse files
authored
ci: build and publish to PyPI (#4)
1 parent d030507 commit ad1f1d7

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build & Publish
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
release:
8+
types: [published]
9+
10+
permissions: {}
11+
12+
jobs:
13+
python-build:
14+
name: Python Build
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read # Required to checkout the repository.
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
21+
with:
22+
persist-credentials: false
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
26+
with:
27+
python-version-file: .python-version
28+
29+
- name: Install dependecies
30+
run: python -m pip install --upgrade pip build
31+
32+
- name: Generate distributions
33+
run: python -m build
34+
35+
- name: Upload artifact
36+
id: upload-artifact
37+
if: github.event_name == 'release' && github.event.action == 'published'
38+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
39+
with:
40+
name: python-package-dist
41+
path: dist
42+
43+
outputs:
44+
artifact-uploaded: ${{ steps.upload-artifact.outcome == 'success' }}
45+
46+
pypi-publish:
47+
name: PyPI Publish
48+
needs: python-build
49+
if: needs.python-build.outputs.artifact-uploaded == 'true'
50+
runs-on: ubuntu-latest
51+
environment: pypi
52+
permissions:
53+
id-token: write # Required for PyPI Trusted Publishing.
54+
steps:
55+
- name: Download artifact
56+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
57+
with:
58+
name: python-package-dist
59+
path: dist
60+
61+
- name: Publish to PyPI
62+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e

0 commit comments

Comments
 (0)