-
Notifications
You must be signed in to change notification settings - Fork 1
70 lines (59 loc) · 1.77 KB
/
publish.yml
File metadata and controls
70 lines (59 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Publish to PyPI
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
jobs:
build-and-publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write # 需要写权限来创建 Release
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Build package
run: |
uv run python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Generate release notes
id: release_notes
run: |
# 读取 CHANGELOG.md 中当前版本的内容
VERSION=${{ steps.get_version.outputs.VERSION }}
if [ -f CHANGELOG.md ]; then
# 提取当前版本的变更日志
awk "/## \[${VERSION}\]/,/## \[/" CHANGELOG.md | sed '$d' > release_notes.md
if [ ! -s release_notes.md ]; then
echo "Release v${VERSION}" > release_notes.md
fi
else
echo "Release v${VERSION}" > release_notes.md
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release v${{ steps.get_version.outputs.VERSION }}
body_path: release_notes.md
files: |
dist/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}