From f435a14f62ec02ceae098a3ef9763c83d5bbb202 Mon Sep 17 00:00:00 2001 From: aTheo Date: Fri, 15 Nov 2024 12:50:24 +0100 Subject: [PATCH] Update sync-branches-through-pr-2.yaml --- .../workflows/sync-branches-through-pr-2.yaml | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/.github/workflows/sync-branches-through-pr-2.yaml b/.github/workflows/sync-branches-through-pr-2.yaml index f64ac65e003..0c69d6d0c41 100644 --- a/.github/workflows/sync-branches-through-pr-2.yaml +++ b/.github/workflows/sync-branches-through-pr-2.yaml @@ -5,11 +5,11 @@ on: workflow_dispatch: inputs: source: - description: "Source branch: From" + description: "From:" required: true type: string target: - description: "Target branch: To" + description: "To:" required: true type: string @@ -58,13 +58,19 @@ jobs: # Special handling for the Makefile MAKEFILE="components/odh-notebook-controller/Makefile" if [[ -f "$MAKEFILE" && "$(git status --porcelain=v1 2>/dev/null | grep -c "$MAKEFILE")" -gt 0 ]]; then - if git diff --ours "$MAKEFILE" | grep -q 'KF_TAG \?='; then - echo "Change in Makefile is limited to KF_TAG. Keeping target branch version." - git checkout --ours "$MAKEFILE" - else - echo "Changes in Makefile are not limited to KF_TAG. Applying incoming changes." - git checkout --theirs "$MAKEFILE" + echo "Resolving conflicts in $MAKEFILE while preserving KF_TAG." + + # Extract the KF_TAG value from the target branch + KF_TAG_TARGET=$(git show :2:"$MAKEFILE" | grep '^KF_TAG \?=' || echo "") + + # Apply incoming changes + git checkout --theirs "$MAKEFILE" + + # Restore the KF_TAG line from the target branch + if [[ -n "$KF_TAG_TARGET" ]]; then + sed -i "s/^KF_TAG \?=.*/$KF_TAG_TARGET/" "$MAKEFILE" fi + git add "$MAKEFILE" fi @@ -90,18 +96,3 @@ jobs: --body ":robot: This is an automated PR generated by `/.github/workflows/sync-branches-through-pr.yaml`" \ --base "${{ github.event.inputs.target }}" \ --head "${SYNC_BRANCH}" - - delete-branch: - if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }} - runs-on: ubuntu-latest - - steps: - - name: Delete branch - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - BRANCH_NAME=$(echo "${{ github.event.pull_request.head.ref }}") - REPO=${{ github.repository }} - echo "Deleting branch ${BRANCH_NAME} from ${REPO}..." - gh api -X DELETE \ - repos/${REPO}/git/refs/heads/${BRANCH_NAME}