Skip to content

Commit 330d095

Browse files
authored
feat: main to feature branches merge (#73)
1 parent a78edcd commit 330d095

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Merge Main
2+
description: Merges main into feature branches (*-main)
3+
inputs:
4+
exempt-branches:
5+
description: Feature branches that are exempt from receiving merges from main (comma separated, no blank space)
6+
7+
runs:
8+
using: composite
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Git
14+
shell: bash
15+
run: |
16+
git config user.name aws-sdk-kotlin-ci
17+
git config user.email "[email protected]"
18+
19+
- name: Run Script
20+
shell: bash
21+
run: |
22+
.github/scripts/merge-main.sh ${{ inputs.exempt-branches }}

.github/scripts/merge-main.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
input=$1
4+
5+
function fetch_latest_changes() {
6+
echo "Fetching the latest remote branches"
7+
git fetch --all
8+
}
9+
10+
fetch_latest_changes
11+
12+
function find_feature_branches() {
13+
echo "Searching for feature branches"
14+
feature_branches=($(git branch -r --list "*-main" | sed 's|origin/||'))
15+
16+
if [ ${#feature_branches[@]} -eq 0 ]; then
17+
echo "...none found"
18+
return
19+
fi
20+
21+
for feature_branch in "${feature_branches[@]}"; do
22+
echo "...found feature branch: $feature_branch"
23+
done
24+
}
25+
26+
find_feature_branches
27+
28+
function find_exempt_branches() {
29+
echo "Searching for exempt branches"
30+
IFS=',' read -r -a exempt_branches <<< "$input"
31+
32+
if [ ${#exempt_branches[@]} -eq 0 ]; then
33+
echo "...none found"
34+
return
35+
fi
36+
37+
for exempt_branch in "${exempt_branches[@]}"; do
38+
echo "...found exempt branch: $exempt_branch"
39+
done
40+
}
41+
42+
find_exempt_branches
43+
44+
function filter_feature_branches() {
45+
echo "Filtering branches"
46+
branches=()
47+
48+
for feature_branch in "${feature_branches[@]}"; do
49+
if ! [[ "${exempt_branches[*]}" =~ "$feature_branch" ]]; then
50+
echo "...including feature branch: $feature_branch"
51+
branches+=("$feature_branch")
52+
else
53+
echo "...excluding feature branch: $feature_branch"
54+
fi
55+
done
56+
}
57+
58+
filter_feature_branches
59+
60+
function merge_main() {
61+
echo "Merging main into branches"
62+
63+
if [ ${#branches[@]} -eq 0 ]; then
64+
echo "...no branches to merge into"
65+
return
66+
fi
67+
68+
for branch in "${branches[@]}"; do
69+
echo "...switching to branch: $branch"
70+
git switch "$branch"
71+
echo "...merging main"
72+
git merge -m "misc: merge from main" main
73+
if [ $? -eq 0 ]; then
74+
echo "...pushing to origin"
75+
git push origin "$branch"
76+
else
77+
echo "...merge failed"
78+
git merge --abort
79+
fi
80+
done
81+
}
82+
83+
merge_main

.github/workflows/merge-main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Merge main
2+
on:
3+
schedule:
4+
- cron: "0 7 * * 1-5" # At 07:00 UTC (00:00 PST, 03:00 EST), Monday through Friday
5+
workflow_dispatch:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Merge main
12+
uses: awslabs/aws-kotlin-repo-tools/.github/actions/merge-main@main
13+
with:
14+
exempt-branches: # Add any if required

0 commit comments

Comments
 (0)