Skip to content

Commit

Permalink
Update sync-branches-through-pr-2.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
atheo89 authored Nov 15, 2024
1 parent 317323d commit f435a14
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions .github/workflows/sync-branches-through-pr-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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}

0 comments on commit f435a14

Please sign in to comment.