Skip to content

Commit dbc4ffd

Browse files
committed
chore: add publish workflow
1 parent 5e5c581 commit dbc4ffd

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

.github/workflows/publish.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
environment:
9+
description: 'Publish to'
10+
required: true
11+
default: 'testpypi'
12+
type: choice
13+
options:
14+
- testpypi
15+
- pypi
16+
17+
jobs:
18+
build:
19+
name: Build Package
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Install UV
25+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
26+
27+
- name: Add UV to PATH
28+
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
29+
30+
- name: Set up Python 3.12
31+
run: uv python install 3.12
32+
33+
- name: Install dependencies
34+
run: uv sync --all-extras
35+
36+
- name: Run tests
37+
run: uv run pytest -v
38+
39+
- name: Build package
40+
run: uv build
41+
42+
- name: Check package
43+
run: |
44+
uv run pip install twine
45+
uv run twine check dist/*
46+
47+
- name: Upload artifacts
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: dist
51+
path: dist/
52+
retention-days: 7
53+
54+
publish-testpypi:
55+
name: Publish to TestPyPI
56+
runs-on: ubuntu-latest
57+
needs: build
58+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'testpypi'
59+
environment:
60+
name: testpypi
61+
url: https://test.pypi.org/project/decart/
62+
permissions:
63+
id-token: write
64+
steps:
65+
- name: Download artifacts
66+
uses: actions/download-artifact@v4
67+
with:
68+
name: dist
69+
path: dist/
70+
71+
- name: Publish to TestPyPI
72+
uses: pypa/gh-action-pypi-publish@release/v1
73+
with:
74+
repository-url: https://test.pypi.org/legacy/
75+
76+
publish-pypi:
77+
name: Publish to PyPI
78+
runs-on: ubuntu-latest
79+
needs: build
80+
if: (github.event_name == 'release' && github.event.action == 'published') || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi')
81+
environment:
82+
name: pypi
83+
url: https://pypi.org/project/decart/
84+
permissions:
85+
id-token: write
86+
steps:
87+
- name: Download artifacts
88+
uses: actions/download-artifact@v4
89+
with:
90+
name: dist
91+
path: dist/
92+
93+
- name: Publish to PyPI
94+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)