From 2a537fa9941486037433f721d147f24b52d84a09 Mon Sep 17 00:00:00 2001 From: ComfyUI Wiki Date: Sat, 7 Feb 2026 19:56:44 +0800 Subject: [PATCH] Update GitHub Actions workflow to enhance version extraction, tagging, and conditional publishing to PyPI --- .github/workflows/publish.yml | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eea63f18..5fc6cdf7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,26 +21,50 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.x" + python-version: "3.11" + + - name: Extract version from pyproject.toml + id: get_version + run: | + VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "Detected version: $VERSION" + + - name: Check if tag exists + id: check_tag + run: | + if git rev-parse "v${{ steps.get_version.outputs.VERSION }}" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag v${{ steps.get_version.outputs.VERSION }} already exists" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Tag v${{ steps.get_version.outputs.VERSION }} does not exist" + fi - name: Install build dependencies + if: steps.check_tag.outputs.exists == 'false' run: python -m pip install build - name: Build package + if: steps.check_tag.outputs.exists == 'false' run: python -m build - name: Publish to PyPI + if: steps.check_tag.outputs.exists == 'false' uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_TOKEN }} - - name: Extract version from pyproject.toml - id: get_version + - name: Create Git Tag + if: steps.check_tag.outputs.exists == 'false' run: | - VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") - echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "v${{ steps.get_version.outputs.VERSION }}" -m "Release v${{ steps.get_version.outputs.VERSION }}" + git push origin "v${{ steps.get_version.outputs.VERSION }}" - name: Create GitHub Release + if: steps.check_tag.outputs.exists == 'false' env: GH_TOKEN: ${{ github.token }} run: |