forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update sync workflow to handle specific conflicts (#459)
* Update sync workflow to hadle specific conflicts * Externalize KF_TAG variable to dedicated file outside of the makefile * Update makefile logic handling
- Loading branch information
Showing
3 changed files
with
72 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,80 @@ | ||
--- | ||
name: Sync branches through Pull Request | ||
name: Sync Branches | ||
|
||
on: # yamllint disable-line rule:truthy | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
source: | ||
description: Source branch | ||
description: "From:" | ||
required: true | ||
type: string | ||
target: | ||
description: Target branch | ||
description: "To:" | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
sync: | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
sync-branches: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.inputs.target }} | ||
fetch-depth: 0 | ||
|
||
- name: Prepare sync branch | ||
id: prepare | ||
run: | | ||
git fetch origin ${{ github.event.inputs.source }} | ||
git reset --hard origin/${{ github.event.inputs.source }} | ||
TIMESTAMP=$(date +'%Y%m%d%H%M%S') | ||
SYNC_BRANCH=sync__${{ github.event.inputs.source }}__${{ github.event.inputs.target }}__${TIMESTAMP} | ||
echo "branch=$SYNC_BRANCH" >> $GITHUB_OUTPUT | ||
- name: Create pull request | ||
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 | ||
with: | ||
branch: ${{ steps.prepare.outputs.branch }} | ||
title: "Sync `${{ github.event.inputs.target }}` branch with `${{ github.event.inputs.source }}` branch" | ||
body: | | ||
:robot: This is an automated Pull Request created by `/.github/workflows/sync-branches-through-pr.yml`. | ||
It merges all commits from `${{ github.event.inputs.source }}` branch into `${{ github.event.inputs.target }}` branch. | ||
:warning: **IMPORTANT NOTE**: Remember to delete the `${{ steps.prepare.outputs.branch }}` branch after merging the changes. | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Ensure full history is fetched for merging | ||
|
||
- name: Set up Git | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
- name: Merge source branch into target with conflict resolution | ||
id: merge | ||
run: | | ||
set -e | ||
SOURCE_BRANCH="${{ github.event.inputs.source }}" | ||
TARGET_BRANCH="${{ github.event.inputs.target }}" | ||
git fetch origin ${TARGET_BRANCH}:${TARGET_BRANCH} | ||
git checkout ${TARGET_BRANCH} | ||
git fetch origin ${SOURCE_BRANCH}:${SOURCE_BRANCH} | ||
git merge --no-commit origin/${SOURCE_BRANCH} || true | ||
# Resolve conflicts for specific files | ||
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 | ||
if [[ -f "$FILE" && "$(git status --porcelain=v1 2>/dev/null | grep -c "$FILE")" -gt 0 ]]; then | ||
echo "Resolving conflict for $FILE by keeping target branch version." | ||
git checkout --ours "$FILE" | ||
git add "$FILE" | ||
fi | ||
done | ||
# Commit the merge changes | ||
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') | ||
SYNC_BRANCH="sync__${SOURCE_BRANCH}__${TARGET_BRANCH}__${TIMESTAMP}" | ||
git checkout -b $SYNC_BRANCH | ||
git push origin $SYNC_BRANCH | ||
echo "branch=$SYNC_BRANCH" >> $GITHUB_OUTPUT | ||
- name: Create a Pull Request | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
SOURCE_BRANCH="${{ github.event.inputs.source }}" | ||
TARGET_BRANCH="${{ github.event.inputs.target }}" | ||
SYNC_BRANCH=$(echo "${{ steps.merge.outputs.branch }}") | ||
gh pr create \ | ||
--title "Sync ${SOURCE_BRANCH} into ${TARGET_BRANCH}" \ | ||
--body ":robot: This is an automated PR" \ | ||
--base "${{ github.event.inputs.target }}" \ | ||
--head "${SYNC_BRANCH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
KF_TAG ?= main-363bcdb |