5555 run : |
5656 set -euo pipefail
5757 git fetch origin ${BASE_BRANCH} --quiet
58- UP_SHA=$(git rev-parse upstream/${BASE_BRANCH})
59- OR_SHA=$(git rev-parse origin/${BASE_BRANCH} || true)
60- echo "upstream/main: $UP_SHA"
61- echo "origin/main : $OR_SHA"
62- # Content-based sync check (robust to squash/rebase): compare trees
63- UP_TREE=$(git rev-parse upstream/${BASE_BRANCH}^{tree})
64- OR_TREE=$(git rev-parse origin/${BASE_BRANCH}^{tree} || true)
65- echo "upstream tree: $UP_TREE"
66- echo "origin tree: $OR_TREE"
67- if [ "$UP_TREE" = "$OR_TREE" ]; then
58+ echo "Checking differences excluding .github/workflows/**"
59+ if git diff --quiet upstream/${BASE_BRANCH} origin/${BASE_BRANCH} -- . ':(exclude).github/workflows/**'; then
6860 echo "in_sync=true" >> $GITHUB_OUTPUT
6961 else
7062 echo "in_sync=false" >> $GITHUB_OUTPUT
@@ -88,13 +80,22 @@ jobs:
8880 git switch -c ${SYNC_BRANCH} origin/${BASE_BRANCH}
8981 fi
9082
91- # Force reset sync branch to upstream/main
92- git reset --hard upstream/${BASE_BRANCH}
93-
94- # Restore our own workflow files (don't sync upstream workflows)
95- git checkout origin/${BASE_BRANCH} -- .github/workflows/ || true
96- git commit -m "Preserve Mirantis workflow files" --allow-empty || true
97-
83+ # Rebase local state of sync branch onto our main to start clean
84+ git reset --hard origin/${BASE_BRANCH}
85+
86+ # Compute and apply upstream changes excluding workflow files
87+ if git diff --quiet origin/${BASE_BRANCH} upstream/${BASE_BRANCH} -- . ':(exclude).github/workflows/**'; then
88+ echo "No non-workflow changes from upstream; nothing to apply."
89+ else
90+ git diff --binary origin/${BASE_BRANCH} upstream/${BASE_BRANCH} -- . ':(exclude).github/workflows/**' > /tmp/upstream-no-workflows.patch
91+ git apply -3 /tmp/upstream-no-workflows.patch || {
92+ echo "::error::Failed to apply upstream patch excluding workflows";
93+ exit 1;
94+ }
95+ git add -A
96+ git commit -m "Sync with upstream/${BASE_BRANCH} (excluding .github/workflows)" || true
97+ fi
98+
9899 # Push the updated sync branch
99100 git push -f origin ${SYNC_BRANCH}
100101
@@ -105,18 +106,15 @@ jobs:
105106 # Fetch latest state to ensure we have current refs
106107 git fetch origin ${BASE_BRANCH} ${SYNC_BRANCH} --quiet
107108
108- # After resetting sync to upstream, decide if PR is needed based on patch-unique commits
109- UPSTREAM_PATCH_AHEAD=$(git rev-list --left-only --cherry-pick --count upstream/${BASE_BRANCH}...origin/${BASE_BRANCH} || echo 0)
110- echo "upstream patch-ahead of main by: $UPSTREAM_PATCH_AHEAD commits"
111-
112- if [ "$UPSTREAM_PATCH_AHEAD" -gt 0 ]; then
113- echo "has_changes=true" >> $GITHUB_OUTPUT
114- echo "PR is needed; upstream has patch-unique commits not in main"
115- echo "Representative missing upstream commits:"
116- git log --left-right --cherry-pick --oneline upstream/${BASE_BRANCH}...origin/${BASE_BRANCH} | sed -n 's/^</missing /p' | head -10 || true
117- else
109+ # Decide if PR is needed based on content differences excluding workflow files
110+ if git diff --quiet origin/${BASE_BRANCH} origin/${SYNC_BRANCH} -- . ':(exclude).github/workflows/**'; then
118111 echo "has_changes=false" >> $GITHUB_OUTPUT
119- echo "All upstream changes already present in main (possibly via squash/rebase); no PR needed"
112+ echo "All upstream changes already present in main (excluding workflows); no PR needed"
113+ else
114+ echo "has_changes=true" >> $GITHUB_OUTPUT
115+ echo "PR is needed; content changes detected outside .github/workflows/**"
116+ echo "Changed files (excluding workflows):"
117+ git diff --name-only origin/${BASE_BRANCH} origin/${SYNC_BRANCH} -- . ':(exclude).github/workflows/**' | head -50 || true
120118 fi
121119
122120 - name : Create or update PR to main
@@ -172,12 +170,12 @@ jobs:
172170 echo ""
173171 echo "=== Mirror Sync Report ==="
174172 if [ "${{ steps.diff.outputs.in_sync }}" = "true" ]; then
175- echo "Already in sync with upstream/main. No PR updates needed."
173+ echo "Already in sync with upstream/main (excluding .github/workflows) . No PR updates needed."
176174 elif [ "${{ steps.branch_diff.outputs.has_changes || 'false' }}" = "false" ]; then
177- echo "Branches were out of sync but have identical content. Sync branch updated."
175+ echo "Branches were out of sync but have identical content outside workflows . Sync branch updated."
178176 else
179177 echo "Opened/updated PR from ${SYNC_BRANCH} -> ${BASE_BRANCH}."
180- echo "Content changes detected between branches"
178+ echo "Content changes detected between branches (excluding .github/workflows) "
181179 fi
182180 echo ""
183181 echo "Latest commits on upstream/main:"
0 commit comments