Repository navigation
99 lines (85 loc) · 2.65 KB
/
Copy pathpublish.yml
File metadata and controls
99 lines (85 loc) · 2.65 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# .github/workflows/publish.yml
name: Python Package Publish
on:
# 手动触发发布工作流
workflow_dispatch:
inputs:
destination:
description: '发布目标'
required: true
default: 'testpypi'
type: choice
options:
- testpypi
- pypi
jobs:
# 检查测试工作流是否成功完成
check-tests:
runs-on: ubuntu-latest
permissions:
contents: read
if: >
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
github.event_name == 'workflow_dispatch'
steps:
- name: Success check
run: echo "前置测试通过,可以继续执行发布流程"
# 发布到TestPyPI
publish-testpypi:
name: Publish to TestPyPI
needs: check-tests
if: >
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.destination == 'testpypi')
runs-on: ubuntu-latest
environment: publish-testpypi # 使用需要审批的环境
permissions:
# Required for trusted publishing
id-token: write
contents: read
steps:
- name: Check out the repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
# Note: removed user and password fields to use Trusted Publishers
# 发布到PyPI
publish-pypi:
name: Publish to PyPI
needs: check-tests
if: github.event_name == 'workflow_dispatch' && github.event.inputs.destination == 'pypi'
runs-on: ubuntu-latest
environment: publish-pypi # 使用需要严格审批的环境
permissions:
# Required for trusted publishing
id-token: write
contents: read
steps:
- name: Check out the repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Note: removed user and password fields to use Trusted Publishers