Skip to content

Commit f3d694e

Browse files
committed
add pypi publish wf
1 parent 496c20a commit f3d694e

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# This workflow will upload a Python Package to PyPI 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: [released]
14+
workflow_dispatch:
15+
inputs:
16+
publish_test:
17+
description: 'Publish to TestPyPI'
18+
required: true
19+
type: boolean
20+
default: false
21+
publish_to_pypi:
22+
description: 'Publish to PyPI'
23+
required: true
24+
type: boolean
25+
default: false
26+
27+
28+
permissions:
29+
contents: read
30+
31+
jobs:
32+
release-build:
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- uses: actions/setup-python@v5
39+
with:
40+
python-version: "3.x"
41+
42+
- name: Build release distributions
43+
run: |
44+
# NOTE: put your own distribution build steps here.
45+
python -m pip install build
46+
python -m build
47+
48+
- name: Upload distributions
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: release-dists
52+
path: dist/
53+
54+
pypi-publish-test:
55+
runs-on: ubuntu-latest
56+
needs:
57+
- release-build
58+
if: github.event_name == 'workflow_dispatch' && inputs.publish_test == true
59+
permissions:
60+
id-token: write
61+
environment:
62+
name: testpypi
63+
url: https://test.pypi.org/project/pangbank/
64+
65+
steps:
66+
- name: Retrieve release distributions
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: release-dists
70+
path: dist/
71+
72+
- name: Publish to TestPyPI
73+
uses: pypa/gh-action-pypi-publish@release/v1
74+
with:
75+
repository-url: https://test.pypi.org/legacy/
76+
77+
pypi-publish:
78+
runs-on: ubuntu-latest
79+
needs:
80+
- release-build
81+
if: (github.event_name == 'release' && github.event.action == 'released') || (github.event_name == 'workflow_dispatch' && inputs.publish_to_pypi == true)
82+
permissions:
83+
id-token: write
84+
environment:
85+
name: pypi
86+
url: https://pypi.org/project/pangbank/
87+
88+
steps:
89+
- name: Retrieve release distributions
90+
uses: actions/download-artifact@v4
91+
with:
92+
name: release-dists
93+
path: dist/
94+
95+
- name: Publish to PyPI
96+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)