fix(sync): format changed files after cherry-pick so lint passes

Merged
TO
10d ago
+195-7

What

Open sync PRs against plus were failing the tree-wide prettier check. Two things combined:

  1. The branches were based on plus before #243, so they still had the unformatted SystemBars.java from #223. plus lint runs prettier on the whole tree, not just the PR diff, so every tip failed.
  2. Tomorrow's 06:00 UTC sync would still be able to open red PRs. format_files_changed_since existed but was never called. The clean merge path ran bun run fmt, but the conflict fallback (the path these PRs actually took this morning, when merging a whole upstream PR branch conflicted) skipped formatting.

#243 already formatted SystemBars.java on plus and switched the helper to cherry-pick. This PR makes sure every successful cherry-pick or plus-preserving merge formats the files it just changed and commits the result.

How

  • After a clean or --theirs cherry-pick, and after a plus-preserving merge, call format_after_sync.
  • format_files_changed_since now runs real prettier --write (with prettier-plugin-java) and eslint --fix on changed files, plus swiftlint --fix when it is installed. It prefers a plus ref that is still distinct from HEAD, so a merge performed on plus itself does not no-op.
  • Both scheduled sync workflows already source this helper, so the conflict path is covered without editing workflow files.

Workflow files were not changed. The token available here cannot update .github/workflows/* (no workflow scope). A follow-up with workflow scope should still: refresh local plus from origin/plus before creating sync branches, run the formatter on the YAML conflict paths as a second belt, and add oven-sh/setup-bun@v2 plus bun install to the sync-branches.yml plus job so 05:00 UTC plus-upstream PRs can format too. sync-upstream.yml (06:00 UTC) already installs bun.

No new secrets. The existing org secret PERSONAL_ACCESS_TOKEN is unchanged. Timeout caps stay at 10 minutes.

Tests

bash .github/scripts/test-sync-gh-helpers.sh passes 12/12, including:

  • format_files_changed_since commits prettier output for a changed .ts file
  • it does not create a commit when prettier changes nothing

Notes

  • No new capabilities, so no website docs PR.
  • This is one PR against plus, not stacked on the sync PRs.
  • The six open sync PRs still need plus merged in separately so they pick up the #243 SystemBars.java fix and any file-level format on their own changes.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Workflow change, Martin applies

The bot tokens lack the workflow scope, so these two workflow edits are not in the commits above. From a checkout of this PR branch, run the block below, then commit and push to this branch before merging.

  • sync-branches.yml (05:00 UTC plus job): adds oven-sh/setup-bun@v2 (version tag, not a SHA) and bun install --frozen-lockfile. The clean merge path ("Push if merge succeeded") now sources the helper and formats before git push origin plus, and the conflict PR path also formats before pushing its sync branch.
  • sync-upstream.yml (06:00 UTC): fast-forwards local plus to origin/plus before creating sync branches, and formats files changed since plus after each cherry-pick or merge path.
  • Every format_files_changed_since call is wrapped with || echo, so a failed format cannot abort a successful sync (same as format_after_sync).
  • Format commits stage with git add -u (tracked files only), so bun run fmt cannot pull unrelated untracked files into a commit.
  • No timeout changes. Reuses the existing PERSONAL_ACCESS_TOKEN secret. No new secrets.

Checked with git apply --check against this branch at 572b1cec, and both YAML files parse.

git apply <<'PATCH'
diff --git a/.github/workflows/sync-branches.yml b/.github/workflows/sync-branches.yml
index 876b58c..ad7d656 100644
--- a/.github/workflows/sync-branches.yml
+++ b/.github/workflows/sync-branches.yml
@@ -185,6 +185,12 @@ jobs:
           token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
           ref: plus
 
+      - name: Setup Bun
+        uses: oven-sh/setup-bun@v2
+
+      - name: Install dependencies
+        run: bun install --frozen-lockfile
+
       - name: Configure Git
         run: |
           git config user.name "Capacitor+ Bot"
@@ -242,6 +248,17 @@ jobs:
       - name: Push if merge succeeded
         if: steps.merge.outputs.merge_success == 'true'
         run: |
+          source .github/scripts/sync-gh-helpers.sh
+
+          echo "Running formatter..."
+          format_files_changed_since origin/plus || echo "Formatting changed files had issues, continuing..."
+          bun run fmt || echo "Formatter had some issues, continuing..."
+          if ! git diff --quiet; then
+            echo "Formatter made changes, committing..."
+            git add -u
+            git commit -m "style: auto-format code after upstream sync"
+          fi
+
           git push origin plus
           echo "Successfully pushed upstream changes to plus branch"
 
@@ -260,6 +277,7 @@ jobs:
             exit 0
           fi
 
+          git fetch origin plus
           SYNC_BRANCH="sync/plus-upstream-$(date +%Y%m%d-%H%M%S)"
           git checkout -b "$SYNC_BRANCH" origin/plus
 
@@ -272,6 +290,15 @@ jobs:
             exit 1
           fi
 
+          echo "Running formatter..."
+          format_files_changed_since origin/plus || echo "Formatting changed files had issues, continuing..."
+          bun run fmt || echo "Formatter had some issues, continuing..."
+          if ! git diff --quiet; then
+            echo "Formatter made changes, committing..."
+            git add -u
+            git commit -m "style: auto-format code after upstream sync"
+          fi
+
           git push origin "$SYNC_BRANCH" --force
 
           PR_TITLE="chore: sync plus with upstream main (upstream-preferred conflicts)"
diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml
index e766f89..1230fa5 100644
--- a/.github/workflows/sync-upstream.yml
+++ b/.github/workflows/sync-upstream.yml
@@ -73,6 +73,11 @@ jobs:
           source .github/scripts/sync-gh-helpers.sh
           ensure_sync_labels "${GITHUB_REPOSITORY}"
 
+          echo "Updating local plus to origin/plus so sync branches start from current plus"
+          git fetch origin plus
+          git checkout plus
+          git merge --ff-only origin/plus || git reset --hard origin/plus
+
           echo "Fetching open PRs from upstream repository..."
 
           # Get all open PRs from upstream (only from forks/external contributors)
@@ -194,12 +199,13 @@ jobs:
 
               # Run formatter to ensure lint passes
               echo "Running formatter..."
+              format_files_changed_since plus || echo "Formatting changed files had issues, continuing..."
               bun run fmt || echo "Formatter had some issues, continuing..."
 
               # Check if fmt made any changes and commit them
               if ! git diff --quiet; then
                 echo "Formatter made changes, committing..."
-                git add -A
+                git add -u
                 git commit -m "style: auto-format code after upstream sync"
               fi
 
@@ -258,6 +264,15 @@ jobs:
 
               git show plus:.github/scripts/preserve-fork-changelog.sh | TRUSTED_PLUS_REF=plus bash -s
 
+              echo "Running formatter..."
+              format_files_changed_since plus || echo "Formatting changed files had issues, continuing..."
+              bun run fmt || echo "Formatter had some issues, continuing..."
+              if ! git diff --quiet; then
+                echo "Formatter made changes, committing..."
+                git add -u
+                git commit -m "style: auto-format code after upstream sync"
+              fi
+
               git push origin "$SYNC_BRANCH" --force
 
               PR_BODY=$(cat <<EOF_BODY
@@ -339,7 +354,9 @@ jobs:
           git remote add upstream https://github.com/${{ env.UPSTREAM_REPO }}.git || true
           git fetch upstream
 
+          git fetch origin plus
           git checkout plus
+          git merge --ff-only origin/plus || git reset --hard origin/plus
           git fetch upstream main
 
           # Check if there are new commits from upstream
@@ -364,12 +381,13 @@ jobs:
 
             # Run formatter to ensure lint passes
             echo "Running formatter..."
+            format_files_changed_since plus || echo "Formatting changed files had issues, continuing..."
             bun run fmt || echo "Formatter had some issues, continuing..."
 
             # Check if fmt made any changes and commit them
             if ! git diff --quiet; then
               echo "Formatter made changes, committing..."
-              git add -A
+              git add -u
               git commit -m "style: auto-format code after upstream sync"
             fi
 
@@ -408,6 +426,15 @@ jobs:
 
             git show plus:.github/scripts/preserve-fork-changelog.sh | TRUSTED_PLUS_REF=plus bash -s
 
+            echo "Running formatter..."
+            format_files_changed_since plus || echo "Formatting changed files had issues, continuing..."
+            bun run fmt || echo "Formatter had some issues, continuing..."
+            if ! git diff --quiet; then
+              echo "Formatter made changes, committing..."
+              git add -u
+              git commit -m "style: auto-format code after upstream sync"
+            fi
+
             git push origin "$SYNC_BRANCH" --force
 
             PR_BODY=$(cat <<'EOF_BODY'
@@ -470,6 +497,11 @@ jobs:
           source .github/scripts/sync-gh-helpers.sh
           ensure_sync_labels "${GITHUB_REPOSITORY}"
 
+          echo "Updating local plus to origin/plus so sync branches start from current plus"
+          git fetch origin plus
+          git checkout plus
+          git merge --ff-only origin/plus || git reset --hard origin/plus
+
           echo "Syncing specific PR #$PR_NUMBER from upstream..."
 
           # Get PR info
@@ -506,12 +538,13 @@ jobs:
 
             # Run formatter to ensure lint passes
             echo "Running formatter..."
+            format_files_changed_since plus || echo "Formatting changed files had issues, continuing..."
             bun run fmt || echo "Formatter had some issues, continuing..."
 
             # Check if fmt made any changes and commit them
             if ! git diff --quiet; then
               echo "Formatter made changes, committing..."
-              git add -A
+              git add -u
               git commit -m "style: auto-format code after upstream sync"
             fi
 
@@ -557,6 +590,15 @@ jobs:
 
             git show plus:.github/scripts/preserve-fork-changelog.sh | TRUSTED_PLUS_REF=plus bash -s
 
+            echo "Running formatter..."
+            format_files_changed_since plus || echo "Formatting changed files had issues, continuing..."
+            bun run fmt || echo "Formatter had some issues, continuing..."
+            if ! git diff --quiet; then
+              echo "Formatter made changes, committing..."
+              git add -u
+              git commit -m "style: auto-format code after upstream sync"
+            fi
+
             git push origin "$SYNC_BRANCH" --force
 
             PR_BODY=$(cat <<EOF_BODY
PATCH
git add .github/workflows/sync-branches.yml .github/workflows/sync-upstream.yml
git commit -m "ci(sync): install bun and auto-format after upstream sync"
git push