Files
dify-docs/.github/workflows/sync_docs_cleanup.yml
Chenhe Gu f5d84b7790 Fix/sync pr auto close (#560)
* fix redirect language code prefixes

* fix: don't close sync PR when original is merged

Only close sync PR when original is closed without merging.
When original is merged, leave sync PR open for independent review.
2025-11-27 07:25:53 -08:00

86 lines
3.3 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Workflow for cleaning up sync PRs when original PR is closed
name: Cleanup Sync PR
on:
pull_request:
branches: [main, revamp]
types: [closed]
permissions:
contents: read
pull-requests: write
jobs:
cleanup-sync-pr:
runs-on: ubuntu-latest
# Skip if this IS a sync PR (don't want infinite loops)
if: "!startsWith(github.event.pull_request.head.ref, 'docs-sync-pr-')"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if PR has English docs changes
id: check-english
run: |
# Quick check if this PR touched source language docs
PR_NUMBER=${{ github.event.pull_request.number }}
# Get source language directory from config.json (single source of truth)
SOURCE_DIR=$(python3 -c "import json; config = json.load(open('tools/translate/config.json')); print(config['languages'][config['source_language']]['directory'])")
# Get list of changed files
CHANGED_FILES=$(gh pr view $PR_NUMBER --json files --jq '.files[].path')
# Check if any source language docs were changed
if echo "$CHANGED_FILES" | grep -qE "^(docs\.json|${SOURCE_DIR}/.*\.(md|mdx))$"; then
echo "has_english_changes=true" >> $GITHUB_OUTPUT
echo "✅ PR has ${SOURCE_DIR}/ docs changes - checking for sync PR"
else
echo "has_english_changes=false" >> $GITHUB_OUTPUT
echo " No ${SOURCE_DIR}/ docs changes - skipping"
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Find and close sync PR
if: steps.check-english.outputs.has_english_changes == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PR_MERGED=${{ github.event.pull_request.merged }}
SYNC_BRANCH="docs-sync-pr-${PR_NUMBER}"
echo "Looking for sync PR with branch: $SYNC_BRANCH"
# Search for sync PR
SYNC_PR_DATA=$(gh pr list \
--search "head:${SYNC_BRANCH}" \
--json number,state \
--jq '.[0] // empty' 2>/dev/null || echo "")
if [ -z "$SYNC_PR_DATA" ] || [ "$SYNC_PR_DATA" = "null" ]; then
echo " No sync PR found for PR #${PR_NUMBER}"
exit 0
fi
SYNC_PR_NUMBER=$(echo "$SYNC_PR_DATA" | jq -r '.number')
SYNC_PR_STATE=$(echo "$SYNC_PR_DATA" | jq -r '.state')
if [ "$SYNC_PR_STATE" != "OPEN" ]; then
echo " Sync PR #${SYNC_PR_NUMBER} is already ${SYNC_PR_STATE}"
exit 0
fi
echo "Found open sync PR #${SYNC_PR_NUMBER}"
# Handle sync PR based on original PR status
if [ "$PR_MERGED" = "true" ]; then
# Original PR was merged - leave sync PR open for independent merging
echo " Original PR #${PR_NUMBER} was merged. Leaving sync PR #${SYNC_PR_NUMBER} open for independent review."
else
# Original PR was closed without merging - close sync PR
gh pr close ${SYNC_PR_NUMBER} --comment "❌ Original PR #${PR_NUMBER} was closed without merging. Closing this sync PR. If the original PR reopens, sync will resume automatically."
echo "✅ Closed sync PR #${SYNC_PR_NUMBER}"
fi