Skip to content

Commit f827460

Browse files
committed
fix: move auto-merge script to action
1 parent 555a8d3 commit f827460

File tree

3 files changed

+93
-85
lines changed

3 files changed

+93
-85
lines changed

.github/actions/merge-main/action.yml

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,84 @@ runs:
2121
- name: Run Script
2222
shell: bash
2323
run: |
24-
.github/scripts/merge-main.sh ${{ inputs.exempt-branches }}
24+
input=${{ inputs.exempt-branches }}
25+
26+
function fetch_latest_changes() {
27+
echo "Fetching the latest remote branches"
28+
git fetch --all
29+
}
30+
31+
fetch_latest_changes
32+
33+
function find_feature_branches() {
34+
echo "Searching for feature branches"
35+
feature_branches=($(git branch -r --list "*-main" | sed 's|origin/||'))
36+
37+
if [ ${#feature_branches[@]} -eq 0 ]; then
38+
echo "...none found"
39+
return
40+
fi
41+
42+
for feature_branch in "${feature_branches[@]}"; do
43+
echo "...found feature branch: $feature_branch"
44+
done
45+
}
46+
47+
find_feature_branches
48+
49+
function find_exempt_branches() {
50+
echo "Searching for exempt branches"
51+
IFS=',' read -r -a exempt_branches <<< "$input"
52+
53+
if [ ${#exempt_branches[@]} -eq 0 ]; then
54+
echo "...none found"
55+
return
56+
fi
57+
58+
for exempt_branch in "${exempt_branches[@]}"; do
59+
echo "...found exempt branch: $exempt_branch"
60+
done
61+
}
62+
63+
find_exempt_branches
64+
65+
function filter_feature_branches() {
66+
echo "Filtering branches"
67+
branches=()
68+
69+
for feature_branch in "${feature_branches[@]}"; do
70+
if ! [[ "${exempt_branches[*]}" =~ "$feature_branch" ]]; then
71+
echo "...including feature branch: $feature_branch"
72+
branches+=("$feature_branch")
73+
else
74+
echo "...excluding feature branch: $feature_branch"
75+
fi
76+
done
77+
}
78+
79+
filter_feature_branches
80+
81+
function merge_main() {
82+
echo "Merging main into branches"
83+
84+
if [ ${#branches[@]} -eq 0 ]; then
85+
echo "...no branches to merge into"
86+
return
87+
fi
88+
89+
for branch in "${branches[@]}"; do
90+
echo "...switching to branch: $branch"
91+
git switch "$branch"
92+
echo "...merging main"
93+
git merge -m "misc: merge from main" origin/main
94+
if [ $? -eq 0 ]; then
95+
echo "...pushing to origin"
96+
git push origin "$branch"
97+
else
98+
echo "...merge failed"
99+
git merge --abort
100+
fi
101+
done
102+
}
103+
104+
merge_main

.github/scripts/merge-main.sh

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

.github/workflows/merge-main.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ on:
33
schedule:
44
- cron: "0 7 * * 1-5" # At 07:00 UTC (00:00 PST, 03:00 EST), Monday through Friday
55
workflow_dispatch:
6+
# TODO: REMOVE v
7+
push:
8+
branches:
9+
- main
10+
- '*-main'
11+
pull_request:
12+
branches:
13+
- main
14+
- '*-main'
15+
# TODO: REMOVE ^
616

717
jobs:
818
test:
919
runs-on: ubuntu-latest
1020
steps:
1121
- name: Merge main
12-
uses: awslabs/aws-kotlin-repo-tools/.github/actions/merge-main@main
22+
uses: awslabs/aws-kotlin-repo-tools/.github/actions/merge-main@fix-auto-merge-workflow
23+
# TODO: Use main instead of feature branch ^
1324
with:
1425
exempt-branches: # Add any if required

0 commit comments

Comments
 (0)