Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TMP-1717): Add PR validation check #4013

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 .circleci/check-pr-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

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
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ jobs:
paths:
- ./

check-pr-branch:
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

run_lint:
executor: node
steps:
Expand Down Expand Up @@ -285,27 +293,34 @@ workflows:
run_tests:
jobs:
- setup
- check-pr-branch:
<<: *only_on_pr_branch
- run_lint:
requires:
- setup
- check-pr-branch
jackbritchford marked this conversation as resolved.
Show resolved Hide resolved
- build_storybook:
requires:
- setup
- check-pr-branch
- run_noplatform_tests:
requires:
- setup
- check-pr-branch
- run_web_tests:
requires:
- setup
- check-pr-branch
- run_unit_tests:
requires:
- setup
- check-pr-branch
- sonarcloud_scan:
context: SonarCloud
- run_cypress_tests:
requires:
- setup

- check-pr-branch
- verdaccio-test-approval:
<<: *only_on_master_branch
type: approval
Expand Down