Ai dlc/haiku rebrand/main (#138) #82
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Conflict Resolver | |
| on: | |
| push: | |
| branches: [main] | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| resolve-conflicts: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Find and resolve conflicting PRs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Poll until GitHub recalculates mergeability | |
| for attempt in 1 2 3 4 5; do | |
| echo "Attempt $attempt: checking mergeability..." | |
| sleep $(( attempt * 10 )) | |
| ALL_PRS=$(gh pr list --base main --state open --json number,headRefName,mergeable --repo "$GITHUB_REPOSITORY" 2>/dev/null || echo "[]") | |
| UNKNOWN=$(echo "$ALL_PRS" | jq '[.[] | select(.mergeable == "UNKNOWN")] | length') | |
| [ "$UNKNOWN" -eq 0 ] && break | |
| done | |
| CONFLICTING=$(echo "$ALL_PRS" | jq -r '.[] | select(.mergeable == "CONFLICTING") | "\(.number) \(.headRefName)"') | |
| if [ -z "$CONFLICTING" ]; then | |
| echo "No conflicting PRs" | |
| exit 0 | |
| fi | |
| echo "Conflicting PRs:" | |
| echo "$CONFLICTING" | |
| RESOLVED=0 | |
| FAILED=0 | |
| while IFS=' ' read -r PR_NUM BRANCH; do | |
| echo "" | |
| echo "=== PR #$PR_NUM ($BRANCH) ===" | |
| # Fetch and checkout PR branch | |
| git fetch origin "$BRANCH" main | |
| git checkout "$BRANCH" | |
| git reset --hard "origin/$BRANCH" | |
| # Attempt merge | |
| if git merge origin/main --no-edit 2>/dev/null; then | |
| echo "Auto-merged cleanly" | |
| git push origin "$BRANCH" | |
| RESOLVED=$((RESOLVED + 1)) | |
| continue | |
| fi | |
| # Check if conflicts are in version/changelog files only (auto-resolvable) | |
| CONFLICT_FILES=$(git diff --name-only --diff-filter=U) | |
| echo "Conflicted files: $CONFLICT_FILES" | |
| CAN_AUTO_RESOLVE=true | |
| for f in $CONFLICT_FILES; do | |
| case "$f" in | |
| # Version files: take main's version (theirs) | |
| plugin/.claude-plugin/plugin.json|.claude-plugin/marketplace.json) | |
| git checkout --theirs "$f" | |
| git add "$f" | |
| ;; | |
| # Changelog: take main's version (theirs) — it has the full history | |
| CHANGELOG.md) | |
| git checkout --theirs "$f" | |
| git add "$f" | |
| ;; | |
| # Content files: try to auto-resolve by keeping both | |
| *.md|*.sh|*.json|*.yml|*.yaml|*.ts|*.tsx) | |
| # Check if conflict markers exist | |
| if grep -q '<<<<<<<' "$f" 2>/dev/null; then | |
| echo " Complex conflict in $f — needs manual resolution" | |
| CAN_AUTO_RESOLVE=false | |
| fi | |
| ;; | |
| *) | |
| echo " Unknown conflict in $f — needs manual resolution" | |
| CAN_AUTO_RESOLVE=false | |
| ;; | |
| esac | |
| done | |
| if [ "$CAN_AUTO_RESOLVE" = true ]; then | |
| # All conflicts were version/changelog — commit and push | |
| git commit --no-edit | |
| git push origin "$BRANCH" | |
| echo "Resolved (version/changelog only)" | |
| RESOLVED=$((RESOLVED + 1)) | |
| else | |
| # Abort and comment on PR | |
| git merge --abort | |
| gh pr comment "$PR_NUM" --repo "$GITHUB_REPOSITORY" --body "⚠️ This PR has merge conflicts with main that require manual resolution. Conflicted files: \`$CONFLICT_FILES\`" | |
| echo "Could not auto-resolve — commented on PR" | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| done <<< "$CONFLICTING" | |
| echo "" | |
| echo "Summary: $RESOLVED resolved, $FAILED need manual resolution" |