github.com/vipernet-xyz/tendermint-core@v0.32.0/.circleci/codecov.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Apache License Version 2.0, January 2004
     4  # https://github.com/codecov/codecov-bash/blob/master/LICENSE
     5  
     6  
     7  set -e +o pipefail
     8  
     9  VERSION="0b37652"
    10  
    11  url="https://codecov.io"
    12  env="$CODECOV_ENV"
    13  service=""
    14  token=""
    15  search_in=""
    16  flags=""
    17  exit_with=0
    18  curlargs=""
    19  curlawsargs=""
    20  dump="0"
    21  clean="0"
    22  curl_s="-s"
    23  name="$CODECOV_NAME"
    24  include_cov=""
    25  exclude_cov=""
    26  ddp="$(echo ~)/Library/Developer/Xcode/DerivedData"
    27  xp=""
    28  files=""
    29  cacert="$CODECOV_CA_BUNDLE"
    30  gcov_ignore="-not -path './bower_components/**' -not -path './node_modules/**' -not -path './vendor/**'"
    31  gcov_include=""
    32  
    33  ft_gcov="1"
    34  ft_coveragepy="1"
    35  ft_fix="1"
    36  ft_search="1"
    37  ft_s3="1"
    38  ft_network="1"
    39  ft_xcodellvm="1"
    40  ft_xcodeplist="0"
    41  
    42  _git_root=$(git rev-parse --show-toplevel 2>/dev/null || hg root 2>/dev/null || echo $PWD)
    43  git_root="$_git_root"
    44  codecov_yml=""
    45  remote_addr=""
    46  if [ "$git_root" = "$PWD" ];
    47  then
    48    git_root="."
    49  fi
    50  
    51  url_o=""
    52  pr_o=""
    53  build_o=""
    54  commit_o=""
    55  search_in_o=""
    56  tag_o=""
    57  branch_o=""
    58  slug_o=""
    59  prefix_o=""
    60  
    61  commit="$VCS_COMMIT_ID"
    62  branch="$VCS_BRANCH_NAME"
    63  pr="$VCS_PULL_REQUEST"
    64  slug="$VCS_SLUG"
    65  tag="$VCS_TAG"
    66  build_url="$CI_BUILD_URL"
    67  build="$CI_BUILD_ID"
    68  job="$CI_JOB_ID"
    69  
    70  beta_xcode_partials=""
    71  
    72  proj_root="$git_root"
    73  gcov_exe="gcov"
    74  gcov_arg=""
    75  
    76  b="\033[0;36m"
    77  g="\033[0;32m"
    78  r="\033[0;31m"
    79  e="\033[0;90m"
    80  x="\033[0m"
    81  
    82  show_help() {
    83  cat << EOF
    84  
    85                  Codecov Bash $VERSION
    86  
    87            Global report uploading tool for Codecov
    88         Documentation at https://docs.codecov.io/docs
    89      Contribute at https://github.com/codecov/codecov-bash
    90  
    91  
    92      -h          Display this help and exit
    93      -f FILE     Target file(s) to upload
    94  
    95                   -f "path/to/file"     only upload this file
    96                                         skips searching unless provided patterns below
    97  
    98                   -f '!*.bar'           ignore all files at pattern *.bar
    99                   -f '*.foo'            include all files at pattern *.foo
   100                   Must use single quotes.
   101                   This is non-exclusive, use -s "*.foo" to match specific paths.
   102  
   103      -s DIR       Directory to search for coverage reports.
   104                   Already searches project root and artifact folders.
   105      -t TOKEN     Set the private repository token
   106                   (option) set environment variable CODECOV_TOKEN=:uuid
   107  
   108                   -t @/path/to/token_file
   109                   -t uuid
   110  
   111      -n NAME      Custom defined name of the upload. Visible in Codecov UI
   112  
   113      -e ENV       Specify environment variables to be included with this build
   114                   Also accepting environment variables: CODECOV_ENV=VAR,VAR2
   115  
   116                   -e VAR,VAR2
   117  
   118      -X feature   Toggle functionalities
   119  
   120                   -X gcov          Disable gcov
   121                   -X coveragepy    Disable python coverage
   122                   -X fix           Disable report fixing
   123                   -X search        Disable searching for reports
   124                   -X xcode         Disable xcode processing
   125                   -X network       Disable uploading the file network
   126  
   127      -R root dir  Used when not in git/hg project to identify project root directory
   128      -y conf file Used to specify the location of the .codecov.yml config file
   129      -F flag      Flag the upload to group coverage metrics
   130  
   131                   -F unittests        This upload is only unittests
   132                   -F integration      This upload is only integration tests
   133                   -F ui,chrome        This upload is Chrome - UI tests
   134  
   135      -c           Move discovered coverage reports to the trash
   136      -Z           Exit with 1 if not successful. Default will Exit with 0
   137  
   138      -- xcode --
   139      -D           Custom Derived Data Path for Coverage.profdata and gcov processing
   140                   Default '~/Library/Developer/Xcode/DerivedData'
   141      -J           Specify packages to build coverage.
   142                   This can significantly reduces time to build coverage reports.
   143  
   144                   -J 'MyAppName'      Will match "MyAppName" and "MyAppNameTests"
   145                   -J '^ExampleApp$'   Will match only "ExampleApp" not "ExampleAppTests"
   146  
   147      -- gcov --
   148      -g GLOB      Paths to ignore during gcov gathering
   149      -G GLOB      Paths to include during gcov gathering
   150      -p dir       Project root directory
   151                   Also used when preparing gcov
   152      -k prefix    Prefix filepaths to help resolve path fixing: https://github.com/codecov/support/issues/472
   153      -x gcovexe   gcov executable to run. Defaults to 'gcov'
   154      -a gcovargs  extra arguments to pass to gcov
   155  
   156      -- Override CI Environment Variables --
   157         These variables are automatically detected by popular CI providers
   158  
   159      -B branch    Specify the branch name
   160      -C sha       Specify the commit sha
   161      -P pr        Specify the pull request number
   162      -b build     Specify the build number
   163      -T tag       Specify the git tag
   164  
   165      -- Enterprise --
   166      -u URL       Set the target url for Enterprise customers
   167                   Not required when retrieving the bash uploader from your CCE
   168                   (option) Set environment variable CODECOV_URL=https://my-hosted-codecov.com
   169      -r SLUG      owner/repo slug used instead of the private repo token in Enterprise
   170                   (option) set environment variable CODECOV_SLUG=:owner/:repo
   171                   (option) set in your codecov.yml "codecov.slug"
   172      -S PATH      File path to your cacert.pem file used to verify ssl with Codecov Enterprise (optional)
   173                   (option) Set environment variable: CODECOV_CA_BUNDLE="/path/to/ca.pem"
   174      -U curlargs  Extra curl arguments to communicate with Codecov. e.g., -U "--proxy http://http-proxy"
   175      -A curlargs  Extra curl arguments to communicate with AWS.
   176  
   177      -- Debugging --
   178      -d           Don't upload, but dump upload file to stdout
   179      -K           Remove color from the output
   180      -v           Verbose mode
   181  
   182  EOF
   183  }
   184  
   185  
   186  say() {
   187    echo -e "$1"
   188  }
   189  
   190  
   191  urlencode() {
   192    echo "$1" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" | cut -c 3- | sed -e 's/%0A//'
   193  }
   194  
   195  
   196  swiftcov() {
   197    _dir=$(dirname "$1" | sed 's/\(Build\).*/\1/g')
   198    for _type in app framework xctest
   199    do
   200      find "$_dir" -name "*.$_type" | while read f
   201      do
   202        _proj=${f##*/}
   203        _proj=${_proj%."$_type"}
   204        if [ "$2" = "" ] || [ "$(echo "$_proj" | grep -i "$2")" != "" ];
   205        then
   206          say "    $g+$x Building reports for $_proj $_type"
   207          dest=$([ -f "$f/$_proj" ] && echo "$f/$_proj" || echo "$f/Contents/MacOS/$_proj")
   208          _proj_name=$(echo "$_proj" | sed -e 's/[[:space:]]//g')
   209          xcrun llvm-cov show $beta_xcode_partials -instr-profile "$1" "$dest" > "$_proj_name.$_type.coverage.txt" \
   210           || say "    ${r}x>${x} llvm-cov failed to produce results for $dest"
   211        fi
   212      done
   213    done
   214  }
   215  
   216  
   217  # Credits to: https://gist.github.com/pkuczynski/8665367
   218  parse_yaml() {
   219     local prefix=$2
   220     local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
   221     sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
   222          -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
   223     awk -F$fs '{
   224        indent = length($1)/2;
   225        vname[indent] = $2;
   226        for (i in vname) {if (i > indent) {delete vname[i]}}
   227        if (length($3) > 0) {
   228           vn=""; if (indent > 0) {vn=(vn)(vname[0])("_")}
   229           printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
   230        }
   231     }'
   232  }
   233  
   234  
   235  if [ $# != 0 ];
   236  then
   237    while getopts "a:A:b:B:cC:dD:e:f:F:g:G:hJ:k:Kn:p:P:r:R:y:s:S:t:T:u:U:vx:X:Z" o
   238    do
   239      case "$o" in
   240        "a")
   241          gcov_arg=$OPTARG
   242          ;;
   243        "A")
   244          curlawsargs="$OPTARG"
   245          ;;
   246        "b")
   247          build_o="$OPTARG"
   248          ;;
   249        "B")
   250          branch_o="$OPTARG"
   251          ;;
   252        "c")
   253          clean="1"
   254          ;;
   255        "C")
   256          commit_o="$OPTARG"
   257          ;;
   258        "d")
   259          dump="1"
   260          ;;
   261        "D")
   262          ddp="$OPTARG"
   263          ;;
   264        "e")
   265          env="$env,$OPTARG"
   266          ;;
   267        "f")
   268          if [ "${OPTARG::1}" = "!" ];
   269          then
   270            exclude_cov="$exclude_cov -not -path '${OPTARG:1}'"
   271  
   272          elif [[ "$OPTARG" = *"*"* ]];
   273          then
   274            include_cov="$include_cov -or -name '$OPTARG'"
   275  
   276          else
   277            ft_search=0
   278            if [ "$files" = "" ];
   279            then
   280              files="$OPTARG"
   281            else
   282              files="$files
   283  $OPTARG"
   284            fi
   285          fi
   286          ;;
   287        "F")
   288          if [ "$flags" = "" ];
   289          then
   290            flags="$OPTARG"
   291          else
   292            flags="$flags,$OPTARG"
   293          fi
   294          ;;
   295        "g")
   296          gcov_ignore="$gcov_ignore -not -path '$OPTARG'"
   297          ;;
   298        "G")
   299          gcov_include="$gcov_include -path '$OPTARG'"
   300          ;;
   301        "h")
   302          show_help
   303          exit 0;
   304          ;;
   305        "J")
   306          ft_xcodellvm="1"
   307          ft_xcodeplist="0"
   308          if [ "$xp" = "" ];
   309          then
   310            xp="$OPTARG"
   311          else
   312            xp="$xp\|$OPTARG"
   313          fi
   314          ;;
   315        "k")
   316          prefix_o=$(echo "$OPTARG" | sed -e 's:^/*::' -e 's:/*$::')
   317          ;;
   318        "K")
   319          b=""
   320          g=""
   321          r=""
   322          e=""
   323          x=""
   324          ;;
   325        "n")
   326          name="$OPTARG"
   327          ;;
   328        "p")
   329          proj_root="$OPTARG"
   330          ;;
   331        "P")
   332          pr_o="$OPTARG"
   333          ;;
   334        "r")
   335          slug_o="$OPTARG"
   336          ;;
   337        "R")
   338          git_root="$OPTARG"
   339          ;;
   340        "s")
   341          if [ "$search_in_o" = "" ];
   342          then
   343            search_in_o="$OPTARG"
   344          else
   345            search_in_o="$search_in_o $OPTARG"
   346          fi
   347          ;;
   348        "S")
   349          cacert="--cacert \"$OPTARG\""
   350          ;;
   351        "t")
   352          if [ "${OPTARG::1}" = "@" ];
   353          then
   354            token=$(cat "${OPTARG:1}" | tr -d ' \n')
   355          else
   356            token="$OPTARG"
   357          fi
   358          ;;
   359        "T")
   360          tag_o="$OPTARG"
   361          ;;
   362        "u")
   363          url_o=$(echo "$OPTARG" | sed -e 's/\/$//')
   364          ;;
   365        "U")
   366          curlargs="$OPTARG"
   367          ;;
   368        "v")
   369          set -x
   370          curl_s=""
   371          ;;
   372        "x")
   373          gcov_exe=$OPTARG
   374          ;;
   375        "X")
   376          if [ "$OPTARG" = "gcov" ];
   377          then
   378            ft_gcov="0"
   379          elif [ "$OPTARG" = "coveragepy" ] || [ "$OPTARG" = "py" ];
   380          then
   381            ft_coveragepy="0"
   382          elif [ "$OPTARG" = "xcodellvm" ];
   383          then
   384            ft_xcodellvm="1"
   385            ft_xcodeplist="0"
   386          elif [ "$OPTARG" = "fix" ] || [ "$OPTARG" = "fixes" ];
   387          then
   388            ft_fix="0"
   389          elif [ "$OPTARG" = "xcode" ];
   390          then
   391            ft_xcodellvm="0"
   392            ft_xcodeplist="0"
   393          elif [ "$OPTARG" = "search" ];
   394          then
   395            ft_search="0"
   396          elif [ "$OPTARG" = "xcodepartials" ];
   397          then
   398            beta_xcode_partials="-use-color"
   399          elif [ "$OPTARG" = "network" ];
   400          then
   401            ft_network="0"
   402          elif [ "$OPTARG" = "s3" ];
   403          then
   404            ft_s3="0"
   405          fi
   406          ;;
   407        "y")
   408          codecov_yml="$OPTARG"
   409          ;;
   410        "Z")
   411          exit_with=1
   412          ;;
   413      esac
   414    done
   415  fi
   416  
   417  say "
   418    _____          _
   419   / ____|        | |
   420  | |     ___   __| | ___  ___ _____   __
   421  | |    / _ \\ / _\` |/ _ \\/ __/ _ \\ \\ / /
   422  | |___| (_) | (_| |  __/ (_| (_) \\ V /
   423   \\_____\\___/ \\__,_|\\___|\\___\\___/ \\_/
   424                                Bash-$VERSION
   425  
   426  "
   427  
   428  search_in="$proj_root"
   429  
   430  if [ "$JENKINS_URL" != "" ];
   431  then
   432    say "$e==>$x Jenkins CI detected."
   433    # https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
   434    # https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables
   435    service="jenkins"
   436  
   437    if [ "$ghprbSourceBranch" != "" ];
   438    then
   439       branch="$ghprbSourceBranch"
   440    elif [ "$GIT_BRANCH" != "" ];
   441    then
   442       branch="$GIT_BRANCH"
   443    elif [ "$BRANCH_NAME" != "" ];
   444    then
   445      branch="$BRANCH_NAME"
   446    fi
   447  
   448    if [ "$ghprbActualCommit" != "" ];
   449    then
   450      commit="$ghprbActualCommit"
   451    elif [ "$GIT_COMMIT" != "" ];
   452    then
   453      commit="$GIT_COMMIT"
   454    fi
   455  
   456    if [ "$ghprbPullId" != "" ];
   457    then
   458      pr="$ghprbPullId"
   459    elif [ "$CHANGE_ID" != "" ];
   460    then
   461      pr="$CHANGE_ID"
   462    fi
   463  
   464    build="$BUILD_NUMBER"
   465    build_url=$(urlencode "$BUILD_URL")
   466  
   467  elif [ "$CI" = "true" ] && [ "$TRAVIS" = "true" ] && [ "$SHIPPABLE" != "true" ];
   468  then
   469    say "$e==>$x Travis CI detected."
   470    # https://docs.travis-ci.com/user/environment-variables/
   471    service="travis"
   472    commit="${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT}"
   473    build="$TRAVIS_JOB_NUMBER"
   474    pr="$TRAVIS_PULL_REQUEST"
   475    job="$TRAVIS_JOB_ID"
   476    slug="$TRAVIS_REPO_SLUG"
   477    env="$env,TRAVIS_OS_NAME"
   478    tag="$TRAVIS_TAG"
   479    if [ "$TRAVIS_BRANCH" != "$TRAVIS_TAG" ];
   480    then
   481      branch="$TRAVIS_BRANCH"
   482    fi
   483  
   484    language=$(printenv | grep "TRAVIS_.*_VERSION" | head -1)
   485    if [ "$language" != "" ];
   486    then
   487      env="$env,${language%=*}"
   488    fi
   489  
   490  elif [ "$DOCKER_REPO" != "" ];
   491  then
   492    say "$e==>$x Docker detected."
   493    # https://docs.docker.com/docker-cloud/builds/advanced/
   494    service="docker"
   495    branch="$SOURCE_BRANCH"
   496    commit="$SOURCE_COMMIT"
   497    slug="$DOCKER_REPO"
   498    tag="$CACHE_TAG"
   499    env="$env,IMAGE_NAME"
   500  
   501  elif [ "$CI" = "true" ] && [ "$CI_NAME" = "codeship" ];
   502  then
   503    say "$e==>$x Codeship CI detected."
   504    # https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
   505    service="codeship"
   506    branch="$CI_BRANCH"
   507    build="$CI_BUILD_NUMBER"
   508    build_url=$(urlencode "$CI_BUILD_URL")
   509    commit="$CI_COMMIT_ID"
   510  
   511  elif [ ! -z "$CF_BUILD_URL" ] && [ ! -z "$CF_BUILD_ID" ];
   512  then
   513    say "$e==>$x Codefresh CI detected."
   514    # https://docs.codefresh.io/v1.0/docs/variables
   515    service="codefresh"
   516    branch="$CF_BRANCH"
   517    build="$CF_BUILD_ID"
   518    build_url=$(urlencode "$CF_BUILD_URL")
   519    commit="$CF_REVISION"
   520  
   521  elif [ "$TEAMCITY_VERSION" != "" ];
   522  then
   523    say "$e==>$x TeamCity CI detected."
   524    # https://confluence.jetbrains.com/display/TCD8/Predefined+Build+Parameters
   525    # https://confluence.jetbrains.com/plugins/servlet/mobile#content/view/74847298
   526    if [ "$TEAMCITY_BUILD_BRANCH" = '' ];
   527    then
   528      echo "    Teamcity does not automatically make build parameters available as environment variables."
   529      echo "    Add the following environment parameters to the build configuration"
   530      echo "    env.TEAMCITY_BUILD_BRANCH = %teamcity.build.branch%"
   531      echo "    env.TEAMCITY_BUILD_ID = %teamcity.build.id%"
   532      echo "    env.TEAMCITY_BUILD_URL = %teamcity.serverUrl%/viewLog.html?buildId=%teamcity.build.id%"
   533      echo "    env.TEAMCITY_BUILD_COMMIT = %system.build.vcs.number%"
   534      echo "    env.TEAMCITY_BUILD_REPOSITORY = %vcsroot.<YOUR TEAMCITY VCS NAME>.url%"
   535    fi
   536    service="teamcity"
   537    branch="$TEAMCITY_BUILD_BRANCH"
   538    build="$TEAMCITY_BUILD_ID"
   539    build_url=$(urlencode "$TEAMCITY_BUILD_URL")
   540    if [ "$TEAMCITY_BUILD_COMMIT" != "" ];
   541    then
   542      commit="$TEAMCITY_BUILD_COMMIT"
   543    else
   544      commit="$BUILD_VCS_NUMBER"
   545    fi
   546    remote_addr="$TEAMCITY_BUILD_REPOSITORY"
   547  
   548  elif [ "$CI" = "true" ] && [ "$CIRCLECI" = "true" ];
   549  then
   550    say "$e==>$x Circle CI detected."
   551    # https://circleci.com/docs/environment-variables
   552    service="circleci"
   553    branch="$CIRCLE_BRANCH"
   554    build="$CIRCLE_BUILD_NUM"
   555    job="$CIRCLE_NODE_INDEX"
   556    if [ "$CIRCLE_PROJECT_REPONAME" != "" ];
   557    then
   558      slug="$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
   559    else
   560      # git@github.com:owner/repo.git
   561      slug="${CIRCLE_REPOSITORY_URL##*:}"
   562      # owner/repo.git
   563      slug="${slug%%.git}"
   564    fi
   565    pr="$CIRCLE_PR_NUMBER"
   566    commit="$CIRCLE_SHA1"
   567    search_in="$search_in $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS"
   568  
   569  elif [ "$BUDDYBUILD_BRANCH" != "" ];
   570  then
   571    say "$e==>$x buddybuild detected"
   572    # http://docs.buddybuild.com/v6/docs/custom-prebuild-and-postbuild-steps
   573    service="buddybuild"
   574    branch="$BUDDYBUILD_BRANCH"
   575    build="$BUDDYBUILD_BUILD_NUMBER"
   576    build_url="https://dashboard.buddybuild.com/public/apps/$BUDDYBUILD_APP_ID/build/$BUDDYBUILD_BUILD_ID"
   577    # BUDDYBUILD_TRIGGERED_BY
   578    if [ "$ddp" = "$(echo ~)/Library/Developer/Xcode/DerivedData" ];
   579    then
   580      ddp="/private/tmp/sandbox/${BUDDYBUILD_APP_ID}/bbtest"
   581    fi
   582  
   583  elif [ "${bamboo_planRepository_revision}" != "" ];
   584  then
   585    say "$e==>$x Bamboo detected"
   586    # https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html#Bamboovariables-Build-specificvariables
   587    service="bamboo"
   588    commit="${bamboo_planRepository_revision}"
   589    branch="${bamboo_planRepository_branch}"
   590    build="${bamboo_buildNumber}"
   591    build_url="${bamboo_buildResultsUrl}"
   592    remote_addr="${bamboo_planRepository_repositoryUrl}"
   593  
   594  elif [ "$CI" = "true" ] && [ "$BITRISE_IO" = "true" ];
   595  then
   596    # http://devcenter.bitrise.io/faq/available-environment-variables/
   597    say "$e==>$x Bitrise CI detected."
   598    service="bitrise"
   599    branch="$BITRISE_GIT_BRANCH"
   600    build="$BITRISE_BUILD_NUMBER"
   601    build_url=$(urlencode "$BITRISE_BUILD_URL")
   602    pr="$BITRISE_PULL_REQUEST"
   603    if [ "$GIT_CLONE_COMMIT_HASH" != "" ];
   604    then
   605      commit="$GIT_CLONE_COMMIT_HASH"
   606    fi
   607  
   608  elif [ "$CI" = "true" ] && [ "$SEMAPHORE" = "true" ];
   609  then
   610    say "$e==>$x Semaphore CI detected."
   611    # https://semaphoreapp.com/docs/available-environment-variables.html
   612    service="semaphore"
   613    branch="$BRANCH_NAME"
   614    build="$SEMAPHORE_BUILD_NUMBER"
   615    job="$SEMAPHORE_CURRENT_THREAD"
   616    pr="$PULL_REQUEST_NUMBER"
   617    slug="$SEMAPHORE_REPO_SLUG"
   618    commit="$REVISION"
   619    env="$env,SEMAPHORE_TRIGGER_SOURCE"
   620  
   621  elif [ "$CI" = "true" ] && [ "$BUILDKITE" = "true" ];
   622  then
   623    say "$e==>$x Buildkite CI detected."
   624    # https://buildkite.com/docs/guides/environment-variables
   625    service="buildkite"
   626    branch="$BUILDKITE_BRANCH"
   627    build="$BUILDKITE_BUILD_NUMBER"
   628    job="$BUILDKITE_JOB_ID"
   629    build_url=$(urlencode "$BUILDKITE_BUILD_URL")
   630    slug="$BUILDKITE_PROJECT_SLUG"
   631    commit="$BUILDKITE_COMMIT"
   632    if [[ "$BUILDKITE_PULL_REQUEST" != "false" ]]; then
   633      pr="$BUILDKITE_PULL_REQUEST"
   634    fi
   635    tag="$BUILDKITE_TAG"
   636  
   637  elif [ "$CI" = "drone" ] || [ "$DRONE" = "true" ];
   638  then
   639    say "$e==>$x Drone CI detected."
   640    # http://docs.drone.io/env.html
   641    # drone commits are not full shas
   642    service="drone.io"
   643    branch="$DRONE_BRANCH"
   644    build="$DRONE_BUILD_NUMBER"
   645    build_url=$(urlencode "${DRONE_BUILD_LINK}")
   646    pr="$DRONE_PULL_REQUEST"
   647    job="$DRONE_JOB_NUMBER"
   648    tag="$DRONE_TAG"
   649  
   650  elif [ "$HEROKU_TEST_RUN_BRANCH" != "" ];
   651  then
   652    say "$e==>$x Heroku CI detected."
   653    # https://devcenter.heroku.com/articles/heroku-ci#environment-variables
   654    service="heroku"
   655    branch="$HEROKU_TEST_RUN_BRANCH"
   656    build="$HEROKU_TEST_RUN_ID"
   657  
   658  elif [ "$CI" = "True" ] && [ "$APPVEYOR" = "True" ];
   659  then
   660    say "$e==>$x Appveyor CI detected."
   661    # http://www.appveyor.com/docs/environment-variables
   662    service="appveyor"
   663    branch="$APPVEYOR_REPO_BRANCH"
   664    build=$(urlencode "$APPVEYOR_JOB_ID")
   665    pr="$APPVEYOR_PULL_REQUEST_NUMBER"
   666    job="$APPVEYOR_ACCOUNT_NAME%2F$APPVEYOR_PROJECT_SLUG%2F$APPVEYOR_BUILD_VERSION"
   667    slug="$APPVEYOR_REPO_NAME"
   668    commit="$APPVEYOR_REPO_COMMIT"
   669  
   670  elif [ "$CI" = "true" ] && [ "$WERCKER_GIT_BRANCH" != "" ];
   671  then
   672    say "$e==>$x Wercker CI detected."
   673    # http://devcenter.wercker.com/articles/steps/variables.html
   674    service="wercker"
   675    branch="$WERCKER_GIT_BRANCH"
   676    build="$WERCKER_MAIN_PIPELINE_STARTED"
   677    slug="$WERCKER_GIT_OWNER/$WERCKER_GIT_REPOSITORY"
   678    commit="$WERCKER_GIT_COMMIT"
   679  
   680  elif [ "$CI" = "true" ] && [ "$MAGNUM" = "true" ];
   681  then
   682    say "$e==>$x Magnum CI detected."
   683    # https://magnum-ci.com/docs/environment
   684    service="magnum"
   685    branch="$CI_BRANCH"
   686    build="$CI_BUILD_NUMBER"
   687    commit="$CI_COMMIT"
   688  
   689  elif [ "$SHIPPABLE" = "true" ];
   690  then
   691    say "$e==>$x Shippable CI detected."
   692    # http://docs.shippable.com/ci_configure/
   693    service="shippable"
   694    branch=$([ "$HEAD_BRANCH" != "" ] && echo "$HEAD_BRANCH" || echo "$BRANCH")
   695    build="$BUILD_NUMBER"
   696    build_url=$(urlencode "$BUILD_URL")
   697    pr="$PULL_REQUEST"
   698    slug="$REPO_FULL_NAME"
   699    commit="$COMMIT"
   700  
   701  elif [ "$TDDIUM" = "true" ];
   702  then
   703    say "Solano CI detected."
   704    # http://docs.solanolabs.com/Setup/tddium-set-environment-variables/
   705    service="solano"
   706    commit="$TDDIUM_CURRENT_COMMIT"
   707    branch="$TDDIUM_CURRENT_BRANCH"
   708    build="$TDDIUM_TID"
   709    pr="$TDDIUM_PR_ID"
   710  
   711  elif [ "$GREENHOUSE" = "true" ];
   712  then
   713    say "$e==>$x Greenhouse CI detected."
   714    # http://docs.greenhouseci.com/docs/environment-variables-files
   715    service="greenhouse"
   716    branch="$GREENHOUSE_BRANCH"
   717    build="$GREENHOUSE_BUILD_NUMBER"
   718    build_url=$(urlencode "$GREENHOUSE_BUILD_URL")
   719    pr="$GREENHOUSE_PULL_REQUEST"
   720    commit="$GREENHOUSE_COMMIT"
   721    search_in="$search_in $GREENHOUSE_EXPORT_DIR"
   722  
   723  elif [ "$GITLAB_CI" != "" ];
   724  then
   725    say "$e==>$x GitLab CI detected."
   726    # http://doc.gitlab.com/ce/ci/variables/README.html
   727    service="gitlab"
   728    branch="${CI_BUILD_REF_NAME:-$CI_COMMIT_REF_NAME}"
   729    build="${CI_BUILD_ID:-$CI_JOB_ID}"
   730    remote_addr="${CI_BUILD_REPO:-$CI_REPOSITORY_URL}"
   731    commit="${CI_BUILD_REF:-$CI_COMMIT_SHA}"
   732  
   733  else
   734    say "${r}x>${x} No CI provider detected."
   735    say "    Testing inside Docker? ${b}http://docs.codecov.io/docs/testing-with-docker${x}"
   736    say "    Testing with Tox? ${b}https://docs.codecov.io/docs/python#section-testing-with-tox${x}"
   737  
   738  fi
   739  
   740  say "    ${e}project root:${x} $git_root"
   741  
   742  # find branch, commit, repo from git command
   743  if [ "$GIT_BRANCH" != "" ];
   744  then
   745    branch="$GIT_BRANCH"
   746  
   747  elif [ "$branch" = "" ];
   748  then
   749    branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || hg branch 2>/dev/null || echo "")
   750    if [ "$branch" = "HEAD" ];
   751    then
   752      branch=""
   753    fi
   754  fi
   755  
   756  if [ "$commit_o" = "" ];
   757  then
   758    # merge commit -> actual commit
   759    mc=
   760    if [ -n "$pr" ] && [ "$pr" != false ];
   761    then
   762      mc=$(git show --no-patch --format="%P" 2>/dev/null || echo "")
   763    fi
   764    if [[ "$mc" =~ ^[a-z0-9]{40}[[:space:]][a-z0-9]{40}$ ]];
   765    then
   766      say "    Fixing merge commit SHA"
   767      commit=$(echo "$mc" | cut -d' ' -f2)
   768    elif [ "$GIT_COMMIT" != "" ];
   769    then
   770      commit="$GIT_COMMIT"
   771    elif [ "$commit" = "" ];
   772    then
   773      commit=$(git log -1 --format="%H" 2>/dev/null || hg id -i --debug 2>/dev/null | tr -d '+' || echo "")
   774    fi
   775  else
   776    commit="$commit_o"
   777  fi
   778  
   779  if [ "$CODECOV_TOKEN" != "" ] && [ "$token" = "" ];
   780  then
   781    say "${e}-->${x} token set from env"
   782    token="$CODECOV_TOKEN"
   783  fi
   784  
   785  if [ "$CODECOV_URL" != "" ] && [ "$url_o" = "" ];
   786  then
   787    say "${e}-->${x} url set from env"
   788    url_o=$(echo "$CODECOV_URL" | sed -e 's/\/$//')
   789  fi
   790  
   791  if [ "$CODECOV_SLUG" != "" ];
   792  then
   793    say "${e}-->${x} slug set from env"
   794    slug_o="$CODECOV_SLUG"
   795  
   796  elif [ "$slug" = "" ];
   797  then
   798    if [ "$remote_addr" = "" ];
   799    then
   800      remote_addr=$(git config --get remote.origin.url || hg paths default || echo '')
   801    fi
   802    if [ "$remote_addr" != "" ];
   803    then
   804      if echo "$remote_addr" | grep -q "//"; then
   805        # https
   806        slug=$(echo "$remote_addr" | cut -d / -f 4,5 | sed -e 's/\.git$//')
   807      else
   808        # ssh
   809        slug=$(echo "$remote_addr" | cut -d : -f 2 | sed -e 's/\.git$//')
   810      fi
   811    fi
   812    if [ "$slug" = "/" ];
   813    then
   814      slug=""
   815    fi
   816  fi
   817  
   818  yaml=$(test -n "$codecov_yml" && echo "$codecov_yml" \
   819         || cd "$git_root" && \
   820            git ls-files "*codecov.yml" "*codecov.yaml" 2>/dev/null \
   821         || hg locate "*codecov.yml" "*codecov.yaml" 2>/dev/null \
   822         || cd $proj_root && find . -type f -name '*codecov.y*ml' -depth 1 2>/dev/null \
   823         || echo '')
   824  yaml=$(echo "$yaml" | head -1)
   825  
   826  if [ "$yaml" != "" ];
   827  then
   828    say "    ${e}Yaml found at:${x} $yaml"
   829    config=$(parse_yaml "$git_root/$yaml" || echo '')
   830  
   831    # TODO validate the yaml here
   832  
   833    if [ "$(echo "$config" | grep 'codecov_token="')" != "" ] && [ "$token" = "" ];
   834    then
   835      say "${e}-->${x} token set from yaml"
   836      token="$(echo "$config" | grep 'codecov_token="' | sed -e 's/codecov_token="//' | sed -e 's/"\.*//')"
   837    fi
   838  
   839    if [ "$(echo "$config" | grep 'codecov_url="')" != "" ] && [ "$url_o" = "" ];
   840    then
   841      say "${e}-->${x} url set from yaml"
   842      url_o="$(echo "$config" | grep 'codecov_url="' | sed -e 's/codecov_url="//' | sed -e 's/"\.*//')"
   843    fi
   844  
   845    if [ "$(echo "$config" | grep 'codecov_slug="')" != "" ] && [ "$slug_o" = "" ];
   846    then
   847      say "${e}-->${x} slug set from yaml"
   848      slug_o="$(echo "$config" | grep 'codecov_slug="' | sed -e 's/codecov_slug="//' | sed -e 's/"\.*//')"
   849    fi
   850  else
   851    say "    ${g}Yaml not found, that's ok! Learn more at${x} ${b}http://docs.codecov.io/docs/codecov-yaml${x}"
   852  
   853  fi
   854  
   855  if [ "$branch_o" != "" ];
   856  then
   857    branch=$(urlencode "$branch_o")
   858  else
   859    branch=$(urlencode "$branch")
   860  fi
   861  
   862  query="branch=$branch\
   863         &commit=$commit\
   864         &build=$([ "$build_o" = "" ] && echo "$build" || echo "$build_o")\
   865         &build_url=$build_url\
   866         &name=$(urlencode "$name")\
   867         &tag=$([ "$tag_o" = "" ] && echo "$tag" || echo "$tag_o")\
   868         &slug=$([ "$slug_o" = "" ] && urlencode "$slug" || urlencode "$slug_o")\
   869         &service=$service\
   870         &flags=$flags\
   871         &pr=$([ "$pr_o" = "" ] && echo "${pr##\#}" || echo "${pr_o##\#}")\
   872         &job=$job"
   873  
   874  if [ "$ft_search" = "1" ];
   875  then
   876    # detect bower comoponents location
   877    bower_components="bower_components"
   878    bower_rc=$(cd "$git_root" && cat .bowerrc 2>/dev/null || echo "")
   879    if [ "$bower_rc" != "" ];
   880    then
   881      bower_components=$(echo "$bower_rc" | tr -d '\n' | grep '"directory"' | cut -d'"' -f4 | sed -e 's/\/$//')
   882      if [ "$bower_components" = "" ];
   883      then
   884        bower_components="bower_components"
   885      fi
   886    fi
   887  
   888    # Swift Coverage
   889    if [ "$ft_xcodellvm" = "1" ] && [ -d "$ddp" ];
   890    then
   891      say "${e}==>${x} Processing Xcode reports via llvm-cov"
   892      say "    DerivedData folder: $ddp"
   893      profdata_files=$(find "$ddp" -name '*.profdata' 2>/dev/null || echo '')
   894      if [ "$profdata_files" != "" ];
   895      then
   896        # xcode via profdata
   897        if [ "$xp" = "" ];
   898        then
   899          # xp=$(xcodebuild -showBuildSettings 2>/dev/null | grep -i "^\s*PRODUCT_NAME" | sed -e 's/.*= \(.*\)/\1/')
   900          # say " ${e}->${x} Speed up Xcode processing by adding ${e}-J '$xp'${x}"
   901          say "    ${g}hint${x} Speed up Swift processing by using use ${g}-J 'AppName'${x} (regexp accepted)"
   902          say "    ${g}hint${x} This will remove Pods/ from your report. Also ${b}https://docs.codecov.io/docs/ignoring-paths${x}"
   903        fi
   904        while read -r profdata;
   905        do
   906          if [ "$profdata" != "" ];
   907          then
   908            swiftcov "$profdata" "$xp"
   909          fi
   910        done <<< "$profdata_files"
   911      else
   912        say "    ${e}->${x} No Swift coverage found"
   913      fi
   914  
   915      # Obj-C Gcov Coverage
   916      if [ "$ft_gcov" = "1" ];
   917      then
   918        say "    ${e}->${x} Running $gcov_exe for Obj-C"
   919        bash -c "find $ddp -type f -name '*.gcda' $gcov_include $gcov_ignore -exec $gcov_exe -p $gcov_arg {} +" || true
   920      fi
   921    fi
   922  
   923    if [ "$ft_xcodeplist" = "1" ] && [ -d "$ddp" ];
   924    then
   925      say "${e}==>${x} Processing Xcode plists"
   926      plists_files=$(find "$ddp" -name '*.xccoverage' 2>/dev/null || echo '')
   927      if [ "$plists_files" != "" ];
   928      then
   929        while read -r plist;
   930        do
   931          if [ "$plist" != "" ];
   932          then
   933            say "    ${g}Found${x} plist file at $plist"
   934            plutil -convert xml1 -o "$(basename "$plist").plist" -- $plist
   935          fi
   936        done <<< "$plists_files"
   937      fi
   938    fi
   939  
   940    # Gcov Coverage
   941    if [ "$ft_gcov" = "1" ];
   942    then
   943      say "${e}==>${x} Running gcov in $proj_root ${e}(disable via -X gcov)${x}"
   944      bash -c "find $proj_root -type f -name '*.gcno' $gcov_include $gcov_ignore -exec $gcov_exe -pb $gcov_arg {} +" || true
   945    else
   946      say "${e}==>${x} gcov disabled"
   947    fi
   948  
   949    # Python Coverage
   950    if [ "$ft_coveragepy" = "1" ];
   951    then
   952      if [ ! -f coverage.xml ];
   953      then
   954        if which coverage >/dev/null 2>&1;
   955        then
   956          say "${e}==>${x} Python coveragepy exists ${e}disable via -X coveragepy${x}"
   957  
   958          dotcoverage=$(find "$git_root" -name '.coverage' -or -name '.coverage.*' | head -1 || echo '')
   959          if [ "$dotcoverage" != "" ];
   960          then
   961            cd "$(dirname "$dotcoverage")"
   962            if [ ! -f .coverage ];
   963            then
   964              say "    ${e}->${x} Running coverage combine"
   965              coverage combine -a
   966            fi
   967            say "    ${e}->${x} Running coverage xml"
   968            if [ "$(coverage xml -i)" != "No data to report." ];
   969            then
   970              files="$files
   971  $PWD/coverage.xml"
   972            else
   973              say "    ${r}No data to report.${x}"
   974            fi
   975            cd "$proj_root"
   976          else
   977            say "    ${r}No .coverage file found.${x}"
   978          fi
   979        else
   980          say "${e}==>${x} Python coveragepy not found"
   981        fi
   982      fi
   983    else
   984      say "${e}==>${x} Python coveragepy disabled"
   985    fi
   986  
   987    if [ "$search_in_o" != "" ];
   988    then
   989      # location override
   990      search_in="$search_in_o"
   991    fi
   992  
   993    say "$e==>$x Searching for coverage reports in:"
   994    for _path in $search_in
   995    do
   996      say "    ${g}+${x} $_path"
   997    done
   998  
   999    patterns="find $search_in \( \
  1000                          -name vendor \
  1001                          -or -name htmlcov \
  1002                          -or -name virtualenv \
  1003                          -or -name js/generated/coverage \
  1004                          -or -name .virtualenv \
  1005                          -or -name virtualenvs \
  1006                          -or -name .virtualenvs \
  1007                          -or -name .env \
  1008                          -or -name .envs \
  1009                          -or -name env \
  1010                          -or -name .yarn-cache \
  1011                          -or -name envs \
  1012                          -or -name .venv \
  1013                          -or -name .venvs \
  1014                          -or -name venv \
  1015                          -or -name venvs \
  1016                          -or -name .git \
  1017                          -or -name .hg \
  1018                          -or -name .tox \
  1019                          -or -name __pycache__ \
  1020                          -or -name '.egg-info*' \
  1021                          -or -name '$bower_components' \
  1022                          -or -name node_modules \
  1023                          -or -name 'conftest_*.c.gcov' \
  1024                      \) -prune -or \
  1025                      -type f \( -name '*coverage*.*' \
  1026                       -or -name 'nosetests.xml' \
  1027                       -or -name 'jacoco*.xml' \
  1028                       -or -name 'clover.xml' \
  1029                       -or -name 'report.xml' \
  1030                       -or -name '*.codecov.*' \
  1031                       -or -name 'codecov.*' \
  1032                       -or -name 'cobertura.xml' \
  1033                       -or -name 'excoveralls.json' \
  1034                       -or -name 'luacov.report.out' \
  1035                       -or -name 'coverage-final.json' \
  1036                       -or -name 'naxsi.info' \
  1037                       -or -name 'lcov.info' \
  1038                       -or -name 'lcov.dat' \
  1039                       -or -name '*.lcov' \
  1040                       -or -name '*.clover' \
  1041                       -or -name 'cover.out' \
  1042                       -or -name 'gcov.info' \
  1043                       -or -name '*.gcov' \
  1044                       -or -name '*.lst' \
  1045                       $include_cov \) \
  1046                      $exclude_cov \
  1047                      -not -name '*.profdata' \
  1048                      -not -name 'coverage-summary.json' \
  1049                      -not -name 'phpunit-code-coverage.xml' \
  1050                      -not -name '*/classycle/report.xml' \
  1051                      -not -name 'remapInstanbul.coverage*.json' \
  1052                      -not -name 'phpunit-coverage.xml' \
  1053                      -not -name '*codecov.yml' \
  1054                      -not -name '*.serialized' \
  1055                      -not -name '.coverage*' \
  1056                      -not -name '.*coveragerc' \
  1057                      -not -name '*.sh' \
  1058                      -not -name '*.bat' \
  1059                      -not -name '*.ps1' \
  1060                      -not -name '*.env' \
  1061                      -not -name '*.cmake' \
  1062                      -not -name '*.dox' \
  1063                      -not -name '*.ec' \
  1064                      -not -name '*.rst' \
  1065                      -not -name '*.h' \
  1066                      -not -name '*.scss' \
  1067                      -not -name '*.o' \
  1068                      -not -name '*.proto' \
  1069                      -not -name '*.sbt' \
  1070                      -not -name '*.xcoverage.*' \
  1071                      -not -name '*.gz' \
  1072                      -not -name '*.conf' \
  1073                      -not -name '*.p12' \
  1074                      -not -name '*.csv' \
  1075                      -not -name '*.rsp' \
  1076                      -not -name '*.m4' \
  1077                      -not -name '*.pem' \
  1078                      -not -name '*~' \
  1079                      -not -name '*.exe' \
  1080                      -not -name '*.am' \
  1081                      -not -name '*.template' \
  1082                      -not -name '*.cp' \
  1083                      -not -name '*.bw' \
  1084                      -not -name '*.crt' \
  1085                      -not -name '*.log' \
  1086                      -not -name '*.cmake' \
  1087                      -not -name '*.pth' \
  1088                      -not -name '*.in' \
  1089                      -not -name '*.jar*' \
  1090                      -not -name '*.pom*' \
  1091                      -not -name '*.png' \
  1092                      -not -name '*.jpg' \
  1093                      -not -name '*.sql' \
  1094                      -not -name '*.jpeg' \
  1095                      -not -name '*.svg' \
  1096                      -not -name '*.gif' \
  1097                      -not -name '*.csv' \
  1098                      -not -name '*.snapshot' \
  1099                      -not -name '*.mak*' \
  1100                      -not -name '*.bash' \
  1101                      -not -name '*.data' \
  1102                      -not -name '*.py' \
  1103                      -not -name '*.class' \
  1104                      -not -name '*.xcconfig' \
  1105                      -not -name '*.ec' \
  1106                      -not -name '*.coverage' \
  1107                      -not -name '*.pyc' \
  1108                      -not -name '*.cfg' \
  1109                      -not -name '*.egg' \
  1110                      -not -name '*.ru' \
  1111                      -not -name '*.css' \
  1112                      -not -name '*.less' \
  1113                      -not -name '*.pyo' \
  1114                      -not -name '*.whl' \
  1115                      -not -name '*.html' \
  1116                      -not -name '*.ftl' \
  1117                      -not -name '*.erb' \
  1118                      -not -name '*.rb' \
  1119                      -not -name '*.js' \
  1120                      -not -name '*.jade' \
  1121                      -not -name '*.db' \
  1122                      -not -name '*.md' \
  1123                      -not -name '*.cpp' \
  1124                      -not -name '*.gradle' \
  1125                      -not -name '*.tar.tz' \
  1126                      -not -name '*.scss' \
  1127                      -not -name 'include.lst' \
  1128                      -not -name 'fullLocaleNames.lst' \
  1129                      -not -name 'inputFiles.lst' \
  1130                      -not -name 'createdFiles.lst' \
  1131                      -not -name 'scoverage.measurements.*' \
  1132                      -not -name 'test_*_coverage.txt' \
  1133                      -not -name 'testrunner-coverage*' \
  1134                      -print 2>/dev/null"
  1135    files=$(eval "$patterns" || echo '')
  1136  
  1137  elif [ "$include_cov" != "" ];
  1138  then
  1139    files=$(eval "find $search_in -type f \( ${include_cov:5} \)$exclude_cov 2>/dev/null" || echo '')
  1140  fi
  1141  
  1142  num_of_files=$(echo "$files" | wc -l | tr -d ' ')
  1143  if [ "$num_of_files" != '' ] && [ "$files" != '' ];
  1144  then
  1145    say "    ${e}->${x} Found $num_of_files reports"
  1146  fi
  1147  
  1148  # no files found
  1149  if [ "$files" = "" ];
  1150  then
  1151    say "${r}-->${x} No coverage report found."
  1152    say "    Please visit ${b}http://docs.codecov.io/docs/supported-languages${x}"
  1153    exit ${exit_with};
  1154  fi
  1155  
  1156  if [ "$ft_network" == "1" ];
  1157  then
  1158    say "${e}==>${x} Detecting git/mercurial file structure"
  1159    network=$(cd "$git_root" && git ls-files 2>/dev/null || hg locate 2>/dev/null || echo "")
  1160    if [ "$network" = "" ];
  1161    then
  1162      network=$(find "$git_root" \( \
  1163                     -name virtualenv \
  1164                     -name .virtualenv \
  1165                     -name virtualenvs \
  1166                     -name .virtualenvs \
  1167                     -name '*.png' \
  1168                     -name '*.gif' \
  1169                     -name '*.jpg' \
  1170                     -name '*.jpeg' \
  1171                     -name '*.md' \
  1172                     -name .env \
  1173                     -name .envs \
  1174                     -name env \
  1175                     -name envs \
  1176                     -name .venv \
  1177                     -name .venvs \
  1178                     -name venv \
  1179                     -name venvs \
  1180                     -name .git \
  1181                     -name .egg-info \
  1182                     -name shunit2-2.1.6 \
  1183                     -name vendor \
  1184                     -name __pycache__ \
  1185                     -name node_modules \
  1186                     -path '*/$bower_components/*' \
  1187                     -path '*/target/delombok/*' \
  1188                     -path '*/build/lib/*' \
  1189                     -path '*/js/generated/coverage/*' \
  1190                      \) -prune -or \
  1191                      -type f -print 2>/dev/null || echo '')
  1192    fi
  1193  
  1194    if [ "$prefix_o" != "" ];
  1195    then
  1196        network=$(echo "$network" | awk "{print \"$prefix_o/\"\$0}")
  1197    fi
  1198  fi
  1199  
  1200  upload_file=`mktemp /tmp/codecov.XXXXXX`
  1201  adjustments_file=`mktemp /tmp/codecov.adjustments.XXXXXX`
  1202  
  1203  cleanup() {
  1204      rm -f $upload_file $adjustments_file $upload_file.gz
  1205  }
  1206  
  1207  trap cleanup INT ABRT TERM
  1208  
  1209  if [ "$env" != "" ];
  1210  then
  1211    inc_env=""
  1212    say "${e}==>${x} Appending build variables"
  1213    for varname in $(echo "$env" | tr ',' ' ')
  1214    do
  1215      if [ "$varname" != "" ];
  1216      then
  1217        say "    ${g}+${x} $varname"
  1218        inc_env="${inc_env}${varname}=$(eval echo "\$${varname}")
  1219  "
  1220      fi
  1221    done
  1222  
  1223  echo "$inc_env<<<<<< ENV" >> $upload_file
  1224  fi
  1225  
  1226  # Append git file list
  1227  # write discovered yaml location
  1228  echo "$yaml" >> $upload_file
  1229  if [ "$ft_network" == "1" ];
  1230  then
  1231    i="woff|eot|otf"  # fonts
  1232    i="$i|gif|png|jpg|jpeg|psd"  # images
  1233    i="$i|ptt|pptx|numbers|pages|md|txt|xlsx|docx|doc|pdf|html|csv"  # docs
  1234    i="$i|yml|yaml|.gitignore"  # supporting docs
  1235    echo "$network" | grep -vwE "($i)$" >> $upload_file
  1236  fi
  1237  echo "<<<<<< network" >> $upload_file
  1238  
  1239  fr=0
  1240  say "${e}==>${x} Reading reports"
  1241  while IFS='' read -r file;
  1242  do
  1243    # read the coverage file
  1244    if [ "$(echo "$file" | tr -d ' ')" != '' ];
  1245    then
  1246      if [ -f "$file" ];
  1247      then
  1248        report_len=$(wc -c < "$file")
  1249        if [ "$report_len" -ne 0 ];
  1250        then
  1251          say "    ${g}+${x} $file ${e}bytes=$(echo "$report_len" | tr -d ' ')${x}"
  1252          # append to to upload
  1253          _filename=$(basename "$file")
  1254          if [ "${_filename##*.}" = 'gcov' ];
  1255          then
  1256            echo "# path=$(echo "$file.reduced" | sed "s|^$git_root/||")" >> $upload_file
  1257            # get file name
  1258            head -1 $file >> $upload_file
  1259            # 1. remove source code
  1260            # 2. remove ending bracket lines
  1261            # 3. remove whitespace
  1262            # 4. remove contextual lines
  1263            # 5. remove function names
  1264            awk -F': *' '{print $1":"$2":"}' $file \
  1265              | sed '\/: *} *$/d' \
  1266              | sed 's/^ *//' \
  1267              | sed '/^-/d' \
  1268              | sed 's/^function.*/func/' >> $upload_file
  1269          else
  1270            echo "# path=$(echo "$file" | sed "s|^$git_root/||")" >> $upload_file
  1271            cat "$file" >> $upload_file
  1272          fi
  1273          echo "<<<<<< EOF" >> $upload_file
  1274          fr=1
  1275          if [ "$clean" = "1" ];
  1276          then
  1277            rm "$file"
  1278          fi
  1279        else
  1280          say "    ${r}-${x} Skipping empty file $file"
  1281        fi
  1282      else
  1283        say "    ${r}-${x} file not found at $file"
  1284      fi
  1285    fi
  1286  done <<< "$(echo -e "$files")"
  1287  
  1288  if [ "$fr" = "0" ];
  1289  then
  1290    say "${r}-->${x} No coverage data found."
  1291    say "    Please visit ${b}http://docs.codecov.io/docs/supported-languages${x}"
  1292    say "    search for your projects language to learn how to collect reports."
  1293    exit ${exit_with};
  1294  fi
  1295  
  1296  if [ "$ft_fix" = "1" ];
  1297  then
  1298    say "${e}==>${x} Appending adjustments"
  1299    say "    ${b}http://docs.codecov.io/docs/fixing-reports${x}"
  1300  
  1301    empty_line='^[[:space:]]*$'
  1302    # //
  1303    syntax_comment='^[[:space:]]*//.*'
  1304    # /* or */
  1305    syntax_comment_block='^[[:space:]]*(\/\*|\*\/)[[:space:]]*$'
  1306    # { or }
  1307    syntax_bracket='^[[:space:]]*[\{\}][[:space:]]*(//.*)?$'
  1308    # [ or ]
  1309    syntax_list='^[[:space:]]*[][][[:space:]]*(//.*)?$'
  1310  
  1311    skip_dirs="-not -path '*/$bower_components/*' \
  1312               -not -path '*/node_modules/*'"
  1313  
  1314    cut_and_join() {
  1315      awk 'BEGIN { FS=":" }
  1316           $3 ~ /\/\*/ || $3 ~ /\*\// { print $0 ; next }
  1317           $1!=key { if (key!="") print out ; key=$1 ; out=$1":"$2 ; next }
  1318           { out=out","$2 }
  1319           END { print out }' 2>/dev/null
  1320    }
  1321  
  1322    if echo "$network" | grep -m1 '.kt$' 1>/dev/null;
  1323    then
  1324      # skip brackets and comments
  1325      find "$git_root" -type f \
  1326                       -name '*.kt' \
  1327                       -exec \
  1328        grep -nIHE -e $syntax_bracket \
  1329                   -e $syntax_comment_block {} \; \
  1330        | cut_and_join \
  1331        >> $adjustments_file \
  1332        || echo ''
  1333  
  1334      # last line in file
  1335      find "$git_root" -type f \
  1336                       -name '*.kt' -exec \
  1337        wc -l {} \; \
  1338        | while read l; do echo "EOF: $l"; done \
  1339        2>/dev/null \
  1340        >> $adjustments_file \
  1341        || echo ''
  1342  
  1343    fi
  1344  
  1345    if echo "$network" | grep -m1 '.go$' 1>/dev/null;
  1346    then
  1347      # skip empty lines, comments, and brackets
  1348      find "$git_root" -not -path '*/vendor/*' \
  1349                       -type f \
  1350                       -name '*.go' \
  1351                       -exec \
  1352        grep -nIHE \
  1353             -e $empty_line \
  1354             -e $syntax_comment \
  1355             -e $syntax_comment_block \
  1356             -e $syntax_bracket \
  1357             {} \; \
  1358        | cut_and_join \
  1359        >> $adjustments_file \
  1360        || echo ''
  1361    fi
  1362  
  1363    if echo "$network" | grep -m1 '.dart$' 1>/dev/null;
  1364    then
  1365      # skip brackets
  1366      find "$git_root" -type f \
  1367                       -name '*.dart' \
  1368                       -exec \
  1369        grep -nIHE \
  1370             -e $syntax_bracket \
  1371             {} \; \
  1372        | cut_and_join \
  1373        >> $adjustments_file \
  1374        || echo ''
  1375    fi
  1376  
  1377    if echo "$network" | grep -m1 '.php$' 1>/dev/null;
  1378    then
  1379      # skip empty lines, comments, and brackets
  1380      find "$git_root" -not -path "*/vendor/*" \
  1381                       -type f \
  1382                       -name '*.php' \
  1383                       -exec \
  1384        grep -nIHE \
  1385             -e $syntax_list \
  1386             -e $syntax_bracket \
  1387             -e '^[[:space:]]*\);[[:space:]]*(//.*)?$' \
  1388             {} \; \
  1389        | cut_and_join \
  1390        >> $adjustments_file \
  1391        || echo ''
  1392    fi
  1393  
  1394    if echo "$network" | grep -m1 '\(.cpp\|.h\|.cxx\|.c\|.hpp\|.m\)$' 1>/dev/null;
  1395    then
  1396      # skip brackets
  1397      find "$git_root" -type f \
  1398                       $skip_dirs \
  1399           \( \
  1400             -name '*.h' \
  1401             -or -name '*.cpp' \
  1402             -or -name '*.cxx' \
  1403             -or -name '*.m' \
  1404             -or -name '*.c' \
  1405             -or -name '*.hpp' \
  1406           \) -exec \
  1407        grep -nIHE \
  1408             -e $empty_line \
  1409             -e $syntax_bracket \
  1410             -e '// LCOV_EXCL' \
  1411             {} \; \
  1412        | cut_and_join \
  1413        >> $adjustments_file \
  1414        || echo ''
  1415  
  1416      # skip brackets
  1417      find "$git_root" -type f \
  1418                       $skip_dirs \
  1419           \( \
  1420             -name '*.h' \
  1421             -or -name '*.cpp' \
  1422             -or -name '*.cxx' \
  1423             -or -name '*.m' \
  1424             -or -name '*.c' \
  1425             -or -name '*.hpp' \
  1426           \) -exec \
  1427        grep -nIH '// LCOV_EXCL' \
  1428             {} \; \
  1429        >> $adjustments_file \
  1430        || echo ''
  1431  
  1432    fi
  1433  
  1434    found=$(cat $adjustments_file | tr -d ' ')
  1435  
  1436    if [ "$found" != "" ];
  1437    then
  1438      say "    ${g}+${x} Found adjustments"
  1439      echo "# path=fixes" >> $upload_file
  1440      cat $adjustments_file >> $upload_file
  1441      echo "<<<<<< EOF" >> $upload_file
  1442      rm -rf $adjustments_file
  1443    else
  1444      say "    ${e}->${x} No adjustments found"
  1445    fi
  1446  fi
  1447  
  1448  if [ "$url_o" != "" ];
  1449  then
  1450    url="$url_o"
  1451  fi
  1452  
  1453  if [ "$dump" != "0" ];
  1454  then
  1455    # trim whitespace from query
  1456    say "    ${e}->${x} Dumping upload file (no upload)"
  1457    echo "$url/upload/v4?$(echo "package=bash-$VERSION&token=$token&$query" | tr -d ' ')"
  1458    cat $upload_file
  1459  else
  1460  
  1461    say "${e}==>${x} Gzipping contents"
  1462    gzip -nf9 $upload_file
  1463  
  1464    query=$(echo "${query}" | tr -d ' ')
  1465    say "${e}==>${x} Uploading reports"
  1466    say "    ${e}url:${x} $url"
  1467    say "    ${e}query:${x} $query"
  1468  
  1469    # now add token to query
  1470    query=$(echo "package=bash-$VERSION&token=$token&$query" | tr -d ' ')
  1471  
  1472    if [ "$ft_s3" = "1" ];
  1473    then
  1474      i="0"
  1475      while [ $i -lt 4 ]
  1476      do
  1477        i=$[$i+1]
  1478        say "    ${e}->${x} Pinging Codecov"
  1479        res=$(curl $curl_s -X POST $curlargs $cacert \
  1480              -H 'X-Reduced-Redundancy: false' \
  1481              -H 'X-Content-Type: application/x-gzip' \
  1482              "$url/upload/v4?$query" || true)
  1483        # a good replay is "https://codecov.io" + "\n" + "https://codecov.s3.amazonaws.com/..."
  1484        status=$(echo "$res" | head -1 | grep 'HTTP ' | cut -d' ' -f2)
  1485        if [ "$status" = "" ];
  1486        then
  1487          s3target=$(echo "$res" | sed -n 2p)
  1488          say "    ${e}->${x} Uploading"
  1489          s3=$(curl $curl_s -fiX PUT $curlawsargs \
  1490                    --data-binary @$upload_file.gz \
  1491                    -H 'Content-Type: application/x-gzip' \
  1492                    -H 'Content-Encoding: gzip' \
  1493                    -H 'x-amz-acl: public-read' \
  1494                    "$s3target" || true)
  1495          if [ "$s3" != "" ];
  1496          then
  1497            say "    ${g}->${x} View reports at ${b}$(echo "$res" | sed -n 1p)${x}"
  1498            exit 0
  1499          else
  1500            say "    ${r}X>${x} Failed to upload"
  1501          fi
  1502        elif [ "$status" = "400" ];
  1503        then
  1504            # 400 Error
  1505            say "${g}${res}${x}"
  1506            exit ${exit_with}
  1507        fi
  1508        say "    ${e}->${x} Sleeping for 30s and trying again..."
  1509        sleep 30
  1510      done
  1511    fi
  1512  
  1513    say "    ${e}->${x} Uploading to Codecov"
  1514    i="0"
  1515    while [ $i -lt 4 ]
  1516    do
  1517      i=$[$i+1]
  1518  
  1519      res=$(curl $curl_s -X POST $curlargs $cacert \
  1520            --data-binary @$upload_file.gz \
  1521            -H 'Content-Type: text/plain' \
  1522            -H 'Content-Encoding: gzip' \
  1523            -H 'X-Content-Encoding: gzip' \
  1524            -H 'Accept: text/plain' \
  1525            "$url/upload/v2?$query" || echo 'HTTP 500')
  1526      # HTTP 200
  1527      # http://....
  1528      status=$(echo "$res" | head -1 | cut -d' ' -f2)
  1529      if [ "$status" = "" ];
  1530      then
  1531        say "    View reports at ${b}$(echo "$res" | head -2 | tail -1)${x}"
  1532        exit 0
  1533  
  1534      elif [ "${status:0:1}" = "5" ];
  1535      then
  1536        say "    ${e}->${x} Sleeping for 30s and trying again..."
  1537        sleep 30
  1538  
  1539      else
  1540        say "    ${g}${res}${x}"
  1541        exit 0
  1542        exit ${exit_with}
  1543      fi
  1544  
  1545    done
  1546  
  1547    say "    ${r}X> Failed to upload coverage reports${x}"
  1548  fi
  1549  
  1550  exit ${exit_with}