|
| 1 | +name: Auto PR to ComfyUI on Version Bump |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "pyproject.toml" |
| 8 | + |
| 9 | +jobs: |
| 10 | + create-pr: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout embedded-docs repo |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 # Get full history for changelog generation |
| 18 | + |
| 19 | + - name: Get current version |
| 20 | + id: current_version |
| 21 | + run: | |
| 22 | + VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') |
| 23 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 24 | + echo "Current version: $VERSION" |
| 25 | + |
| 26 | + - name: Get previous version |
| 27 | + id: previous_version |
| 28 | + run: | |
| 29 | + # Get the previous version tag |
| 30 | + PREV_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) |
| 31 | + if [ -z "$PREV_TAG" ]; then |
| 32 | + echo "version=0.0.0" >> $GITHUB_OUTPUT |
| 33 | + echo "No previous version tag found, using 0.0.0" |
| 34 | + else |
| 35 | + PREV_VERSION=${PREV_TAG#v} |
| 36 | + echo "version=$PREV_VERSION" >> $GITHUB_OUTPUT |
| 37 | + echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT |
| 38 | + echo "Previous version: $PREV_VERSION (tag: $PREV_TAG)" |
| 39 | + fi |
| 40 | + |
| 41 | + - name: Check if version changed |
| 42 | + id: version_check |
| 43 | + run: | |
| 44 | + CURRENT="${{ steps.current_version.outputs.version }}" |
| 45 | + PREVIOUS="${{ steps.previous_version.outputs.version }}" |
| 46 | + |
| 47 | + if [ "$CURRENT" != "$PREVIOUS" ]; then |
| 48 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 49 | + echo "✅ Version bumped from $PREVIOUS to $CURRENT" |
| 50 | + else |
| 51 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 52 | + echo "ℹ️ No version change detected" |
| 53 | + fi |
| 54 | + |
| 55 | + - name: Generate changelog |
| 56 | + id: changelog |
| 57 | + if: steps.version_check.outputs.changed == 'true' |
| 58 | + run: | |
| 59 | + PREV_TAG="${{ steps.previous_version.outputs.tag }}" |
| 60 | + CURRENT_VERSION="${{ steps.current_version.outputs.version }}" |
| 61 | + |
| 62 | + # Create changelog file |
| 63 | + CHANGELOG_FILE="pr_changelog.md" |
| 64 | + |
| 65 | + echo "## Update embedded docs to v${CURRENT_VERSION}" > $CHANGELOG_FILE |
| 66 | + echo "" >> $CHANGELOG_FILE |
| 67 | + echo "### 📦 Package Information" >> $CHANGELOG_FILE |
| 68 | + echo "- **PyPI**: https://pypi.org/project/comfyui-embedded-docs/${CURRENT_VERSION}/" >> $CHANGELOG_FILE |
| 69 | + echo "- **Release**: https://github.com/Comfy-Org/embedded-docs/releases/tag/v${CURRENT_VERSION}" >> $CHANGELOG_FILE |
| 70 | + echo "" >> $CHANGELOG_FILE |
| 71 | + |
| 72 | + if [ -n "$PREV_TAG" ]; then |
| 73 | + echo "### 📝 Changes since ${PREV_TAG}" >> $CHANGELOG_FILE |
| 74 | + echo "" >> $CHANGELOG_FILE |
| 75 | + |
| 76 | + # Get merged PRs |
| 77 | + echo "#### Merged Pull Requests" >> $CHANGELOG_FILE |
| 78 | + git log ${PREV_TAG}..HEAD --merges --pretty=format:"- %s (%h)" | grep -i "Merge pull request" | sed 's/Merge pull request/PR/' >> $CHANGELOG_FILE || echo "- No merged PRs found" >> $CHANGELOG_FILE |
| 79 | + echo "" >> $CHANGELOG_FILE |
| 80 | + |
| 81 | + # Get commits (excluding merge commits) |
| 82 | + echo "#### Commits" >> $CHANGELOG_FILE |
| 83 | + git log ${PREV_TAG}..HEAD --no-merges --pretty=format:"- %s (%h)" >> $CHANGELOG_FILE |
| 84 | + echo "" >> $CHANGELOG_FILE |
| 85 | + else |
| 86 | + echo "### 📝 Initial Release" >> $CHANGELOG_FILE |
| 87 | + echo "" >> $CHANGELOG_FILE |
| 88 | + echo "This is the initial automated sync of the embedded-docs package." >> $CHANGELOG_FILE |
| 89 | + echo "" >> $CHANGELOG_FILE |
| 90 | + fi |
| 91 | + |
| 92 | + echo "" >> $CHANGELOG_FILE |
| 93 | + echo "---" >> $CHANGELOG_FILE |
| 94 | + echo "*This is an automated draft PR created by the embedded-docs sync workflow.*" >> $CHANGELOG_FILE |
| 95 | + |
| 96 | + echo "changelog_file=$CHANGELOG_FILE" >> $GITHUB_OUTPUT |
| 97 | + |
| 98 | + echo "📄 Generated changelog:" |
| 99 | + cat $CHANGELOG_FILE |
| 100 | + |
| 101 | + - name: Checkout ComfyUI fork |
| 102 | + if: steps.version_check.outputs.changed == 'true' |
| 103 | + uses: actions/checkout@v4 |
| 104 | + with: |
| 105 | + repository: 'comfyui-wiki/ComfyUI' |
| 106 | + token: ${{ secrets.COMFYUI_FORK_TOKEN }} |
| 107 | + path: comfyui-fork |
| 108 | + fetch-depth: 1 |
| 109 | + |
| 110 | + - name: Create branch and update requirements.txt |
| 111 | + if: steps.version_check.outputs.changed == 'true' |
| 112 | + working-directory: comfyui-fork |
| 113 | + run: | |
| 114 | + # Configure git |
| 115 | + git config user.name "github-actions[bot]" |
| 116 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 117 | + |
| 118 | + # Create branch with version and timestamp |
| 119 | + TIMESTAMP=$(date +%Y%m%d-%H%M%S) |
| 120 | + VERSION="${{ steps.current_version.outputs.version }}" |
| 121 | + BRANCH_NAME="update-docs-${VERSION}-${TIMESTAMP}" |
| 122 | + |
| 123 | + git checkout -b $BRANCH_NAME |
| 124 | + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV |
| 125 | + echo "🌿 Created branch: $BRANCH_NAME" |
| 126 | + |
| 127 | + # Update requirements.txt |
| 128 | + if [ -f requirements.txt ]; then |
| 129 | + sed -i "s/comfyui-embedded-docs==.*/comfyui-embedded-docs==${VERSION}/" requirements.txt |
| 130 | + echo "✅ Updated requirements.txt to version ${VERSION}" |
| 131 | + git add requirements.txt |
| 132 | + git commit -m "chore: update embedded-docs to v${VERSION}" |
| 133 | + else |
| 134 | + echo "⚠️ Warning: requirements.txt not found!" |
| 135 | + exit 1 |
| 136 | + fi |
| 137 | + |
| 138 | + - name: Push to fork |
| 139 | + if: steps.version_check.outputs.changed == 'true' |
| 140 | + working-directory: comfyui-fork |
| 141 | + run: | |
| 142 | + git push origin ${{ env.BRANCH_NAME }} |
| 143 | + echo "✅ Pushed branch ${{ env.BRANCH_NAME }} to fork" |
| 144 | + |
| 145 | + - name: Create draft PR |
| 146 | + if: steps.version_check.outputs.changed == 'true' |
| 147 | + env: |
| 148 | + GH_TOKEN: ${{ secrets.COMFYUI_FORK_TOKEN }} |
| 149 | + run: | |
| 150 | + VERSION="${{ steps.current_version.outputs.version }}" |
| 151 | + CHANGELOG_FILE="${{ steps.changelog.outputs.changelog_file }}" |
| 152 | + |
| 153 | + # Create PR from fork to upstream |
| 154 | + PR_URL=$(gh pr create \ |
| 155 | + --repo comfyanonymous/ComfyUI \ |
| 156 | + --base master \ |
| 157 | + --head comfyui-wiki:${{ env.BRANCH_NAME }} \ |
| 158 | + --title "Update docs to v${VERSION}" \ |
| 159 | + --body-file "$CHANGELOG_FILE" \ |
| 160 | + --draft) |
| 161 | + |
| 162 | + echo "✅ Draft PR created: $PR_URL" |
| 163 | + echo "PR_URL=$PR_URL" >> $GITHUB_ENV |
| 164 | + |
| 165 | + - name: Send notification |
| 166 | + if: steps.version_check.outputs.changed == 'true' |
| 167 | + run: | |
| 168 | + VERSION="${{ steps.current_version.outputs.version }}" |
| 169 | + echo "🎉 Successfully created draft PR for version ${VERSION}" |
| 170 | + echo "📝 PR URL: ${{ env.PR_URL }}" |
| 171 | + echo "" |
| 172 | + echo "👉 You will receive a GitHub notification for the draft PR" |
| 173 | + echo "📧 Check your GitHub notifications at: https://github.com/notifications" |
| 174 | +
|
0 commit comments