xref: /aosp_15_r20/external/opencensus-java/buildscripts/kokoro/linux_presubmit.sh (revision a24ffb47c3166327784aa05b149974e82e8f71b8)
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_GRADLE"
22  echo "- BUILD_EXAMPLES_MAVEN"
23  echo "- CHECKER_FRAMEWORK"
24  echo "- CHECK_GIT_HISTORY"
25}
26
27if [[ ! -v TASK ]]; then
28  set +x
29  echo "TASK not set in environment"
30  valid_tasks
31  exit 1
32fi
33
34case "$TASK" in
35  "CHECK_GIT_HISTORY")
36    python ./buildscripts/check-git-history.py
37    ;;
38  "BUILD")
39    ./gradlew clean assemble --stacktrace
40    ./gradlew check :opencensus-all:jacocoTestReport
41    ./gradlew verGJF
42
43    # Run codecoverage reporting only if the script is running
44    # as a part of KOKORO BUILD. If it is outside of kokoro
45    # then there is no access to the codecov token and hence
46    # there is no point in running it.
47    if [[ -v KOKORO_BUILD_NUMBER ]]; then
48      # Get token from file located at
49      # $KOKORO_KEYSTORE_DIR/73495_codecov-auth-token
50      if [ -f $KOKORO_KEYSTORE_DIR/73495_codecov-auth-token ] ; then
51        curl -s https://codecov.io/bash | bash -s -- -Z -t @$KOKORO_KEYSTORE_DIR/73495_codecov-auth-token
52      else
53        echo "Codecov token file not found"
54        exit 1
55      fi
56    else
57      echo "Skipping codecov reporting"
58    fi
59    ;;
60  "CHECKER_FRAMEWORK")
61    ./gradlew clean assemble -PcheckerFramework=true
62    ;;
63  "BUILD_EXAMPLES_GRADLE")
64    pushd examples && ./gradlew clean assemble --stacktrace && ./gradlew check && ./gradlew verGJF && popd
65    ;;
66  "BUILD_EXAMPLES_MAVEN")
67    pushd examples && mvn clean package appassembler:assemble -e && popd
68    ;;
69  *)
70    set +x
71    echo "Unknown task $TASK"
72    valid_tasks
73    exit 1
74    ;;
75esac
76