Skip to content

Commit 7b22ea7

Browse files
authored
Merge pull request #10 from Mirantis/workflow_fix
fix: workflow comparing commits and raising PR
2 parents 95594d5 + 06bf8dd commit 7b22ea7

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

.github/workflows/upstream-sync.yaml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,51 @@ jobs:
6464
if: steps.diff.outputs.in_sync == 'false'
6565
run: |
6666
# Create or switch to the evergreen sync branch
67-
if git rev-parse --verify origin/${SYNC_BRANCH} >/dev/null 2>&1; then
68-
git switch -c ${SYNC_BRANCH} --track origin/${SYNC_BRANCH} || git switch ${SYNC_BRANCH}
67+
if git show-ref --verify --quiet refs/remotes/origin/${SYNC_BRANCH}; then
68+
# Sync branch exists on remote - check if we have it locally
69+
if git show-ref --verify --quiet refs/heads/${SYNC_BRANCH}; then
70+
git switch ${SYNC_BRANCH}
71+
else
72+
git switch -c ${SYNC_BRANCH} --track origin/${SYNC_BRANCH}
73+
fi
6974
else
70-
git switch -c ${SYNC_BRANCH} origin/${BASE_BRANCH} || git switch -c ${SYNC_BRANCH}
75+
# Sync branch doesn't exist - create from main
76+
git switch -c ${SYNC_BRANCH} origin/${BASE_BRANCH}
7177
fi
7278
7379
# Force reset sync branch to upstream/main
7480
git reset --hard upstream/${BASE_BRANCH}
7581
# Push the updated sync branch
7682
git push -f origin ${SYNC_BRANCH}
7783
78-
- name: Create or update PR to main
84+
- name: Check if sync branch differs from main
7985
if: steps.diff.outputs.in_sync == 'false'
86+
id: branch_diff
87+
run: |
88+
# Fetch latest state to ensure we have current refs
89+
git fetch origin ${BASE_BRANCH} ${SYNC_BRANCH} --quiet
90+
91+
# Check if branches are actually different (tree-wise)
92+
MAIN_TREE=$(git rev-parse origin/${BASE_BRANCH}^{tree})
93+
SYNC_TREE=$(git rev-parse origin/${SYNC_BRANCH}^{tree})
94+
95+
echo "main tree: $MAIN_TREE"
96+
echo "sync tree: $SYNC_TREE"
97+
98+
if [ "$MAIN_TREE" = "$SYNC_TREE" ]; then
99+
echo "has_changes=false" >> $GITHUB_OUTPUT
100+
echo "Branches have identical content (same tree), no PR needed"
101+
else
102+
echo "has_changes=true" >> $GITHUB_OUTPUT
103+
echo "Branches have different content, PR is needed"
104+
105+
# Show what's different (for debugging)
106+
echo "Files changed between branches:"
107+
git diff --name-only origin/${BASE_BRANCH} origin/${SYNC_BRANCH} | head -10
108+
fi
109+
110+
- name: Create or update PR to main
111+
if: steps.diff.outputs.in_sync == 'false' && steps.branch_diff.outputs.has_changes == 'true'
80112
uses: actions/github-script@v7
81113
with:
82114
script: |
@@ -128,8 +160,11 @@ jobs:
128160
echo "=== Mirror Sync Report ==="
129161
if [ "${{ steps.diff.outputs.in_sync }}" = "true" ]; then
130162
echo "Already in sync with upstream/main. No PR updates needed."
163+
elif [ "${{ steps.branch_diff.outputs.has_changes || 'false' }}" = "false" ]; then
164+
echo "Branches were out of sync but have identical content. Sync branch updated."
131165
else
132166
echo "Opened/updated PR from ${SYNC_BRANCH} -> ${BASE_BRANCH}."
167+
echo "Content changes detected between branches"
133168
fi
134169
echo ""
135170
echo "Latest commits on upstream/main:"
@@ -144,4 +179,4 @@ jobs:
144179
run: |
145180
echo "::error::🚨 Mirror sync failed! Manual intervention required."
146181
echo "::error::Repository: ${{ github.repository }}"
147-
echo "::error::Run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
182+
echo "::error::Run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"

0 commit comments

Comments
 (0)