You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1550 lines
45 KiB

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