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

Commit

Permalink
Merge pull request #403 from codecov/use-ruby-formatter
Browse files Browse the repository at this point in the history
Add upload only for bash uploader
  • Loading branch information
thomasrockhu authored Jan 27, 2021
2 parents 54b1a92 + 12198f1 commit 5de0eef
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Extract shunit
command: tar --strip-components=1 -zxvf tests/shunit2-2.1.8.tar.gz
- run:
name: Install bashcov and json
name: Install Ruby dependencies
command: |
gem install json
gem install simplecov
Expand All @@ -30,7 +30,7 @@ jobs:
- run:
name: Upload Codecov
command: |
bash <(curl -s https://codecov.io/bash) -s /home/circleci/project/coverage -Z
bash ./codecov -s coverage -Z
- store_artifacts:
path: coverage
deploy:
Expand Down
2 changes: 1 addition & 1 deletion SHA1SUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
930c0975570559ee7ad02cebaa6e823c3d2795df codecov
c03399a861d5dbcfc7ca3c5ce45eb4ee7d3b2225 codecov
2 changes: 1 addition & 1 deletion SHA256SUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2ad0f9d8237901d5fb7718d82d833379ef03d406d5ec798272486ce8449285f3 codecov
670815401d1cee718ba051a33cfd92e2a670906a682c800306d3f89f10cf1e42 codecov
2 changes: 1 addition & 1 deletion SHA512SUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3517e4cb2d7c9674744a77270d46ff45d09a63e45da9ca0e640d6b0a437689af9da16a1382c1f9c9da0501709e7ba15d3a7ac8f518902ba75ab10709591cdb0f codecov
d4281a64f2528b9365ce08f6d41477ffd3ef8886f18ace3dab20be468e88a6020c28a2bad12d6d2cc394e7e6ef035bafc2c1f24a3fbed2cbf1c415406bd60c44 codecov
160 changes: 96 additions & 64 deletions codecov
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ddp="$HOME/Library/Developer/Xcode/DerivedData"
xp=""
files=""
save_to=""
direct_file_upload=""
cacert="$CODECOV_CA_BUNDLE"
gcov_ignore="-not -path './bower_components/**' -not -path './node_modules/**' -not -path './vendor/**'"
gcov_include=""
Expand Down Expand Up @@ -146,6 +147,9 @@ cat << EOF
-F ui,chrome This upload is Chrome - UI tests
-c Move discovered coverage reports to the trash
-z FILE Upload specified file directly to Codecov and bypass all report generation.
This is inteded to be used only with a pre-formatted Codecov report and is not
expected to work under any other circumstances.
-Z Exit with 1 if not successful. Default will Exit with 0
-- xcode --
Expand Down Expand Up @@ -248,10 +252,9 @@ parse_yaml() {
}'
}


if [ $# != 0 ];
then
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
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
do
codecov_flags+=( "$o" )
case "$o" in
Expand Down Expand Up @@ -451,6 +454,17 @@ $OPTARG"
"Z")
exit_with=1
;;
"z")
direct_file_upload="$OPTARG"
ft_gcov="0"
ft_coveragepy="0"
ft_fix="0"
ft_search="0"
ft_network="0"
ft_xcodellvm="0"
ft_gcovout="0"
include_cov=""
;;
*)
echo -e "${r}Unexpected flag not supported${x}"
;;
Expand All @@ -471,16 +485,19 @@ say "

# check for installed tools
# git/hg
if [ -x "$(command -v git)" ];
if [ "$direct_file_upload" = "" ];
then
say "$b==>$x $(git --version) found"
else
say "$y==>$x git not installed, testing for mercurial"
if [ -x "$(command -v hg)" ];
if [ -x "$(command -v git)" ];
then
say "$b==>$x $(hg --version) found"
say "$b==>$x $(git --version) found"
else
say "$r==>$x git nor mercurial are installed. Uploader may fail or have unintended consequences"
say "$y==>$x git not installed, testing for mercurial"
if [ -x "$(command -v hg)" ];
then
say "$b==>$x $(hg --version) found"
else
say "$r==>$x git nor mercurial are installed. Uploader may fail or have unintended consequences"
fi
fi
fi
# curl
Expand Down Expand Up @@ -1373,6 +1390,9 @@ $PWD/coverage.xml"
elif [ "$include_cov" != "" ];
then
files=$(eval "find $search_in -type f \( ${include_cov:5} \)$exclude_cov 2>/dev/null" || echo '')
elif [ "$direct_file_upload" != "" ];
then
files=$direct_file_upload
fi

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

trap cleanup INT ABRT TERM


if [ "$env" != "" ];
then
inc_env=""
Expand All @@ -1455,13 +1476,16 @@ then
"
fi
done

echo "$inc_env<<<<<< ENV" >> "$upload_file"
echo "$inc_env<<<<<< ENV" >> "$upload_file"
fi

# Append git file list
# write discovered yaml location
echo "$yaml" >> "$upload_file"
if [ "$direct_file_upload" = "" ];
then
echo "$yaml" >> "$upload_file"
fi

if [ "$ft_network" == "1" ];
then
i="woff|eot|otf" # fonts
Expand All @@ -1473,70 +1497,78 @@ then
then
i="$i|html"
fi

echo "$network" | grep -vwE "($i)$" >> "$upload_file"
fi
echo "<<<<<< network" >> "$upload_file"

fr=0
say "${e}==>${x} Reading reports"
while IFS='' read -r file;
do
# read the coverage file
if [ "$(echo "$file" | tr -d ' ')" != '' ];
then
if [ -f "$file" ];
if [ "$direct_file_upload" = "" ];
then
fr=0
say "${e}==>${x} Reading reports"
while IFS='' read -r file;
do
# read the coverage file
if [ "$(echo "$file" | tr -d ' ')" != '' ];
then
report_len=$(wc -c < "$file")
if [ "$report_len" -ne 0 ];
if [ -f "$file" ];
then
say " ${g}+${x} $file ${e}bytes=$(echo "$report_len" | tr -d ' ')${x}"
# append to to upload
_filename=$(basename "$file")
if [ "${_filename##*.}" = 'gcov' ];
report_len=$(wc -c < "$file")
if [ "$report_len" -ne 0 ];
then
{
echo "# path=$(echo "$file.reduced" | sed "s|^$git_root/||")";
# get file name
head -1 "$file";
} >> "$upload_file"
# 1. remove source code
# 2. remove ending bracket lines
# 3. remove whitespace
# 4. remove contextual lines
# 5. remove function names
awk -F': *' '{print $1":"$2":"}' "$file" \
| sed '\/: *} *$/d' \
| sed 's/^ *//' \
| sed '/^-/d' \
| sed 's/^function.*/func/' >> "$upload_file"
say " ${g}+${x} $file ${e}bytes=$(echo "$report_len" | tr -d ' ')${x}"
# append to to upload
_filename=$(basename "$file")
if [ "${_filename##*.}" = 'gcov' ];
then
{
echo "# path=$(echo "$file.reduced" | sed "s|^$git_root/||")";
# get file name
head -1 "$file";
} >> "$upload_file"
# 1. remove source code
# 2. remove ending bracket lines
# 3. remove whitespace
# 4. remove contextual lines
# 5. remove function names
awk -F': *' '{print $1":"$2":"}' "$file" \
| sed '\/: *} *$/d' \
| sed 's/^ *//' \
| sed '/^-/d' \
| sed 's/^function.*/func/' >> "$upload_file"
else
{
echo "# path=${file//^$git_root/||}";
cat "$file";
} >> "$upload_file"
fi
echo "<<<<<< EOF" >> "$upload_file"
fr=1
if [ "$clean" = "1" ];
then
rm "$file"
fi
else
{
echo "# path=${file//^$git_root/||}";
cat "$file";
} >> "$upload_file"
fi
echo "<<<<<< EOF" >> "$upload_file"
fr=1
if [ "$clean" = "1" ];
then
rm "$file"
say " ${r}-${x} Skipping empty file $file"
fi
else
say " ${r}-${x} Skipping empty file $file"
say " ${r}-${x} file not found at $file"
fi
else
say " ${r}-${x} file not found at $file"
fi
fi
done <<< "$(echo -e "$files")"
done <<< "$(echo -e "$files")"

if [ "$fr" = "0" ];
then
say "${r}-->${x} No coverage data found."
say " Please visit ${b}http://docs.codecov.io/docs/supported-languages${x}"
say " search for your projects language to learn how to collect reports."
exit ${exit_with};
if [ "$fr" = "0" ];
then
say "${r}-->${x} No coverage data found."
say " Please visit ${b}http://docs.codecov.io/docs/supported-languages${x}"
say " search for your projects language to learn how to collect reports."
exit ${exit_with};
fi
else
cp "$direct_file_upload" "$upload_file"
if [ "$clean" = "1" ];
then
rm "$direct_file_upload"
fi
fi

if [ "$ft_fix" = "1" ];
Expand Down Expand Up @@ -1725,7 +1757,7 @@ else
if [ "$save_to" != "" ];
then
say "${e}==>${x} Copying upload file to ${save_to}"
mkdir --parents "$save_to"
mkdir -p "$(dirname "$save_to")"
cp "$upload_file" "$save_to"
fi

Expand Down
45 changes: 45 additions & 0 deletions tests/reports/direct_report.json

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions tests/test
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,28 @@ function test_token_env () {
assertTrue 'Expected output differs.' $?
}

# function test_upload () {
# reset
# export CI="true"
# export TRAVIS_JOB_ID="33116958"
# export TRAVIS="true"
# export TRAVIS_BRANCH="master"
# export TRAVIS_COMMIT="c739768fcac68144a3a6d82305b9c4106934d31a"
# export TRAVIS_REPO_SLUG='codecov/ci-repo'
# export TRAVIS_JOB_ID="33116958"
# export TRAVIS_PULL_REQUEST="false"
# export TRAVIS_JOB_NUMBER="4.1"
# res=$(./codecov)
# assertContains "$res" "Reports queued to"
# assertContains "$res" "http://codecov.io/github/codecov/ci-repo?ref=c739768fcac68144a3a6d82305b9c4106934d31a"
# }
function test_upload () {
reset
export CI="true"
export CIRCLECI="true"
export VERSION=$VERSION
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
printenv
res=$(./codecov -F test)
assertContains "$res" "View reports at"
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
}

function test_direct_upload () {
reset
export CI="true"
export CIRCLECI="true"
export VERSION=$VERSION
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
res=$(./codecov -z "tests/reports/direct_report.json" -F test)
assertContains "$res" "View reports at"
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
}

# -----------------
# Test CI Companies
Expand Down

0 comments on commit 5de0eef

Please sign in to comment.