name: Release
on:
# 正式发布:推送语义化版本 tag(例如 v1.4.4)
push:
tags:
- "v*.*.*"
# 手动触发:默认只构建并上传产物(不发布/不创建 Release)
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: Build (sdist + wheel)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: 安装 uv(带缓存)
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: |
uv.lock
pyproject.toml
- name: 同步依赖(含 dev 组,严格使用 uv.lock)
run: uv sync --all-groups --frozen
# 发布前的质量门禁(与 test.yml 对齐)
- name: Ruff(Lint)
run: uv run ruff check .
- name: Ruff(Format Check)
run: uv run ruff format --check .
- name: Ty(Type Check)
run: uv run ty check .
- name: Pytest
run: uv run pytest -q
- name: 构建(uv build)
run: uv build --sdist --wheel --out-dir dist --clear
- name: 校验产物(twine check)
run: uv tool run twine check dist/*
- name: 设置 Node.js(用于构建 VSCode 插件 VSIX)
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: 安装 Node 依赖(npm workspaces)
run: npm ci
- name: 构建 VSCode 插件 VSIX
run: npm run vscode:package
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
if-no-files-found: error
retention-days: 7
- name: 上传 VSCode 插件产物(VSIX)
uses: actions/upload-artifact@v4
with:
name: vsix
path: packages/vscode/*.vsix
if-no-files-found: error
retention-days: 7
publish:
name: Publish to PyPI (Trusted Publisher)
runs-on: ubuntu-latest
needs: build
timeout-minutes: 10
# 仅在 tag push 时发布;workflow_dispatch 默认不发布,避免误操作
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
id-token: write
environment:
name: pypi
url: https://pypi.org/project/ai-intervention-agent/
steps:
- name: 下载构建产物
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: 发布到 PyPI
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: publish
timeout-minutes: 10
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: 下载构建产物
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: 下载 VSCode 插件产物(VSIX)
uses: actions/download-artifact@v4
with:
name: vsix
path: vsix/
- name: 创建 GitHub Release(附带产物)
uses: softprops/action-gh-release@v2
with:
files: |
dist/*
vsix/*.vsix
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
open-vsx:
name: Publish VSCode Extension to Open VSX
runs-on: ubuntu-latest
needs: build
timeout-minutes: 10
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: 下载 VSCode 插件产物(VSIX)
uses: actions/download-artifact@v4
with:
name: vsix
path: vsix/
- name: 设置 Node.js(用于发布 Open VSX)
uses: actions/setup-node@v4
with:
node-version: "20"
- name: 发布到 Open VSX(从 VSIX 发布)
env:
OVSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
run: |
# 最佳实践:namespace(publisher)在 open-vsx.org 手动创建一次;
# CI 仅负责校验权限并发布 VSIX。
npx --yes ovsx verify-pat xiadengma -p "$OVSX_TOKEN"
npx --yes ovsx publish -p "$OVSX_TOKEN" vsix/*.vsix