Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/actions/merge-main/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Merge Main
description: Merges main into feature branches (*-main)
inputs:
exempt-branches:
description: Feature branches that are exempt from receiving merges from main (comma separated, no blank space)

runs:
using: composite
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Git
shell: bash
run: |
git config user.name aws-sdk-kotlin-ci
git config user.email "[email protected]"

- name: Run Script
shell: bash
run: |
.github/scripts/merge-main.sh ${{ inputs.exempt-branches }}
83 changes: 83 additions & 0 deletions .github/scripts/merge-main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

input=$1

function fetch_latest_changes() {
echo "Fetching the latest remote branches"
git fetch --all
}

fetch_latest_changes

function find_feature_branches() {
echo "Searching for feature branches"
feature_branches=($(git branch -r --list "*-main" | sed 's|origin/||'))

if [ ${#feature_branches[@]} -eq 0 ]; then
echo "...none found"
return
fi

for feature_branch in "${feature_branches[@]}"; do
echo "...found feature branch: $feature_branch"
done
}

find_feature_branches

function find_exempt_branches() {
echo "Searching for exempt branches"
IFS=',' read -r -a exempt_branches <<< "$input"

if [ ${#exempt_branches[@]} -eq 0 ]; then
echo "...none found"
return
fi

for exempt_branch in "${exempt_branches[@]}"; do
echo "...found exempt branch: $exempt_branch"
done
}

find_exempt_branches

function filter_feature_branches() {
echo "Filtering branches"
branches=()

for feature_branch in "${feature_branches[@]}"; do
if ! [[ "${exempt_branches[*]}" =~ "$feature_branch" ]]; then
echo "...including feature branch: $feature_branch"
branches+=("$feature_branch")
else
echo "...excluding feature branch: $feature_branch"
fi
done
}

filter_feature_branches

function merge_main() {
echo "Merging main into branches"

if [ ${#branches[@]} -eq 0 ]; then
echo "...no branches to merge into"
return
fi

for branch in "${branches[@]}"; do
echo "...switching to branch: $branch"
git switch "$branch"
echo "...merging main"
git merge -m "misc: merge from main" main
if [ $? -eq 0 ]; then
echo "...pushing to origin"
git push origin "$branch"
else
echo "...merge failed"
git merge --abort
fi
done
}

merge_main
14 changes: 14 additions & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Merge main
on:
schedule:
- cron: "0 7 * * 1-5" # At 07:00 UTC (00:00 PST, 03:00 EST), Monday through Friday
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Configure Gradle
uses: awslabs/aws-kotlin-repo-tools/.github/actions/merge-main@main
with:
exempt-branches: # Add any if required