Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git rebase reminder for CircleCI
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 "circleci@wework.com"
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
You can’t perform that action at this time.