Skip to content

Commit 5f4bbdc

Browse files
committed
ci: publish only via manual workflow_dispatch
1 parent a17bcf2 commit 5f4bbdc

1 file changed

Lines changed: 53 additions & 51 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1+
# .github/workflows/publish.yml
12
name: Python Package Publish
23

34
on:
4-
workflow_run:
5-
workflows: ["Python Test"]
6-
types:
7-
- completed
8-
branches:
9-
- main
10-
5+
# 手动触发发布工作流
116
workflow_dispatch:
127
inputs:
138
destination:
@@ -19,79 +14,86 @@ on:
1914
- testpypi
2015
- pypi
2116

22-
permissions:
23-
contents: write
24-
packages: write
25-
2617
jobs:
18+
# 检查测试工作流是否成功完成
2719
check-tests:
2820
runs-on: ubuntu-latest
29-
if: >-
21+
permissions:
22+
contents: read
23+
if: >
3024
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
3125
github.event_name == 'workflow_dispatch'
3226
steps:
3327
- name: Success check
3428
run: echo "前置测试通过,可以继续执行发布流程"
3529

30+
# 发布到TestPyPI
3631
publish-testpypi:
3732
name: Publish to TestPyPI
3833
needs: check-tests
39-
if: >-
34+
if: >
4035
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
4136
(github.event_name == 'workflow_dispatch' && github.event.inputs.destination == 'testpypi')
4237
runs-on: ubuntu-latest
43-
environment: publish-testpypi
38+
environment: publish-testpypi # 使用需要审批的环境
4439
permissions:
40+
# Required for trusted publishing
4541
id-token: write
42+
contents: read
4643

4744
steps:
48-
- name: Check out the repository
49-
uses: actions/checkout@v6
50-
51-
- name: Set up Python
52-
uses: actions/setup-python@v6
53-
with:
54-
python-version: "3.13"
55-
56-
- name: Install dependencies
57-
run: |
58-
python -m pip install --upgrade pip
59-
pip install build twine
60-
61-
- name: Build package
62-
run: python -m build
63-
64-
- name: Publish to TestPyPI
65-
uses: pypa/gh-action-pypi-publish@release/v1
66-
with:
67-
repository-url: https://test.pypi.org/legacy/
68-
skip-existing: true
69-
45+
- name: Check out the repository
46+
uses: actions/checkout@v6
47+
48+
- name: Set up Python
49+
uses: actions/setup-python@v6
50+
with:
51+
python-version: "3.13"
52+
53+
- name: Install dependencies
54+
run: |
55+
python -m pip install --upgrade pip
56+
pip install build twine
57+
58+
- name: Build package
59+
run: python -m build
60+
61+
- name: Publish to TestPyPI
62+
uses: pypa/gh-action-pypi-publish@release/v1
63+
with:
64+
repository-url: https://test.pypi.org/legacy/
65+
skip-existing: true
66+
# Note: removed user and password fields to use Trusted Publishers
67+
68+
# 发布到PyPI
7069
publish-pypi:
7170
name: Publish to PyPI
7271
needs: check-tests
7372
if: github.event_name == 'workflow_dispatch' && github.event.inputs.destination == 'pypi'
7473
runs-on: ubuntu-latest
75-
environment: publish-pypi
74+
environment: publish-pypi # 使用需要严格审批的环境
7675
permissions:
76+
# Required for trusted publishing
7777
id-token: write
78+
contents: read
7879

7980
steps:
80-
- name: Check out the repository
81-
uses: actions/checkout@v6
81+
- name: Check out the repository
82+
uses: actions/checkout@v6
8283

83-
- name: Set up Python
84-
uses: actions/setup-python@v6
85-
with:
86-
python-version: "3.13"
84+
- name: Set up Python
85+
uses: actions/setup-python@v6
86+
with:
87+
python-version: "3.13"
8788

88-
- name: Install dependencies
89-
run: |
90-
python -m pip install --upgrade pip
91-
pip install build twine
89+
- name: Install dependencies
90+
run: |
91+
python -m pip install --upgrade pip
92+
pip install build twine
9293
93-
- name: Build package
94-
run: python -m build
94+
- name: Build package
95+
run: python -m build
9596

96-
- name: Publish to PyPI
97-
uses: pypa/gh-action-pypi-publish@release/v1
97+
- name: Publish to PyPI
98+
uses: pypa/gh-action-pypi-publish@release/v1
99+
# Note: removed user and password fields to use Trusted Publishers

0 commit comments

Comments
 (0)