Created
May 18, 2018 16:32
-
-
Save we4tech/1ced377edeb3375b56ff0d7e9f1cc9ff to your computer and use it in GitHub Desktop.
Git rebase reminder for CircleCI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rebase-reminder: | |
docker: | |
# specify the version you desire here | |
- image: circleci/ruby:2.4.1-node-browsers | |
environment: | |
RAILS_ENV: test | |
PGHOST: 127.0.0.1 | |
PGUSER: root | |
PUBLIC_HOST: https://example.org | |
working_directory: ~/repo | |
steps: | |
- checkout | |
- run: | |
name: Check if rebase is required | |
command: | | |
mkdir -p /tmp/test-results/rebase-status | |
PR_NUMBER=${CI_PULL_REQUEST//*pull\//} | |
CI_HEAD_BRANCH=${CI_HEAD_BRANCH-"master"} | |
err=0 | |
# Set git identity | |
git config user.email "[email protected]" | |
git config user.name "circleci" | |
if [ -z "$PR_NUMBER" ]; then | |
echo --> Not merging with master | |
exit | |
fi | |
# Update the CI_HEAD_BRANCH (ie. master/develop) | |
(set -x && git fetch -f origin $CI_HEAD_BRANCH) || err=$? | |
# Find current head from the HEAD_BRANCH | |
# Thanks to this: https://stackoverflow.com/questions/30177047/how-to-pragmatically-check-with-bash-script-if-a-branch-in-git-needs-to-be-rebas | |
hash1=$(git show-ref --heads -s $CI_HEAD_BRANCH) | |
hash2=$(git merge-base $CI_HEAD_BRANCH $CIRCLE_BRANCH) | |
if [[ "${hash1}" = "${hash2}" ]]; then | |
echo "OK: Already rebased" > /tmp/test-results/rebase-status/rebase-status.txt | |
else | |
echo "FAIL: Rebase is required" > /tmp/test-results/rebase-status/rebase-status.txt | |
exit 1 | |
fi | |
# collect reports | |
- store_test_results: | |
path: /tmp/test-results | |
- store_artifacts: | |
path: /tmp/test-results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment