• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# This file is used for Linux builds.
4# It expects TASK environment variable is defined.
5# To run locally:
6#  ./buildscripts/kokoro/linux.sh
7
8# This script assumes `set -e`. Removing it may lead to undefined behavior.
9set -exu -o pipefail
10
11# It would be nicer to use 'readlink -f' here but osx does not support it.
12readonly OPENCENSUS_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)"
13
14# cd to the root dir of opencensus-java
15cd $(dirname $0)/../..
16
17valid_tasks() {
18  echo "Valid tasks are"
19  echo ""
20  echo "- BUILD"
21  echo "- BUILD_EXAMPLES_BAZEL"
22  echo "- BUILD_EXAMPLES_GRADLE"
23  echo "- BUILD_EXAMPLES_MAVEN"
24  echo "- CHECKER_FRAMEWORK"
25  echo "- CHECK_EXAMPLES_FORMAT"
26  echo "- CHECK_EXAMPLES_LICENSE"
27  echo "- CHECK_GIT_HISTORY"
28}
29
30if [[ ! -v TASK ]]; then
31  set +x
32  echo "TASK not set in environment"
33  valid_tasks
34  exit 1
35fi
36
37case "$TASK" in
38  "CHECK_GIT_HISTORY")
39    python ./scripts/check-git-history.py
40    ;;
41  "BUILD")
42    ./gradlew clean assemble --stacktrace
43    ./gradlew check :opencensus-all:jacocoTestReport
44    ./gradlew verGJF
45
46    # Run codecoverage reporting only if the script is running
47    # as a part of KOKORO BUILD. If it is outside of kokoro
48    # then there is no access to the codecov token and hence
49    # there is no point in running it.
50    if [[ -v KOKORO_BUILD_NUMBER ]]; then
51      # Get token from file located at
52      # $KOKORO_KEYSTORE_DIR/73495_codecov-auth-token
53      if [ -f $KOKORO_KEYSTORE_DIR/73495_codecov-auth-token ] ; then
54        curl -s https://codecov.io/bash | bash -s -- -Z -t @$KOKORO_KEYSTORE_DIR/73495_codecov-auth-token
55      else
56        echo "Codecov token file not found"
57        exit 1
58      fi
59    else
60      echo "Skipping codecov reporting"
61    fi
62    ;;
63  "CHECKER_FRAMEWORK")
64    ./gradlew clean assemble -PcheckerFramework=true
65    ;;
66  "CHECK_EXAMPLES_LICENSE")
67    curl -L -o checkstyle-8.12-all.jar https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.12/checkstyle-8.12-all.jar
68    java -DrootDir=. -jar checkstyle-8.12-all.jar -c buildscripts/checkstyle.xml examples/src/
69    ;;
70  "CHECK_EXAMPLES_FORMAT")
71    curl -L -o google-java-format-1.5-all-deps.jar \
72      https://github.com/google/google-java-format/releases/download/google-java-format-1.5/google-java-format-1.5-all-deps.jar
73    java -jar google-java-format-1.5-all-deps.jar --set-exit-if-changed --dry-run `find examples/src/ -name '*.java'`
74    ;;
75  "BUILD_EXAMPLES_GRADLE")
76    pushd examples && ./gradlew clean assemble --stacktrace && popd
77    ;;
78  "BUILD_EXAMPLES_MAVEN")
79    pushd examples && mvn clean package appassembler:assemble -e && popd
80    ;;
81  "BUILD_EXAMPLES_BAZEL")
82    pushd examples && bazel clean && bazel build :all && popd
83    ;;
84  *)
85    set +x
86    echo "Unknown task $TASK"
87    valid_tasks
88    exit 1
89    ;;
90esac
91