Skip to content

Commit cb59c3e

Browse files
committed
feat: sync feature branches with main action
1 parent 3694e72 commit cb59c3e

File tree

4 files changed

+85
-91
lines changed

4 files changed

+85
-91
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

.github/workflows/continuous-integration.yml

Lines changed: 0 additions & 64 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/test-bed.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Testing new GH action
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
- '!main'
7+
pull_request:
8+
branches: [ main ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
ktlint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Run GH action
16+
uses: ./.github/actions/sync-feature-branches
17+
with:
18+
disabled-feature-branches: 'test-main'

0 commit comments

Comments
 (0)