Skip to content

Commit a320065

Browse files
authored
Add GitHub action to release code on PyPI
1 parent c79bd09 commit a320065

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
build:
20+
name: Build distribution
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.x"
29+
- name: Install pypa/build
30+
run: python3 -m pip install build--user
31+
- name: Build a binary wheel and a source tarball
32+
run: python3 -m build
33+
- name: Store the distribution packages
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: python-package-distributions
37+
path: dist/
38+
39+
publish-to-pypi:
40+
name: Publish Python distribution to PyPI
41+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
42+
needs:
43+
- build
44+
runs-on: ubuntu-latest
45+
environment: release
46+
permissions:
47+
id-token: write # IMPORTANT: mandatory for trusted publishing
48+
steps:
49+
- name: Download the dist file
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: python-package-distributions
53+
path: dist/
54+
- name: Publish distribution to PyPI
55+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)