diff options
author | Stefan Schmidt <ubschmidt2@users.noreply.github.com> | 2017-10-31 03:54:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-31 03:54:25 +0100 |
commit | 4a03931492e791ad155d5ea0f4c97702a781b339 (patch) | |
tree | f42b18149bf1cd744c6c95235f07138a3023f0c5 /scripts | |
parent | b09a163af2a6406798fa5cdf73f94cd829a2ec9e (diff) | |
download | opencensus-java-4a03931492e791ad155d5ea0f4c97702a781b339.tar.gz |
Move the Travis "script" from .travis.yml to a separate file. (#747)
* Move the Travis "script" from .travis.yml to a separate file.
* Set -e -v.
* Replace "jdk_switcher use" as it would require sudo.
* Source jdk_switcher.sh on linux only.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/check-git-history.py | 42 | ||||
-rwxr-xr-x | scripts/travis_script | 54 |
2 files changed, 96 insertions, 0 deletions
diff --git a/scripts/check-git-history.py b/scripts/check-git-history.py new file mode 100644 index 00000000..1aba2ca2 --- /dev/null +++ b/scripts/check-git-history.py @@ -0,0 +1,42 @@ +import os +import sys +import traceback + +def main(argv): + # Only check the history if the build is running on a pull request. + if is_travis_pull_request(): + # This function assumes that HEAD^1 is the base branch and HEAD^2 is the + # pull request. + exit_if_pull_request_has_merge_commits() + print 'Checked pull request history: SUCCEEDED' + else: + print 'Skipped history check.' + +def is_travis_pull_request(): + '''Returns true if TRAVIS_PULL_REQUEST is set to indicate a pull request.''' + return os.environ['TRAVIS_PULL_REQUEST'] != 'false' + +def exit_if_pull_request_has_merge_commits(): + '''Exits with an error if any of the commits added by the pull request are + merge commits.''' + # Print the parents of each commit added by the pull request. + git_command = 'git log --format="%P" HEAD^1..HEAD^2' + for line in os.popen(git_command): + parents = line.split() + assert len(parents) >= 1, line + if len(parents) > 1: + print 'Pull request contains a merge commit:' + print_history() + print 'Checked pull request history: FAILED' + sys.exit(1) + +def print_history(): + os.system('git log HEAD^1 HEAD^2 -30 --graph --oneline --decorate') + +def read_process(command): + '''Runs a command and returns everything printed to stdout.''' + with os.popen(command, 'r') as fd: + return fd.read() + +if __name__ == '__main__': + main(sys.argv) diff --git a/scripts/travis_script b/scripts/travis_script new file mode 100755 index 00000000..74b50bf0 --- /dev/null +++ b/scripts/travis_script @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Travis build script, cf. +# https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps. + +set -o errexit +set -o xtrace + +case "$TASK" in + "CHECK_GIT_HISTORY") + python "$(dirname "$0")"/check-git-history.py + ;; + "BUILD") + case "$TRAVIS_OS_NAME" in + "linux") + source /opt/jdk_switcher/jdk_switcher.sh + export JAVA8_HOME="$(jdk_switcher home oraclejdk8)" + case "$TRAVIS_JDK_VERSION" in + "oraclejdk8") + export JAVA_HOMES="$(jdk_switcher home openjdk6)/jre:$(jdk_switcher home openjdk7)/jre:$(jdk_switcher home oraclejdk8)/jre:$(jdk_switcher home oraclejdk9)" + ./gradlew clean assemble --stacktrace + ./gradlew check :opencensus-all:jacocoTestReport + ;; + "openjdk7") + # "./gradlew classes testClasses" is a workaround for + # https://github.com/gradle/gradle/issues/2421. + # See https://github.com/gradle/gradle/issues/2421#issuecomment-319916874. + JAVA_HOME="$(jdk_switcher home openjdk8)" ./gradlew classes testClasses + ./gradlew clean assemble --stacktrace + ./gradlew check + ;; + *) + echo "Unknown JDK version $TRAVIS_JDK_VERSION" + exit 1 + ;; + esac + ;; + "osx") + # OS X is a separate case, because the JDK version is determined by the OS X image: + # https://docs.travis-ci.com/user/reference/osx/#JDK-and-OS-X + ./gradlew clean assemble --stacktrace + ./gradlew check + ;; + *) + echo "Unknown OS name $TRAVIS_OS_NAME" + exit 1 + ;; + esac + ;; + *) + echo "Unknown task $TASK" + exit 1 + ;; +esac |