|
| 1 | +# .github/workflows/publish.yml |
1 | 2 | name: Python Package Publish |
2 | 3 |
|
3 | 4 | on: |
4 | | - workflow_run: |
5 | | - workflows: ["Python Test"] |
6 | | - types: |
7 | | - - completed |
8 | | - branches: |
9 | | - - main |
10 | | - |
| 5 | + # 手动触发发布工作流 |
11 | 6 | workflow_dispatch: |
12 | 7 | inputs: |
13 | 8 | destination: |
|
19 | 14 | - testpypi |
20 | 15 | - pypi |
21 | 16 |
|
22 | | -permissions: |
23 | | - contents: write |
24 | | - packages: write |
25 | | - |
26 | 17 | jobs: |
| 18 | + # 检查测试工作流是否成功完成 |
27 | 19 | check-tests: |
28 | 20 | runs-on: ubuntu-latest |
29 | | - if: >- |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + if: > |
30 | 24 | (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || |
31 | 25 | github.event_name == 'workflow_dispatch' |
32 | 26 | steps: |
33 | 27 | - name: Success check |
34 | 28 | run: echo "前置测试通过,可以继续执行发布流程" |
35 | 29 |
|
| 30 | + # 发布到TestPyPI |
36 | 31 | publish-testpypi: |
37 | 32 | name: Publish to TestPyPI |
38 | 33 | needs: check-tests |
39 | | - if: >- |
| 34 | + if: > |
40 | 35 | (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || |
41 | 36 | (github.event_name == 'workflow_dispatch' && github.event.inputs.destination == 'testpypi') |
42 | 37 | runs-on: ubuntu-latest |
43 | | - environment: publish-testpypi |
| 38 | + environment: publish-testpypi # 使用需要审批的环境 |
44 | 39 | permissions: |
| 40 | + # Required for trusted publishing |
45 | 41 | id-token: write |
| 42 | + contents: read |
46 | 43 |
|
47 | 44 | 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 |
70 | 69 | publish-pypi: |
71 | 70 | name: Publish to PyPI |
72 | 71 | needs: check-tests |
73 | 72 | if: github.event_name == 'workflow_dispatch' && github.event.inputs.destination == 'pypi' |
74 | 73 | runs-on: ubuntu-latest |
75 | | - environment: publish-pypi |
| 74 | + environment: publish-pypi # 使用需要严格审批的环境 |
76 | 75 | permissions: |
| 76 | + # Required for trusted publishing |
77 | 77 | id-token: write |
| 78 | + contents: read |
78 | 79 |
|
79 | 80 | steps: |
80 | | - - name: Check out the repository |
81 | | - uses: actions/checkout@v6 |
| 81 | + - name: Check out the repository |
| 82 | + uses: actions/checkout@v6 |
82 | 83 |
|
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" |
87 | 88 |
|
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 |
92 | 93 |
|
93 | | - - name: Build package |
94 | | - run: python -m build |
| 94 | + - name: Build package |
| 95 | + run: python -m build |
95 | 96 |
|
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