1+ name : Sync feature branches
2+ description : Synchronizes feature branches with main
3+ inputs :
4+ disabled-feature-branches :
5+ # GH doesn't have list inputs so we're using a string
6+ description : Feature branches for which syncing will be disabled, separated by comma (e.g. feat-1-main,feat-2-main)
7+ default : " "
8+
9+ runs :
10+ using : composite
11+ steps :
12+ - name : Checkout repository
13+ uses : actions/checkout@v4
14+ with :
15+ token : ${{ secrets.CI_USER_PAT }}
16+ fetch-depth : 0
17+
18+ - name : Set up Git
19+ shell : bash
20+ run : |
21+ git config user.name aws-sdk-kotlin-ci
22+ git config user.email "[email protected] " 23+
24+ - name : Merge main into feature branches
25+ shell : bash
26+ run : |
27+ echo "Parsing disabled feature branches"
28+ unparsed_disabled_feature_branches="${{ inputs.disabled-feature-branches }}"
29+ IFS=',' read -r -a disabled_feature_branches <<< "$unparsed_disabled_feature_branches"
30+ for i in "${!disabled_feature_branches[@]}"; do
31+ disabled_feature_branches[i]=$(echo "${disabled_feature_branches[i]}" | xargs)
32+ echo "Found: $disabled_feature_branches[i]"
33+ done
34+
35+ git fetch --all
36+
37+ echo "Iterating through feature branches"
38+ for feature_branch in $(git branch -r --list "*-main"); do # TODO: ALL OF THESE WILL HAVE "origin/" in front of them
39+ echo "Found: $feature_branch"
40+
41+ for disabled_feature_branch in "${disabled_feature_branches[@]}"; do
42+ if [[ "$feature_branch" == "$disabled_feature_branch" ]]; then
43+ echo "Main will not be merged into $feature_branch because it was manually disabled"
44+ continue
45+ fi
46+ done
47+
48+ echo "Checking if $feature_branch is up to date with main"
49+ git checkout $feature_branch
50+ git fetch origin
51+ commits_behind=$(git rev-list --left-right --count main...$feature_branch | awk '{print $1})
52+ if [ "$commits_behind" -eq 0 ]; then
53+ echo "$feature_branch is 0 commits behind main. Skipping merge"
54+ continue
55+ fi
56+
57+ # echo "Attempting to merge main into $feature_branch"
58+ # git pull origin $branch
59+ # git merge origin/main --no-ff
60+ # if [ $? -ne 0 ]; then
61+ # echo "Merge conflict detected! Creating a pull request..."
62+ # gh pr create --base main --head "$BRANCH" --title "Merge main into $BRANCH" --body "This PR merges main into $BRANCH to resolve conflicts."
63+ # else
64+ # echo "Merge successful. No conflicts detected."
65+ # fi
66+ # echo "Pushing to origin"
67+ # git push $feature_branch
0 commit comments