From 70de366b96a91d1a2d7321d5560f6457a0e9f827 Mon Sep 17 00:00:00 2001 From: Franco Date: Tue, 7 Apr 2026 13:40:03 -0300 Subject: [PATCH] Fix sync-from-upstream overwriting existing update branch Use the existing remote branch when it already exists instead of resetting from main with -B and force-pushing. This preserves any commits already on the update branch. - Check for remote branch existence with git ls-remote before checkout - Track the existing remote branch if present, otherwise create from main - Guard commit with git diff --cached to skip if vendir.yml unchanged - Drop --force from git push --- .github/workflows/sync-from-upstream.yaml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sync-from-upstream.yaml b/.github/workflows/sync-from-upstream.yaml index 337d82e..ae81837 100644 --- a/.github/workflows/sync-from-upstream.yaml +++ b/.github/workflows/sync-from-upstream.yaml @@ -40,12 +40,19 @@ jobs: git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" git fetch origin - git checkout main - git checkout -B "${{ inputs.update_branch }}" + + # Use the existing remote branch if present; otherwise create from main + if git ls-remote --exit-code --heads origin "${{ inputs.update_branch }}" > /dev/null 2>&1; then + git checkout --track "origin/${{ inputs.update_branch }}" + else + git checkout main + git checkout -b "${{ inputs.update_branch }}" + fi + git checkout "origin/${{ github.ref_name }}" -- vendir.yml git add vendir.yml - git commit -m "Update vendir.yml from upstream" - git push origin "${{ inputs.update_branch }}" --force + git diff --cached --quiet || git commit -m "Update vendir.yml from upstream" + git push origin "${{ inputs.update_branch }}" call-update-chart: needs: prepare-update-branch