可用于在华为云流水线中发布 Python 包到官方 PyPI 仓库,支持官方及TestPyPI仓库,提供令牌和用户名密码认证,自动构建包,支持跳过已存在版本和详细输出模式。【此简介由AI生成】
| Files | Last commit | Last update |
|---|---|---|
| 6 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 4 months ago | ||
| 6 months ago | ||
| 6 months ago | ||
| 6 months ago | ||
| 4 months ago | ||
| 5 months ago | ||
| 6 months ago | ||
| 6 months ago | ||
| 6 months ago | ||
| 6 months ago |
PyPI-DevTools_pypi-publish 使用示例
这是一个用于 gitcode CI/CD 流水线的 PyPI 发布插件,专门用于发布 Python 包到官方 PyPI 仓库。
功能特性
- 支持发布到官方 PyPI 仓库(upload.pypi.org)和 TestPyPI(test.pypi.org)
- 支持 PyPI 访问令牌认证(推荐使用
__token__用户名) - 支持用户名/密码认证
- 自动构建 Python 包(使用
python -m build) - 支持跳过已存在版本的发布
- 支持详细输出模式(verbose)
gitcode CI/CD 流水线配置示例
方式1:通过输入参数传递 PyPI 令牌
- name: pypi-publish
uses: pypi-publish
with:
package-path: './my-python-package'
pypi-token: xxx
test-pypi: 'false'
skip-existing: 'false'
verbose: 'true'
方式2:通过环境变量传递 PyPI 令牌
- name: pypi-publish
uses: pypi-publish
with:
package-path: './my-python-package'
test-pypi: 'false'
env:
token: '${{ secrets.PYPI_TOKEN }}'
方式3:使用用户名和密码认证
- name: pypi-publish
uses: pypi-publish
with:
package-path: './my-python-package'
pypi-username: 'my_username'
pypi-password: '${{ secrets.PYPI_PASSWORD }}'
test-pypi: 'false'
方式4:发布到 TestPyPI(测试仓库)
- name: pypi-publish
uses: pypi-publish
with:
package-path: './my-python-package'
pypi-token: '${{ secrets.TEST_PYPI_TOKEN }}'
test-pypi: 'true'
skip-existing: 'true'
参数说明
输入参数
| 参数名 | 描述 | 必需 | 默认值 |
|---|---|---|---|
package-path |
要发布的 Python 包路径 | 否 | .(当前目录) |
pypi-token |
PyPI 访问令牌 | 否(可通过环境变量提供) | '' |
pypi-username |
PyPI 用户名 | 否(令牌认证时不需要) | '' |
pypi-password |
PyPI 密码 | 否(令牌认证时不需要) | '' |
test-pypi |
是否发布到 TestPyPI | 否 | false |
skip-existing |
跳过已存在的版本 | 否 | false |
verbose |
详细输出模式 | 否 | false |
环境变量
| 环境变量名 | 描述 | 对应输入参数 |
|---|---|---|
token |
PyPI 访问令牌 | pypi-token |
username |
PyPI 用户名 | pypi-username |
password |
PyPI 密码 | pypi-password |
repositoryUrl |
PyPI 仓库地址 | pypi-repository |
输出参数
| 输出参数名 | 描述 |
|---|---|
success |
发布是否成功 |
package-name |
发布的包名 |
version |
发布的版本 |
registry |
使用的 registry |
完整流水线示例
on:
sources: {}
concurrency:
max: 5
enable: false
preemption:
enable: false
events:
- mr_id
exceed-action: IGNORE
stages:
17761517793640addca29-d0b4-4617-a737-a098a42243fd:
jobs:
JOB_eAdsD:
name: pypi-publish-job
select: selected_by_default
needs: []
steps:
- name: official_checkout
uses: official_checkout
with:
repository: xxx
ref: master
path: ''
token: xxx
fetch-depth: 1
submodules: 'false'
lfs: 'false'
clean: 'true'
- name: pypi-publish
uses: pypi-publish
with:
package-path: './my-python-package'
test-pypi: 'false'
skip-existing: 'false'
verbose: 'true'
env:
token: '${{ secrets.PYPI_TOKEN }}'
if: '${{ default() }}'
runs-on:
- default
pre:
- type: auto
name: 发布阶段
select: selected_by_default
fail_fast: false
注意事项
-
PyPI 访问令牌:你需要一个有效的 PyPI 访问令牌。可以在 PyPI 官网生成:
- 登录 pypi.org
- 点击头像 → Account Settings → API tokens
- 生成新的令牌(建议选择 "Upload" 权限)
-
认证方式:
- 令牌认证:使用
pypi-token参数,用户名自动设置为__token__ - 用户名/密码认证:使用
pypi-username和pypi-password参数
- 令牌认证:使用
-
TestPyPI:
- 设置
test-pypi: 'true'发布到测试仓库 test.pypi.org - 用于发布前验证
- 设置
-
跳过已存在版本:
- 设置
skip-existing: 'true'当版本已存在时不报错 - 适用于重复构建场景
- 设置
-
详细输出模式:
- 设置为
true时,输出详细的调试信息 - 用于排查问题
- 设置为
Introduction
可用于在华为云流水线中发布 Python 包到官方 PyPI 仓库,支持官方及TestPyPI仓库,提供令牌和用户名密码认证,自动构建包,支持跳过已存在版本和详细输出模式。【此简介由AI生成】
Customize your domain