Skip to content

Commit

Permalink
feat(TMP-1717): Add PR validation check (#4013)
Browse files Browse the repository at this point in the history
* added check-pr-branch to circleci yaml

* added check-pr-branch.sh

* fixed executor to node

* updated logic of CircleCI PR branch check

* removed 20-30s unnecessary checkout

* replaced job with inline command run

* changed order of check PR

* removed unintended newline on cci yaml file
  • Loading branch information
jackbritchford authored Jan 7, 2025
1 parent 17e8a41 commit aef6c61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .circleci/check-pr-branch.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -305,7 +308,6 @@ workflows:
- run_cypress_tests:
requires:
- setup

- verdaccio-test-approval:
<<: *only_on_master_branch
type: approval
Expand Down

0 comments on commit aef6c61

Please sign in to comment.