diff --git a/.circleci/check-pr-branch.sh b/.circleci/check-pr-branch.sh new file mode 100755 index 0000000000..43d43d347a --- /dev/null +++ b/.circleci/check-pr-branch.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [[ "$CIRCLE_BRANCH" == "master" ]]; +then + echo "Skipping PR branch check for master branch" + exit 0 +fi + +echo "Checking PR branch is up to date with master branch" + +current_branch=$(git branch --show-current) +merge_base=$(git merge-base $current_branch master) +recommend_rebase="rebase your branch on the master branch." + +# checking if PR branch is up to date +if ! git diff -s --exit-code $current_branch...master ; then + echo "Branch ${current_branch} is not up-to-date with master. Please, ${recommend_rebase}" + exit 1 +fi + +# checking if there is no new merge commit +current_commit=$(git show-ref --heads -s $current_branch) +for commit in $(git log $current_commit...$merge_base --format="%h"); do + parent_count=$(git cat-file -p $commit | grep parent | wc -l) + if [ "${parent_count}" != 1 ]; then + commit_msg=$(git log $commit -1 --format="%s") + echo "Merge commits like ${commit} (${commit_msg}) are not allowed. Please ${recommend_rebase}" + exit 1 + fi +done diff --git a/.circleci/config.yml b/.circleci/config.yml index cfeadc8da8..0c1431ad47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,6 +48,9 @@ jobs: executor: node steps: - checkout + - run: + name: "Check if PR is up-to-date and there are no merge commits" + command: ./.circleci/check-pr-branch.sh - restore-yarn - install-dependencies - save-yarn @@ -305,7 +308,6 @@ workflows: - run_cypress_tests: requires: - setup - - verdaccio-test-approval: <<: *only_on_master_branch type: approval