Skip to content

Commit

Permalink
Fix skipping test on mergify merge commit using bash
Browse files Browse the repository at this point in the history
  • Loading branch information
foriequal0 authored and mergify[bot] committed Jan 24, 2019
1 parent 8c8456b commit 4e7edf5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ rust:
- 1.32.0
stages:
- name: test
# Skip a PR merge. We only merge a PR with up-to-date base branch.
# The HEAD of a master is identical the HEAD to the PR, so testing on master is redundant.
if: branch != docker-build AND NOT (branch = master AND sender = "mergify[bot]")
if: branch != docker-build
- name: deploy
if: branch = docker-build

Expand All @@ -15,6 +13,7 @@ jobs:
name: test-osx
os: osx
before_install:
- SKIP=`.travis/check-mergify-merge` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
- SKIP=`.travis/check-doc-change` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
install:
- rustup toolchain install nightly-2018-12-06
Expand All @@ -29,6 +28,7 @@ jobs:
- name: int-test-osx
os: osx
before_install:
- SKIP=`.travis/check-mergify-merge` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
- SKIP=`.travis/check-doc-change` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
install:
- nvm install 10
Expand All @@ -47,6 +47,7 @@ jobs:
os: linux
sudo: required
before_install:
- SKIP=`.travis/check-mergify-merge` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
- SKIP=`.travis/check-doc-change` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
install:
- rustup toolchain install nightly-2018-12-06
Expand All @@ -62,6 +63,7 @@ jobs:
os: linux
sudo: required
before_install:
- SKIP=`.travis/check-mergify-merge` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
- SKIP=`.travis/check-doc-change` && if [[ "$SKIP" = "skip" ]]; then travis_terminate 0; fi
install:
- nvm install 10
Expand Down
46 changes: 46 additions & 0 deletions .travis/check-mergify-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -e
# Everything that is normally printed to `stdout` in the script will be redirected to `stderr`
# which will be visible in tty/Travis log.
# Outputs that is printed to `fd 3` will be redirected to `stdout`,
# which will be finally assigned to a variable `$SKIP`
exec 3>&1 1>&2 # fd 3 = fd 1; fd 1 = fd 2

function return_to_travis {
STRATEGY="${1}"
echo ${STRATEGY} >&3
exit 0
}
function skip_travis { return_to_travis "skip" ; }
function noskip_travis { return_to_travis "noskip" ; }

echo "Event type ${TRAVIS_EVENT_TYPE}"
echo "Branch: ${TRAVIS_EVENT_TYPE}"
echo "Commit: ${TRAVIS_COMMIT}"

case ${TRAVIS_EVENT_TYPE} in
push)
if [[ "${TRAVIS_BRANCH}" = master ]]
then
echo "Push on master"
else
echo "Don't skip testing for other than master"
noskip_travis
fi
;;
*)
echo "Don't skip for PR, api, cron event"
noskip_travis
;;
esac

MERGIFY_COMMITTER="mergify[bot] <mergify[bot]@users.noreply.github.com>"
COMMITTER=`git show --format="%cN <%cE>" --no-patch "${TRAVIS_COMMIT}"`

if [[ "${COMMITTER}" = "${MERGIFY_COMMITTER}" ]]
then
echo "Skip check since it was checked in other PR"
skip_travis
else
noskip_travis
fi

0 comments on commit 4e7edf5

Please sign in to comment.