Skip to content

测试 CI/CD

测试 CI/CD #4

name: 推送 🐍 分发 📦 到 PyPI 或 TestPyPI
on:
push:
branches: [ main , dev ]
jobs:
# 定义工作流程,这里主要是构建
build:
name: 构建分发 📦
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# https://github.com/marketplace/actions/setup-python
- name: 设置 Python 版本
uses: actions/setup-python@v5
with:
# 使用 python 版本
python-version: "3.12.4"
# 安装 build
- name: 安装 pypa/build
run: >-
python3 -m
pip install
build
--user
# 构建
- name: 构建分发包
run: python3 -m build
# 上传
- name: 上传分发包
uses: actions/upload-artifact@v3
with:
# 上传工件,记住这个名字,后面流程会用到
name: python-package-distributions
path: dist/
publish-to-pypi:
name: >-
推送 🐍 分发 📦 到 PyPI
# man 分支有效
if: github.ref == 'refs/heads/main'
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/tools_mrcode
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: 下载 dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: 推送 📦 到 PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# 发布到 testpypi
publish-to-testpypi:
name: 推送 🐍 分发 📦 到 TestPyPI
# dev 分支有效
if: github.ref == 'refs/heads/dev'
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
# 这里是你 pypi 项目的地址
url: https://test.pypi.org/p/tools_mrcode
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
# 下载打好的包
- name: 下载 dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
# 上传到 pypa
- name: 推送 📦 到 TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/