11#! /usr/bin/env bash
2- CC_WRAPPER_VERSION=" 0.0.18"
2+ CC_WRAPPER_VERSION=" 0.0.30"
3+ set +u
34say () {
45 echo -e " $1 "
56}
67exit_if_error () {
78 say " $r ==> $1 $x "
8- if [ $CC_FAIL_ON_ERROR = true ];
9+ if [ " $CC_FAIL_ON_ERROR " = true ];
910 then
1011 say " $r Exiting...$x "
1112 exit 1;
@@ -14,16 +15,22 @@ exit_if_error() {
1415lower () {
1516 echo $( echo $1 | sed ' s/CC//' | sed ' s/_/-/g' | tr ' [:upper:]' ' [:lower:]' )
1617}
17- write_existing_args () {
18- if [ -n " $( eval echo \$ $1 ) " ];
18+ k_arg () {
19+ if [ -n " $( eval echo \$ " CC_ $1 " ) " ];
1920 then
20- echo " -$( lower " $1 " ) $( eval echo \$ $1 ) "
21+ echo " --$( lower " $1 " ) "
22+ fi
23+ }
24+ v_arg () {
25+ if [ -n " $( eval echo \$ " CC_$1 " ) " ];
26+ then
27+ echo " $( eval echo \$ " CC_$1 " ) "
2128 fi
2229}
2330write_truthy_args () {
2431 if [ " $( eval echo \$ $1 ) " = " true" ] || [ " $( eval echo \$ $1 ) " = " 1" ];
2532 then
26- echo " -$( lower $1 ) "
33+ echo " -$( lower $1 ) "
2734 fi
2835}
2936b=" \033[0;36m" # variables/constants
4956 exit_if_error " Could not find binary file $CC_BINARY "
5057 fi
5158else
52- family=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
53- cc_os=" windows"
54- [[ $family == " darwin" ]] && cc_os=" macos"
55- [[ $family == " linux" ]] && cc_os=" linux"
56- [[ $cc_os == " linux" ]] && \
57- osID=$( grep -e " ^ID=" /etc/os-release | cut -c4-)
58- [[ $osID == " alpine" ]] && cc_os=" alpine"
59- [[ $( arch) == " aarch64" && $family == " linux" ]] && cc_os+=" -arm64"
60- say " $g ==>$x Detected $b ${cc_os} $x "
61- export cc_os=${cc_os}
59+ if [ -n " $CC_OS " ];
60+ then
61+ say " $g ==>$x Overridden OS: $b ${CC_OS} $x "
62+ export cc_os=${CC_OS}
63+ else
64+ CC_OS=" linux"
65+ family=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
66+ cc_os=" windows"
67+ [[ $family == " darwin" ]] && cc_os=" macos"
68+ [[ $family == " linux" ]] && cc_os=" linux"
69+ [[ $cc_os == " linux" ]] && \
70+ osID=$( grep -e " ^ID=" /etc/os-release | cut -c4-)
71+ [[ $osID == " alpine" ]] && cc_os=" alpine"
72+ [[ $( arch) == " aarch64" && $family == " linux" ]] && cc_os+=" -arm64"
73+ say " $g ==>$x Detected $b ${cc_os} $x "
74+ export cc_os=${cc_os}
75+ fi
6276 export cc_version=${CC_VERSION}
6377 cc_filename=" codecov"
6478 [[ $cc_os == " windows" ]] && cc_filename+=" .exe"
7084 cc_url=" $cc_url /${CC_VERSION} "
7185 cc_url=" $cc_url /${cc_os} /${cc_filename} "
7286 say " $g ->$x Downloading $b ${cc_url} $x "
73- curl -Os $cc_url
87+ curl -Os " $cc_url "
7488 say " $g ==>$x Finishing downloading $b ${cc_os} :${CC_VERSION} $x "
89+ version_url=" https://cli.codecov.io/api/${cc_os} /${CC_VERSION} "
90+ version=$( curl -s " $version_url " -H " Accept:application/json" | jq -r ' .version' )
91+ say " Version: $b$version$x "
7592 say " "
7693fi
7794if [ " $CC_SKIP_VALIDATION " = " true" ] || [ -n " $CC_BINARY " ];
7895then
7996 say " $r ==>$x Bypassing validation as requested by user"
8097else
81- CC_PUBLIC_PGP_KEY=$( curl https://keybase.io/codecovsecurity/pgp_keys.asc)
98+ CC_PUBLIC_PGP_KEY=$( curl -s https://keybase.io/codecovsecurity/pgp_keys.asc)
8299 echo " ${CC_PUBLIC_PGP_KEY} " | \
83100 gpg --no-default-keyring --import
84101 # One-time step
@@ -89,13 +106,13 @@ CC_PUBLIC_PGP_KEY=$(curl https://keybase.io/codecovsecurity/pgp_keys.asc)
89106 say " $g ->$x Downloading $b ${sha_url} $x "
90107 say " $g ->$x Downloading $b ${sha_url} .sig$x "
91108 say " "
92- curl -Os " $sha_url "
93- curl -Os " ${sha_url} .sig"
109+ curl -Os --retry 5 --retry-delay 2 --connect-timeout 2 " $sha_url "
110+ curl -Os --retry 5 --retry-delay 2 --connect-timeout 2 " ${sha_url} .sig"
94111 if ! gpg --verify " ${cc_filename} .SHA256SUM.sig" " ${cc_filename} .SHA256SUM" ;
95112 then
96113 exit_if_error " Could not verify signature. Please contact Codecov if problem continues"
97114 fi
98- if ! (shasum -a 256 -c " ${cc_filename} .SHA256SUM" || \
115+ if ! (shasum -a 256 -c " ${cc_filename} .SHA256SUM" 2> /dev/null || \
99116 sha256sum -c " ${cc_filename} .SHA256SUM" );
100117 then
101118 exit_if_error " Could not verify SHASUM. Please contact Codecov if problem continues"
@@ -104,77 +121,74 @@ CC_PUBLIC_PGP_KEY=$(curl https://keybase.io/codecovsecurity/pgp_keys.asc)
104121 say
105122fi
106123cc_cli_args=()
107- cc_cli_args+=( $( write_existing_args CC_AUTO_LOAD_PARAMS_FROM) )
108- cc_cli_args+=( $( write_existing_args CC_ENTERPRISE_URL) )
109- cc_cli_args+=( $( write_existing_args CC_YML_PATH) )
124+ cc_cli_args+=( $( k_arg AUTO_LOAD_PARAMS_FROM) $( v_arg AUTO_LOAD_PARAMS_FROM) )
125+ cc_cli_args+=( $( k_arg ENTERPRISE_URL) $( v_arg ENTERPRISE_URL) )
126+ if [ -n " $CC_YML_PATH " ]
127+ then
128+ cc_cli_args+=( " --codecov-yml-path" )
129+ cc_cli_args+=( " $CC_YML_PATH " )
130+ fi
110131cc_cli_args+=( $( write_truthy_args CC_VERBOSE) )
111- cc_cc_args=()
112- cc_cc_args+=( $( write_truthy_args CC_FAIL_ON_ERROR) )
113- cc_cc_args+=( $( write_existing_args CC_GIT_SERVICE) )
114- cc_cc_args+=( $( write_existing_args CC_PARENT_SHA) )
115- cc_cc_args+=( $( write_existing_args CC_PR) )
116- cc_cc_args+=( $( write_existing_args CC_SHA) )
117- cc_cc_args+=( $( write_existing_args CC_SLUG) )
118- cc_create_report_args=()
119- cc_cr_args+=( $( write_existing_args CC_CODE) )
120- cc_cr_args+=( $( write_truthy_args CC_FAIL_ON_ERROR) )
121- cc_cr_args+=( $( write_existing_args CC_GIT_SERVICE) )
122- cc_cr_args+=( $( write_existing_args CC_PR) )
123- cc_cr_args+=( $( write_existing_args CC_SHA) )
124- cc_cr_args+=( $( write_existing_args CC_SLUG) )
125- cc_du_args=()
132+ cc_uc_args=()
133+ # Args for create commit
134+ cc_uc_args+=( $( write_truthy_args CC_FAIL_ON_ERROR) )
135+ cc_uc_args+=( $( k_arg GIT_SERVICE) $( v_arg GIT_SERVICE) )
136+ cc_uc_args+=( $( k_arg PARENT_SHA) $( v_arg PARENT_SHA) )
137+ cc_uc_args+=( $( k_arg PR) $( v_arg PR) )
138+ cc_uc_args+=( $( k_arg SHA) $( v_arg SHA) )
139+ cc_uc_args+=( $( k_arg SLUG) $( v_arg SLUG) )
140+ # Args for create report
141+ cc_uc_args+=( $( k_arg CODE) $( v_arg CODE) )
142+ # Args for do upload
143+ cc_uc_args+=( $( k_arg ENV) $( v_arg ENV) )
126144OLDIFS=$IFS ; IFS=,
127- cc_du_args+=( $( write_existing_args CC_BRANCH) )
128- cc_du_args+=( $( write_existing_args CC_BUILD) )
129- cc_du_args+=( $( write_existing_args CC_BUILD_URL) )
130- cc_du_args+=( $( write_existing_args CC_CODE) )
131- cc_du_args+=( $( write_existing_args CC_DIR) )
132- cc_du_args+=( $( write_truthy_args CC_DISABLE_FILE_FIXES) )
133- cc_du_args+=( $( write_truthy_args CC_DISABLE_SEARCH) )
134- cc_du_args+=( $( write_truthy_args CC_DRY_RUN) )
135- cc_du_args+=( $( write_existing_args CC_ENV) )
145+ cc_uc_args+=( $( k_arg BRANCH) $( v_arg BRANCH) )
146+ cc_uc_args+=( $( k_arg BUILD) $( v_arg BUILD) )
147+ cc_uc_args+=( $( k_arg BUILD_URL) $( v_arg BUILD_URL) )
148+ cc_uc_args+=( $( k_arg DIR) $( v_arg DIR) )
149+ cc_uc_args+=( $( write_truthy_args CC_DISABLE_FILE_FIXES) )
150+ cc_uc_args+=( $( write_truthy_args CC_DISABLE_SEARCH) )
151+ cc_uc_args+=( $( write_truthy_args CC_DRY_RUN) )
136152if [ -n " $CC_EXCLUDES " ];
137153then
138154 for directory in $CC_EXCLUDES ; do
139- cc_du_args +=( " --exclude " " $directory " )
155+ cc_uc_args +=( " --exclude" " $directory " )
140156 done
141157fi
142- cc_du_args+=( $( write_truthy_args CC_FAIL_ON_ERROR) )
143158if [ -n " $CC_FILES " ];
144159then
145160 for file in $CC_FILES ; do
146- cc_du_args +=( " --file " " $file " )
161+ cc_uc_args +=( " --file" " $file " )
147162 done
148163fi
149164if [ -n " $CC_FLAGS " ];
150165then
151166 for flag in $CC_FLAGS ; do
152- cc_du_args +=( " --flag " " $flag " )
167+ cc_uc_args +=( " --flag" " $flag " )
153168 done
154169fi
155- cc_du_args+=( $( write_existing_args CC_GCOV_ARGS) )
156- cc_du_args+=( $( write_existing_args CC_GCOV_EXECUTABLE) )
157- cc_du_args+=( $( write_existing_args CC_GCOV_IGNORE) )
158- cc_du_args+=( $( write_existing_args CC_GCOV_INCLUDE) )
159- cc_du_args+=( $( write_existing_args CC_GIT_SERVICE) )
160- cc_du_args+=( $( write_truthy_args CC_HANDLE_NO_REPORTS_FOUND) )
161- cc_du_args+=( $( write_existing_args CC_JOB_CODE) )
162- cc_du_args+=( $( write_truthy_args CC_LEGACY) )
163- cc_du_args+=( $( write_existing_args CC_NAME) )
164- cc_du_args+=( $( write_existing_args CC_NETWORK_FILTER) )
165- cc_du_args+=( $( write_existing_args CC_NETWORK_PREFIX) )
166- cc_du_args+=( $( write_existing_args CC_NETWORK_ROOT_FOLDER) )
170+ cc_uc_args+=( $( k_arg GCOV_ARGS) $( v_arg GCOV_ARGS) )
171+ cc_uc_args+=( $( k_arg GCOV_EXECUTABLE) $( v_arg GCOV_EXECUTABLE) )
172+ cc_uc_args+=( $( k_arg GCOV_IGNORE) $( v_arg GCOV_IGNORE) )
173+ cc_uc_args+=( $( k_arg GCOV_INCLUDE) $( v_arg GCOV_INCLUDE) )
174+ cc_uc_args+=( $( write_truthy_args CC_HANDLE_NO_REPORTS_FOUND) )
175+ cc_uc_args+=( $( k_arg JOB_CODE) $( v_arg JOB_CODE) )
176+ cc_uc_args+=( $( write_truthy_args CC_LEGACY) )
177+ if [ -n " $CC_NAME " ];
178+ then
179+ cc_uc_args+=( " --name" " $CC_NAME " )
180+ fi
181+ cc_uc_args+=( $( k_arg NETWORK_FILTER) $( v_arg NETWORK_FILTER) )
182+ cc_uc_args+=( $( k_arg NETWORK_PREFIX) $( v_arg NETWORK_PREFIX) )
183+ cc_uc_args+=( $( k_arg NETWORK_ROOT_FOLDER) $( v_arg NETWORK_ROOT_FOLDER) )
167184if [ -n " $CC_PLUGINS " ];
168185then
169186 for plugin in $CC_PLUGINS ; do
170- cc_du_args +=( " --plugin " " $plugin " )
187+ cc_uc_args +=( " --plugin" " $plugin " )
171188 done
172189fi
173- cc_du_args+=( $( write_existing_args CC_PR) )
174- cc_du_args+=( $( write_existing_args CC_REPORT_TYPE) )
175- cc_du_args+=( $( write_existing_args CC_SHA) )
176- cc_du_args+=( $( write_existing_args CC_SLUG) )
177- cc_du_args+=( $( write_existing_args CC_SWIFT_PROJECT) )
190+ cc_uc_args+=( $( k_arg REPORT_TYPE) $( v_arg REPORT_TYPE) )
191+ cc_uc_args+=( $( k_arg SWIFT_PROJECT) $( v_arg SWIFT_PROJECT) )
178192IFS=$OLDIFS
179193unset NODE_OPTIONS
180194# See https://github.com/codecov/uploader/issues/475
@@ -193,35 +207,13 @@ then
193207 token_str+=" -t <redacted>"
194208 token_arg+=( " -t " " $token " )
195209fi
196- say " $g ==>$x Running create-commit"
197- say " $b ./$cc_filename $( echo " ${cc_cli_args[@]} " ) create-commit$token_str $( echo " ${cc_cc_args[@]} " ) $x "
198- if ! ./$cc_filename \
199- ${cc_cli_args[*]} \
200- create-commit \
201- ${token_arg[*]} \
202- ${cc_cc_args[*]} ;
203- then
204- exit_if_error " Failed to create-commit"
205- fi
206- say " "
207- say " $g ==>$x Running create-report"
208- say " $b ./$cc_filename $( echo " ${cc_cli_args[@]} " ) create-report$token_str $( echo " ${cc_cr_args[@]} " ) $x "
209- if ! ./$cc_filename \
210- ${cc_cli_args[*]} \
211- create-report \
212- ${token_arg[*]} \
213- ${cc_cr_args[*]} ;
214- then
215- exit_if_error " Failed to create-report"
216- fi
217- say " "
218- say " $g ==>$x Running do-upload"
219- say " $b ./$cc_filename $( echo " ${cc_cli_args[@]} " ) do-upload$token_str $( echo " ${cc_du_args[@]} " ) $x "
210+ say " $g ==>$x Running upload-coverage"
211+ say " $b ./$cc_filename $( echo " ${cc_cli_args[@]} " ) upload-coverage$token_str $( echo " ${cc_uc_args[@]} " ) $x "
220212if ! ./$cc_filename \
221213 ${cc_cli_args[*]} \
222- do- upload \
214+ upload-coverage \
223215 ${token_arg[*]} \
224- ${cc_du_args[*]} ;
216+ " ${cc_uc_args[@]} " ;
225217then
226- exit_if_error " Failed to upload"
218+ exit_if_error " Failed to upload coverage "
227219fi
0 commit comments