41 lines
1.0 KiB
YAML
41 lines
1.0 KiB
YAML
name: Publish to PyPI
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*" # 匹配所有以 v 开头的 tag,如 v1.0.0, v0.1.0
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
id-token: write # 用于 trusted publishing (OIDC)
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Install build dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install build hatchling
|
|
|
|
- name: Build distribution packages
|
|
run: |
|
|
python -m build
|
|
|
|
- name: Publish to PyPI
|
|
uses: pypa/gh-action-pypi-publish@release/v1
|
|
with:
|
|
# 使用 trusted publishing (推荐方式,无需 token)
|
|
# 需要在 PyPI 上配置 trusted publishing
|
|
# 参考: https://docs.pypi.org/trusted-publishers/
|
|
print-hash: true # 显示上传文件的哈希值,便于验证
|
|
|