forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 50
116 lines (99 loc) · 3.76 KB
/
Copy pathsync-branches.yaml
File metadata and controls
116 lines (99 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Sync Branches
on:
workflow_dispatch:
inputs:
source:
description: "From:"
required: true
type: string
target:
description: "To:"
required: true
type: string
workflow_call:
inputs:
source:
description: "From:"
required: true
type: string
target:
description: "To:"
required: true
type: string
permissions: {}
env:
SOURCE_BRANCH: ${{ inputs.source }}
TARGET_BRANCH: ${{ inputs.target }}
jobs:
sync-branches:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
- name: Merge source branch into target
run: |
set -e
# Fetch and checkout target branch
git fetch origin ${{ env.TARGET_BRANCH }}:${{ env.TARGET_BRANCH }}
git checkout ${{ env.TARGET_BRANCH }}
# Fetch and merge source branch
git fetch origin ${{ env.SOURCE_BRANCH }}:${{ env.SOURCE_BRANCH }}
git merge --no-commit origin/${{ env.SOURCE_BRANCH }} || true
#########################################################################
# Always keep target branch state for .tekton
# (do not propagate any .tekton changes from source branch).
# Caveats:
# - This applies to any source/target pair using this workflow.
# - If target does not contain .tekton, any merged .tekton content from
# source will be removed.
# - This guard exists only in this workflow; manual merges can still
# propagate .tekton unless handled similarly.
# Reset .tekton completely to target (HEAD) state
git rm -r -f --cached --ignore-unmatch -- ':/.tekton'
rm -rf -- "$(git rev-parse --show-toplevel)/.tekton"
# Re-checkout .tekton only if it exists on target
if git rev-parse --verify HEAD:.tekton >/dev/null 2>&1; then
echo "Keeping target branch version of .tekton."
git checkout HEAD -- ':/.tekton'
git add -A -- ':/.tekton'
fi
#########################################################################
# Known files to resolve the conflicts
FILES=(
"components/notebook-controller/config/overlays/openshift/params.env"
"components/odh-notebook-controller/config/overlays/odh/params.env"
"components/odh-notebook-controller/config/overlays/rhoai/params.env"
"components/odh-notebook-controller/makefile-vars.mk"
)
# Resolve conflicts for known files
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
# Check for potential unresolved conflicts
if [[ -n "$(git ls-files -u)" ]]; then
echo "Unresolved conflicts detected in the following files:"
git ls-files -u
echo "Aborting merge due to unexpected conflicts."
exit 1
fi
# Commit changes if any
if [[ -n "$(git status --porcelain)" ]]; then
git commit -m "Merge ${{ env.SOURCE_BRANCH }} into ${{ env.TARGET_BRANCH }} with known resolved conflicts"
else
echo "No changes to commit. Skipping push."
exit 0
fi
# Push changes directly to target branch
git push origin ${{ env.TARGET_BRANCH }}