Skip to content

Commit

Permalink
Update makefile logic handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atheo89 committed Nov 18, 2024
1 parent d0f6d50 commit 67be00d
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions .github/workflows/sync-branches-through-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
FILES=(
"components/notebook-controller/config/overlays/openshift/params.env"
"components/odh-notebook-controller/config/base/params.env"
"components/odh-notebook-controller/makefile-vars.mk"
)
for FILE in "${FILES[@]}"; do
Expand All @@ -55,46 +56,8 @@ jobs:
fi
done
# Handle the Makefile in case there are other canges apart KF_TAG value
MAKEFILE="components/odh-notebook-controller/Makefile"
if [[ -f "$MAKEFILE" && "$(git status --porcelain=v1 2>/dev/null | grep -c "$MAKEFILE")" -gt 0 ]]; then
echo "Resolving conflicts in $MAKEFILE while preserving KF_TAG."
# Extract KF_TAG from the target branch
KF_TAG_TARGET=$(cat "$MAKEFILE" | awk '
BEGIN { in_head = 0 }
/^<<<<<<< HEAD/ { in_head = 1; next } # Enter HEAD block
/^=======/ { in_head = 0 } # Exit HEAD block
in_head && /^KF_TAG \?=/ { print $0 } # Extract full line
' || echo "KF_TAG ?= main")
if [[ -z "$KF_TAG_TARGET" ]]; then
echo "KF_TAG not found in target branch; using a fallback value."
KF_TAG_TARGET="KF_TAG ?= main"
fi
# Process the conflicting Makefile
awk -v kf_tag="$KF_TAG_TARGET" '
BEGIN { conflict = 0 }
/^<<<<<<< / { conflict = 1; next } # Start of conflict
/^=======/ { conflict = 2; next } # Separator in conflict
/^>>>>>>> / { conflict = 0; next } # End of conflict
conflict == 1 && /^KF_TAG \?=/ { next } # Ignore incoming KF_TAG
conflict == 2 && /^KF_TAG \?=/ { print kf_tag; next } # Use target KF_TAG
{ print $0 } # Print other lines
' "$MAKEFILE" > "$MAKEFILE.new"
# Replace original Makefile with resolved version
mv "$MAKEFILE.new" "$MAKEFILE"
echo "Preserved KF_TAG as: $KF_TAG_TARGET"
# Stage the resolved Makefile
git add "$MAKEFILE"
fi
# Commit the merge changes
git commit -m "Merge ${SOURCE_BRANCH} into ${TARGET_BRANCH} with resolved conflicts, preserving KF_TAG in Makefile" || echo "Nothing to commit"
git commit -m "Merge ${SOURCE_BRANCH} into ${TARGET_BRANCH} with resolved conflicts" || echo "Nothing to commit"
# Create a new branch for the sync
TIMESTAMP=$(date +'%Y%m%d%H%M%S')
Expand Down

0 comments on commit 67be00d

Please sign in to comment.