From 36eb4fdabc756c1d619c71115ed108025cc0c72f Mon Sep 17 00:00:00 2001 From: Cassian Florin Date: Mon, 29 Jun 2026 13:53:29 +0800 Subject: [PATCH] =?UTF-8?q?ci(database-cli):=20=E4=B8=BB=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=8E=E8=87=AA=E5=8A=A8=E6=8C=89=E8=AF=AD?= =?UTF-8?q?=E4=B9=89=E5=8C=96=E7=89=88=E6=9C=AC=E5=8F=91=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增两个 GitHub Actions 工作流: - release.yml:push 到 main 时先跑测试,再按 Conventional Commits 自动计算版本、打 vX.Y.Z tag 并发布 GitHub Release。 - ci.yml:PR 与非 main 分支 push 时运行测试(Python 3.10/3.12)。 Co-Authored-By: Claude Opus 4.8 --- .github/workflows/ci.yml | 31 ++++++++++++++++++ .github/workflows/release.yml | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1380720 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: + pull_request: + push: + branches-ignore: + - main + +# 同一分支/PR 只保留最新一次运行 +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Test (Python ${{ matrix.python-version }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.12"] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Run tests + run: python -m unittest discover -s tests -p "test_*.py" -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..33d14c2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +name: Release + +# 主分支每次更新后:跑测试 -> 按 Conventional Commits 计算版本 -> 打 tag + 发布 Release +on: + push: + branches: + - main + +# 串行执行,避免多次 push 并发打出冲突的 tag +concurrency: + group: release + cancel-in-progress: false + +permissions: + contents: write + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Run tests + run: python -m unittest discover -s tests -p "test_*.py" -v + + release: + name: Tag & Release + needs: test + runs-on: ubuntu-latest + # 跳过机器人/合并产生的空提交场景可在此扩展条件 + steps: + - uses: actions/checkout@v4 + with: + # 计算版本需要完整历史与已有 tag + fetch-depth: 0 + + - name: Determine next version + id: tag + uses: mathieudutour/github-tag-action@v6.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # 沿用现有 vX.Y.Z 命名 + tag_prefix: v + # 非 feat/fix 提交(如 docs/chore)默认按 patch 递增, + # 保证主分支每次更新都会产出新版本;如只想在 feat/fix 时发版, + # 改为 default_bump: false + default_bump: patch + release_branches: main + + - name: Create GitHub Release + if: steps.tag.outputs.new_tag != '' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.tag.outputs.new_tag }} + name: ${{ steps.tag.outputs.new_tag }} + body: ${{ steps.tag.outputs.changelog }}