From 614ffaaf8ff447f3a34052df08b5f7b917a1465b Mon Sep 17 00:00:00 2001 From: worldmozara Date: Mon, 20 Jul 2026 04:44:57 +0800 Subject: [PATCH] ci: publish only after CI check succeeds Merge release into ci.yml: tag pushes run check then publish (needs: check). Remove standalone python-publish so PyPI never ships on red CI. Retag (delete+push v*) still retriggers the pipeline. --- .github/workflows/ci.yml | 54 ++++++++++++++++++++++++---- .github/workflows/python-publish.yml | 39 -------------------- 2 files changed, 48 insertions(+), 45 deletions(-) delete mode 100755 .github/workflows/python-publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2fb15a..de6e57c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,20 @@ +# Single pipeline: CI on main/PRs; on v* tags, publish only after CI succeeds. +# Retagging the same commit (delete + push tag) re-triggers this workflow. + name: CI on: push: branches: [main] + tags: ["v*"] pull_request: branches: [main] +# Cancel superseded runs on the same ref (e.g. force-push / retag races). +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: check: runs-on: ubuntu-latest @@ -18,15 +27,14 @@ jobs: python-version: "3.14" - name: Install PDM - uses: pdm-project/setup-pdm@v4 - with: - python-version: "3.14" + run: pip install pdm - name: Install dependencies - run: pdm sync --dev + # Locked install so CI matches prek pins / pdm.lock. + run: pdm install --check -G :all - name: Ruff check - run: pdm run ruff check --output-format=github . + run: pdm run ruff check . - name: Ruff format run: pdm run ruff format --check . @@ -34,5 +42,39 @@ jobs: - name: basedpyright run: pdm run basedpyright . - - name: pytest + - name: Pytest run: pdm run pytest + + # Only on version tags, and only after check is green (no publish on red CI). + publish: + needs: check + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.14" + + - name: Install PDM + run: pip install pdm + + - name: Build package + run: pdm build + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: dist/* + generate_release_notes: true + fail_on_unmatched_files: true + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100755 index e9d459c..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Release and Publish Python Package - -on: - push: - tags: - - "v*" - -permissions: - contents: write - id-token: write - -jobs: - release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.14" - - - name: Install build - run: python -m pip install --upgrade pip build - - - name: Build package - run: python -m build --sdist --wheel --outdir dist/ . - - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 - - - name: Create GitHub release - uses: softprops/action-gh-release@v2 - with: - files: | - dist/* - generate_release_notes: true