diff --git a/.github/workflows/check_for_unmerged_splits.yml b/.github/workflows/check_for_unmerged_splits.yml new file mode 100644 index 0000000..bc73440 --- /dev/null +++ b/.github/workflows/check_for_unmerged_splits.yml @@ -0,0 +1,30 @@ +name: check for unmerged splits + +on: + pull_request: + branches: + - main + +jobs: + check-branch: + if: endsWith(github.head_ref, '/main') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - run: | + TOPIC_NAME=${GITHUB_HEAD_REF%/main} + readarray -t ALL < <(\ + git branch --format='%(refname:short)' -a \ + | grep "$TOPIC_NAME" + ) + readarray -t MERGED < <(\ + git branch --format='%(refname:short)' --merged \ + | grep "$TOPIC_NAME" + ) + if [ ${#MERGED[@]} -lt ${#ALL[@]} ] + then + echo "The following branches have not been merged:" + # credit [to](https://stackoverflow.com/a/2816152) + echo ${ALL[@]} ${MERGED[@]} | tr ' ' '\n' | sort | uniq -u + exit 1 + fi diff --git a/.github/workflows/merge_main_from_split.yml b/.github/workflows/merge_main_from_split.yml new file mode 100644 index 0000000..f1bfa41 --- /dev/null +++ b/.github/workflows/merge_main_from_split.yml @@ -0,0 +1,23 @@ +# credit [to](https://stackoverflow.com/a/78766052) +name: require merge from main split of split branch + +on: + pull_request: + branches: + - main + +jobs: + check-branch: + if: contains(github.head_ref, '/') + runs-on: ubuntu-latest + steps: + - name: Check split branch + run: | + if [[ ${GITHUB_HEAD_REF} != *\/main ]] + then + echo \ + "Pull request for a split branch must come from the main" \ + "split. Try creating a pull request from the branch with the" \ + "suffix \"/main\"" + exit 1 + fi