Skip to content

Commit 41fad0b

Browse files
committed
ops: add release workflow
1 parent f8b774b commit 41fad0b

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Release to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
test_pypi_only:
9+
description: 'Publish to TestPyPI only'
10+
required: false
11+
type: boolean
12+
default: false
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
build:
19+
name: Build distribution
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.11'
28+
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v5
31+
32+
- name: Build package
33+
run: uv build
34+
35+
- name: Store the distribution packages
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: python-package-distributions
39+
path: dist/
40+
41+
publish-to-testpypi:
42+
name: Publish to TestPyPI
43+
if: github.event_name == 'workflow_dispatch' && inputs.test_pypi_only
44+
needs:
45+
- build
46+
runs-on: ubuntu-latest
47+
environment:
48+
name: testpypi
49+
url: https://test.pypi.org/p/cocoindex-code
50+
permissions:
51+
id-token: write
52+
steps:
53+
- name: Download all the dists
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: python-package-distributions
57+
path: dist/
58+
59+
- name: Publish distribution to TestPyPI
60+
uses: pypa/gh-action-pypi-publish@release/v1
61+
with:
62+
repository-url: https://test.pypi.org/legacy/
63+
64+
publish-to-pypi:
65+
name: Publish to PyPI
66+
if: github.event_name == 'release'
67+
needs:
68+
- build
69+
runs-on: ubuntu-latest
70+
environment:
71+
name: pypi
72+
url: https://pypi.org/p/cocoindex-code
73+
permissions:
74+
id-token: write
75+
steps:
76+
- name: Download all the dists
77+
uses: actions/download-artifact@v4
78+
with:
79+
name: python-package-distributions
80+
path: dist/
81+
82+
- name: Publish distribution to PyPI
83+
uses: pypa/gh-action-pypi-publish@release/v1
84+
85+
github-release:
86+
name: Sign distribution and upload to GitHub Release
87+
needs:
88+
- publish-to-pypi
89+
runs-on: ubuntu-latest
90+
permissions:
91+
contents: write
92+
id-token: write
93+
steps:
94+
- name: Download all the dists
95+
uses: actions/download-artifact@v4
96+
with:
97+
name: python-package-distributions
98+
path: dist/
99+
100+
- name: Sign the dists with Sigstore
101+
uses: sigstore/gh-action-sigstore-python@v3.0.0
102+
with:
103+
inputs: >-
104+
./dist/*.tar.gz
105+
./dist/*.whl
106+
107+
- name: Upload artifact signatures to GitHub Release
108+
env:
109+
GITHUB_TOKEN: ${{ github.token }}
110+
run: >-
111+
gh release upload
112+
'${{ github.ref_name }}' dist/**
113+
--repo '${{ github.repository }}'

0 commit comments

Comments
 (0)