-
Notifications
You must be signed in to change notification settings - Fork 1
75 lines (62 loc) · 1.74 KB
/
python-publish.yml
File metadata and controls
75 lines (62 loc) · 1.74 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
71
72
73
74
75
name: 构建并发布至 PyPI
on:
workflow_run:
workflows: ["预构建检查"]
types: [completed]
branches: [main]
workflow_dispatch:
# 权限最小化
permissions:
contents: read
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检出源码
uses: actions/checkout@v6
- name: 安装 Python 3.13
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: 缓存 pip
uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
- name: 安装构建工具
run: |
python -m pip install --upgrade pip build twine
- name: 构建分发包
run: python -m build --sdist --wheel
- name: 上传构建产物
uses: actions/upload-artifact@v6
with:
name: dist-${{ github.run_number }}
path: dist/
publish:
needs: build
runs-on: ubuntu-latest
if: |
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success') ||
github.event_name == 'workflow_dispatch'
steps:
- name: 下载构建产物
uses: actions/download-artifact@v6
with:
name: dist-${{ github.run_number }}
path: dist/
- name: 安装 Python & twine
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: 安装 twine
run: python -m pip install --upgrade pip twine
- name: 检查包
run: twine check dist/*
- name: 发布至 PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*