Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 5de0eef

Browse files
authored
Merge pull request #403 from codecov/use-ruby-formatter
Add upload only for bash uploader
2 parents 54b1a92 + 12198f1 commit 5de0eef

File tree

7 files changed

+168
-84
lines changed

7 files changed

+168
-84
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Extract shunit
1212
command: tar --strip-components=1 -zxvf tests/shunit2-2.1.8.tar.gz
1313
- run:
14-
name: Install bashcov and json
14+
name: Install Ruby dependencies
1515
command: |
1616
gem install json
1717
gem install simplecov
@@ -30,7 +30,7 @@ jobs:
3030
- run:
3131
name: Upload Codecov
3232
command: |
33-
bash <(curl -s https://codecov.io/bash) -s /home/circleci/project/coverage -Z
33+
bash ./codecov -s coverage -Z
3434
- store_artifacts:
3535
path: coverage
3636
deploy:

SHA1SUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
930c0975570559ee7ad02cebaa6e823c3d2795df codecov
1+
c03399a861d5dbcfc7ca3c5ce45eb4ee7d3b2225 codecov

SHA256SUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2ad0f9d8237901d5fb7718d82d833379ef03d406d5ec798272486ce8449285f3 codecov
1+
670815401d1cee718ba051a33cfd92e2a670906a682c800306d3f89f10cf1e42 codecov

SHA512SUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3517e4cb2d7c9674744a77270d46ff45d09a63e45da9ca0e640d6b0a437689af9da16a1382c1f9c9da0501709e7ba15d3a7ac8f518902ba75ab10709591cdb0f codecov
1+
d4281a64f2528b9365ce08f6d41477ffd3ef8886f18ace3dab20be468e88a6020c28a2bad12d6d2cc394e7e6ef035bafc2c1f24a3fbed2cbf1c415406bd60c44 codecov

codecov

Lines changed: 96 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ddp="$HOME/Library/Developer/Xcode/DerivedData"
2828
xp=""
2929
files=""
3030
save_to=""
31+
direct_file_upload=""
3132
cacert="$CODECOV_CA_BUNDLE"
3233
gcov_ignore="-not -path './bower_components/**' -not -path './node_modules/**' -not -path './vendor/**'"
3334
gcov_include=""
@@ -146,6 +147,9 @@ cat << EOF
146147
-F ui,chrome This upload is Chrome - UI tests
147148
148149
-c Move discovered coverage reports to the trash
150+
-z FILE Upload specified file directly to Codecov and bypass all report generation.
151+
This is inteded to be used only with a pre-formatted Codecov report and is not
152+
expected to work under any other circumstances.
149153
-Z Exit with 1 if not successful. Default will Exit with 0
150154
151155
-- xcode --
@@ -248,10 +252,9 @@ parse_yaml() {
248252
}'
249253
}
250254

251-
252255
if [ $# != 0 ];
253256
then
254-
while getopts "a:A:b:B:cC:dD:e:f:F:g:G:hJ:k:Kn:p:P:Q:q:r:R:s:S:t:T:u:U:vx:X:ZN:-" o
257+
while getopts "a:A:b:B:cC:dD:e:f:F:g:G:hJ:k:Kn:p:P:Q:q:r:R:s:S:t:T:u:U:vx:X:Zz:N:-" o
255258
do
256259
codecov_flags+=( "$o" )
257260
case "$o" in
@@ -451,6 +454,17 @@ $OPTARG"
451454
"Z")
452455
exit_with=1
453456
;;
457+
"z")
458+
direct_file_upload="$OPTARG"
459+
ft_gcov="0"
460+
ft_coveragepy="0"
461+
ft_fix="0"
462+
ft_search="0"
463+
ft_network="0"
464+
ft_xcodellvm="0"
465+
ft_gcovout="0"
466+
include_cov=""
467+
;;
454468
*)
455469
echo -e "${r}Unexpected flag not supported${x}"
456470
;;
@@ -471,16 +485,19 @@ say "
471485

472486
# check for installed tools
473487
# git/hg
474-
if [ -x "$(command -v git)" ];
488+
if [ "$direct_file_upload" = "" ];
475489
then
476-
say "$b==>$x $(git --version) found"
477-
else
478-
say "$y==>$x git not installed, testing for mercurial"
479-
if [ -x "$(command -v hg)" ];
490+
if [ -x "$(command -v git)" ];
480491
then
481-
say "$b==>$x $(hg --version) found"
492+
say "$b==>$x $(git --version) found"
482493
else
483-
say "$r==>$x git nor mercurial are installed. Uploader may fail or have unintended consequences"
494+
say "$y==>$x git not installed, testing for mercurial"
495+
if [ -x "$(command -v hg)" ];
496+
then
497+
say "$b==>$x $(hg --version) found"
498+
else
499+
say "$r==>$x git nor mercurial are installed. Uploader may fail or have unintended consequences"
500+
fi
484501
fi
485502
fi
486503
# curl
@@ -1373,6 +1390,9 @@ $PWD/coverage.xml"
13731390
elif [ "$include_cov" != "" ];
13741391
then
13751392
files=$(eval "find $search_in -type f \( ${include_cov:5} \)$exclude_cov 2>/dev/null" || echo '')
1393+
elif [ "$direct_file_upload" != "" ];
1394+
then
1395+
files=$direct_file_upload
13761396
fi
13771397

13781398
num_of_files=$(echo "$files" | wc -l | tr -d ' ')
@@ -1442,6 +1462,7 @@ cleanup() {
14421462

14431463
trap cleanup INT ABRT TERM
14441464

1465+
14451466
if [ "$env" != "" ];
14461467
then
14471468
inc_env=""
@@ -1455,13 +1476,16 @@ then
14551476
"
14561477
fi
14571478
done
1458-
1459-
echo "$inc_env<<<<<< ENV" >> "$upload_file"
1479+
echo "$inc_env<<<<<< ENV" >> "$upload_file"
14601480
fi
14611481

14621482
# Append git file list
14631483
# write discovered yaml location
1464-
echo "$yaml" >> "$upload_file"
1484+
if [ "$direct_file_upload" = "" ];
1485+
then
1486+
echo "$yaml" >> "$upload_file"
1487+
fi
1488+
14651489
if [ "$ft_network" == "1" ];
14661490
then
14671491
i="woff|eot|otf" # fonts
@@ -1473,70 +1497,78 @@ then
14731497
then
14741498
i="$i|html"
14751499
fi
1476-
14771500
echo "$network" | grep -vwE "($i)$" >> "$upload_file"
14781501
fi
14791502
echo "<<<<<< network" >> "$upload_file"
14801503

1481-
fr=0
1482-
say "${e}==>${x} Reading reports"
1483-
while IFS='' read -r file;
1484-
do
1485-
# read the coverage file
1486-
if [ "$(echo "$file" | tr -d ' ')" != '' ];
1487-
then
1488-
if [ -f "$file" ];
1504+
if [ "$direct_file_upload" = "" ];
1505+
then
1506+
fr=0
1507+
say "${e}==>${x} Reading reports"
1508+
while IFS='' read -r file;
1509+
do
1510+
# read the coverage file
1511+
if [ "$(echo "$file" | tr -d ' ')" != '' ];
14891512
then
1490-
report_len=$(wc -c < "$file")
1491-
if [ "$report_len" -ne 0 ];
1513+
if [ -f "$file" ];
14921514
then
1493-
say " ${g}+${x} $file ${e}bytes=$(echo "$report_len" | tr -d ' ')${x}"
1494-
# append to to upload
1495-
_filename=$(basename "$file")
1496-
if [ "${_filename##*.}" = 'gcov' ];
1515+
report_len=$(wc -c < "$file")
1516+
if [ "$report_len" -ne 0 ];
14971517
then
1498-
{
1499-
echo "# path=$(echo "$file.reduced" | sed "s|^$git_root/||")";
1500-
# get file name
1501-
head -1 "$file";
1502-
} >> "$upload_file"
1503-
# 1. remove source code
1504-
# 2. remove ending bracket lines
1505-
# 3. remove whitespace
1506-
# 4. remove contextual lines
1507-
# 5. remove function names
1508-
awk -F': *' '{print $1":"$2":"}' "$file" \
1509-
| sed '\/: *} *$/d' \
1510-
| sed 's/^ *//' \
1511-
| sed '/^-/d' \
1512-
| sed 's/^function.*/func/' >> "$upload_file"
1518+
say " ${g}+${x} $file ${e}bytes=$(echo "$report_len" | tr -d ' ')${x}"
1519+
# append to to upload
1520+
_filename=$(basename "$file")
1521+
if [ "${_filename##*.}" = 'gcov' ];
1522+
then
1523+
{
1524+
echo "# path=$(echo "$file.reduced" | sed "s|^$git_root/||")";
1525+
# get file name
1526+
head -1 "$file";
1527+
} >> "$upload_file"
1528+
# 1. remove source code
1529+
# 2. remove ending bracket lines
1530+
# 3. remove whitespace
1531+
# 4. remove contextual lines
1532+
# 5. remove function names
1533+
awk -F': *' '{print $1":"$2":"}' "$file" \
1534+
| sed '\/: *} *$/d' \
1535+
| sed 's/^ *//' \
1536+
| sed '/^-/d' \
1537+
| sed 's/^function.*/func/' >> "$upload_file"
1538+
else
1539+
{
1540+
echo "# path=${file//^$git_root/||}";
1541+
cat "$file";
1542+
} >> "$upload_file"
1543+
fi
1544+
echo "<<<<<< EOF" >> "$upload_file"
1545+
fr=1
1546+
if [ "$clean" = "1" ];
1547+
then
1548+
rm "$file"
1549+
fi
15131550
else
1514-
{
1515-
echo "# path=${file//^$git_root/||}";
1516-
cat "$file";
1517-
} >> "$upload_file"
1518-
fi
1519-
echo "<<<<<< EOF" >> "$upload_file"
1520-
fr=1
1521-
if [ "$clean" = "1" ];
1522-
then
1523-
rm "$file"
1551+
say " ${r}-${x} Skipping empty file $file"
15241552
fi
15251553
else
1526-
say " ${r}-${x} Skipping empty file $file"
1554+
say " ${r}-${x} file not found at $file"
15271555
fi
1528-
else
1529-
say " ${r}-${x} file not found at $file"
15301556
fi
1531-
fi
1532-
done <<< "$(echo -e "$files")"
1557+
done <<< "$(echo -e "$files")"
15331558

1534-
if [ "$fr" = "0" ];
1535-
then
1536-
say "${r}-->${x} No coverage data found."
1537-
say " Please visit ${b}http://docs.codecov.io/docs/supported-languages${x}"
1538-
say " search for your projects language to learn how to collect reports."
1539-
exit ${exit_with};
1559+
if [ "$fr" = "0" ];
1560+
then
1561+
say "${r}-->${x} No coverage data found."
1562+
say " Please visit ${b}http://docs.codecov.io/docs/supported-languages${x}"
1563+
say " search for your projects language to learn how to collect reports."
1564+
exit ${exit_with};
1565+
fi
1566+
else
1567+
cp "$direct_file_upload" "$upload_file"
1568+
if [ "$clean" = "1" ];
1569+
then
1570+
rm "$direct_file_upload"
1571+
fi
15401572
fi
15411573

15421574
if [ "$ft_fix" = "1" ];
@@ -1725,7 +1757,7 @@ else
17251757
if [ "$save_to" != "" ];
17261758
then
17271759
say "${e}==>${x} Copying upload file to ${save_to}"
1728-
mkdir --parents "$save_to"
1760+
mkdir -p "$(dirname "$save_to")"
17291761
cp "$upload_file" "$save_to"
17301762
fi
17311763

tests/reports/direct_report.json

Lines changed: 45 additions & 0 deletions
Large diffs are not rendered by default.

tests/test

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,28 @@ function test_token_env () {
212212
assertTrue 'Expected output differs.' $?
213213
}
214214

215-
# function test_upload () {
216-
# reset
217-
# export CI="true"
218-
# export TRAVIS_JOB_ID="33116958"
219-
# export TRAVIS="true"
220-
# export TRAVIS_BRANCH="master"
221-
# export TRAVIS_COMMIT="c739768fcac68144a3a6d82305b9c4106934d31a"
222-
# export TRAVIS_REPO_SLUG='codecov/ci-repo'
223-
# export TRAVIS_JOB_ID="33116958"
224-
# export TRAVIS_PULL_REQUEST="false"
225-
# export TRAVIS_JOB_NUMBER="4.1"
226-
# res=$(./codecov)
227-
# assertContains "$res" "Reports queued to"
228-
# assertContains "$res" "http://codecov.io/github/codecov/ci-repo?ref=c739768fcac68144a3a6d82305b9c4106934d31a"
229-
# }
215+
function test_upload () {
216+
reset
217+
export CI="true"
218+
export CIRCLECI="true"
219+
export VERSION=$VERSION
220+
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
221+
printenv
222+
res=$(./codecov -F test)
223+
assertContains "$res" "View reports at"
224+
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
225+
}
226+
227+
function test_direct_upload () {
228+
reset
229+
export CI="true"
230+
export CIRCLECI="true"
231+
export VERSION=$VERSION
232+
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
233+
res=$(./codecov -z "tests/reports/direct_report.json" -F test)
234+
assertContains "$res" "View reports at"
235+
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
236+
}
230237

231238
# -----------------
232239
# Test CI Companies

0 commit comments

Comments
 (0)