codecov-upload.sh 55 KB

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