fix: auto-resolve package-lock/badge/version conflicts in fork sync

The fork-sync and merge-forward workflows were failing on every run
because package-lock.json, package.json (version), and badge.svg
always conflict between upstream and forks. These are always safe to
take from upstream/main. Now auto-resolves these trivial conflicts
and only fails on real code conflicts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-03-25 00:39:20 +02:00
parent 57e520c7e1
commit bf9b7d0311
2 changed files with 68 additions and 14 deletions

View File

@@ -62,14 +62,34 @@ jobs:
# Merge upstream main into fork's main # Merge upstream main into fork's main
if ! git merge upstream/main --no-edit; then if ! git merge upstream/main --no-edit; then
echo "::error::Failed to merge upstream/main into fork main — conflicts detected" # Auto-resolve trivial conflicts (lockfile, badge, package.json version)
git merge --abort CONFLICTED=$(git diff --name-only --diff-filter=U)
echo "synced=false" >> "$GITHUB_OUTPUT" AUTO_RESOLVABLE=true
echo "sync_failed=true" >> "$GITHUB_OUTPUT" for f in $CONFLICTED; do
exit 0 case "$f" in
package-lock.json|package.json|repo-tokens/badge.svg)
git checkout --theirs "$f"
git add "$f"
;;
*)
AUTO_RESOLVABLE=false
;;
esac
done
if [ "$AUTO_RESOLVABLE" = false ]; then
echo "::error::Failed to merge upstream/main into fork main — non-trivial conflicts detected"
git merge --abort
echo "synced=false" >> "$GITHUB_OUTPUT"
echo "sync_failed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit --no-edit
echo "Auto-resolved lockfile/badge/version conflicts"
fi fi
# Validate build # Regenerate lockfile to match merged package.json
npm ci npm ci
if ! npm run build; then if ! npm run build; then
echo "::error::Build failed after merging upstream/main" echo "::error::Build failed after merging upstream/main"
@@ -115,10 +135,27 @@ jobs:
git checkout -B "$BRANCH" "origin/$BRANCH" git checkout -B "$BRANCH" "origin/$BRANCH"
if ! git merge main --no-edit; then if ! git merge main --no-edit; then
echo "::warning::Merge conflict in $BRANCH" # Auto-resolve trivial conflicts
git merge --abort CONFLICTED=$(git diff --name-only --diff-filter=U)
FAILED="$FAILED $SKILL_NAME" CAN_AUTO=true
continue for f in $CONFLICTED; do
case "$f" in
package-lock.json|package.json|repo-tokens/badge.svg)
git checkout --theirs "$f"
git add "$f"
;;
*)
CAN_AUTO=false
;;
esac
done
if [ "$CAN_AUTO" = false ]; then
echo "::warning::Merge conflict in $BRANCH"
git merge --abort
FAILED="$FAILED $SKILL_NAME"
continue
fi
git commit --no-edit
fi fi
# Check if there's anything new to push # Check if there's anything new to push

View File

@@ -52,10 +52,27 @@ jobs:
# Attempt merge # Attempt merge
if ! git merge main --no-edit; then if ! git merge main --no-edit; then
echo "::warning::Merge conflict in $BRANCH" # Auto-resolve trivial conflicts
git merge --abort CONFLICTED=$(git diff --name-only --diff-filter=U)
FAILED="$FAILED $SKILL_NAME" CAN_AUTO=true
continue for f in $CONFLICTED; do
case "$f" in
package-lock.json|package.json|repo-tokens/badge.svg)
git checkout --theirs "$f"
git add "$f"
;;
*)
CAN_AUTO=false
;;
esac
done
if [ "$CAN_AUTO" = false ]; then
echo "::warning::Merge conflict in $BRANCH"
git merge --abort
FAILED="$FAILED $SKILL_NAME"
continue
fi
git commit --no-edit
fi fi
# Check if there's anything new to push # Check if there's anything new to push