diff --git a/.github/workflows/build_loop.yml b/.github/workflows/build_loop.yml index 2a9755efa6..52d1fccae1 100644 --- a/.github/workflows/build_loop.yml +++ b/.github/workflows/build_loop.yml @@ -233,26 +233,43 @@ jobs: vars.SCHEDULED_SYNC != 'false' && github.repository_owner != 'LoopKit' && needs.check_latest_from_upstream.outputs.ABORT_SYNC == 'false' id: sync run: | - # First try the standard fork sync action - set +e - echo "Attempting standard fork sync..." + set -e + echo "Starting upstream sync process..." - # Use the fork sync action first - gh extension install aormsby/gh-fork-sync || echo "Extension already installed" + # Try to install gh-fork-sync extension if not already installed + if ! gh extension list | grep -q "aormsby/gh-fork-sync"; then + echo "Installing gh-fork-sync extension..." + gh extension install aormsby/gh-fork-sync || echo "Failed to install extension" + fi - # Try fork sync with the action approach first - sync_result=0 + # Try gh-fork-sync first if available + if gh extension list | grep -q "aormsby/gh-fork-sync"; then + echo "Using gh-fork-sync extension..." + set +e + gh fork-sync --upstream "$UPSTREAM_REPO" --branch "$TARGET_BRANCH" + sync_result=$? + set -e + + if [ $sync_result -eq 0 ]; then + echo "Fork sync completed successfully" + echo "has_new_commits=true" >> $GITHUB_OUTPUT + exit 0 + else + echo "Fork sync failed, falling back to custom script..." + fi + else + echo "gh-fork-sync not available, using custom script..." + fi - # If the action approach fails, use our custom script - echo "Using custom sync script to handle potential conflicts..." + # Use our custom script as fallback or primary method + echo "Using custom sync script to handle merge conflicts..." bash ./Scripts/sync_with_upstream.sh sync_result=$? if [ $sync_result -eq 0 ]; then - echo "Sync completed successfully" - echo "has_new_commits=true" >> $GITHUB_OUTPUT + echo "Custom sync completed successfully" else - echo "Sync failed" + echo "Custom sync failed" exit 1 fi env: diff --git a/Scripts/sync_with_upstream.sh b/Scripts/sync_with_upstream.sh index a4f08d81a8..fd4dca9bf5 100755 --- a/Scripts/sync_with_upstream.sh +++ b/Scripts/sync_with_upstream.sh @@ -71,10 +71,14 @@ fi # Attempt merge with upstream echo -e "${YELLOW}Attempting to merge upstream changes${NC}" -if git merge "upstream/$UPSTREAM_BRANCH" --no-edit; then +if git merge "upstream/$UPSTREAM_BRANCH" --no-edit --allow-unrelated-histories; then echo -e "${GREEN}Successfully merged upstream changes without conflicts${NC}" echo -e "${GREEN}Pushing changes to origin${NC}" - git push origin "$TARGET_BRANCH" + if [ "$GH_PAT" = "dummy" ]; then + echo -e "${YELLOW}Skipping push (dummy PAT provided)${NC}" + else + git push origin "$TARGET_BRANCH" + fi exit 0 fi