Skip to content

Commit

Permalink
Merge pull request #28 from codecov/th/revamp-vars
Browse files Browse the repository at this point in the history
fix: update var usage to split properly when run
  • Loading branch information
thomasrockhu-codecov authored Nov 20, 2024
2 parents 6d91f42 + a92bfaa commit 21e5116
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 92 deletions.
94 changes: 50 additions & 44 deletions dist/codecov.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
CC_WRAPPER_VERSION="0.0.25"
CC_WRAPPER_VERSION="0.0.26"
set +u
say() {
echo -e "$1"
Expand All @@ -15,16 +15,22 @@ exit_if_error() {
lower() {
echo $(echo $1 | sed 's/CC//' | sed 's/_/-/g' | tr '[:upper:]' '[:lower:]')
}
write_existing_args() {
if [ -n "$(eval echo \$$1)" ];
k_arg() {
if [ -n "$(eval echo \$"CC_$1")" ];
then
echo " -$(lower "$1") $(eval echo \$$1)"
echo "--$(lower "$1")"
fi
}
v_arg() {
if [ -n "$(eval echo \$"CC_$1")" ];
then
echo "$(eval echo \$"CC_$1")"
fi
}
write_truthy_args() {
if [ "$(eval echo \$$1)" = "true" ] || [ "$(eval echo \$$1)" = "1" ];
then
echo " -$(lower $1)"
echo "-$(lower $1)"
fi
}
b="\033[0;36m" # variables/constants
Expand Down Expand Up @@ -115,80 +121,80 @@ CC_PUBLIC_PGP_KEY=$(curl -s https://keybase.io/codecovsecurity/pgp_keys.asc)
say
fi
cc_cli_args=()
cc_cli_args+=( $(write_existing_args CC_AUTO_LOAD_PARAMS_FROM) )
cc_cli_args+=( $(write_existing_args CC_ENTERPRISE_URL) )
cc_cli_args+=( $(write_existing_args CC_YML_PATH) )
cc_cli_args+=( $(k_arg AUTO_LOAD_PARAMS_FROM) $(v_arg AUTO_LOAD_PARAMS_FROM))
cc_cli_args+=( $(k_arg ENTERPRISE_URL) $(v_arg ENTERPRISE_URL))
cc_cli_args+=( $(k_arg YML_PATH) $(v_arg YML_PATH))
cc_cli_args+=( $(write_truthy_args CC_VERBOSE) )
cc_cc_args=()
cc_cc_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
cc_cc_args+=( $(write_existing_args CC_GIT_SERVICE) )
cc_cc_args+=( $(write_existing_args CC_PARENT_SHA) )
cc_cc_args+=( $(write_existing_args CC_PR) )
cc_cc_args+=( $(write_existing_args CC_SHA) )
cc_cc_args+=( $(write_existing_args CC_SLUG) )
cc_du_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_du_args+=( $(k_arg PARENT_SHA) $(v_arg PARENT_SHA))
cc_du_args+=( $(k_arg PR) $(v_arg PR))
cc_du_args+=( $(k_arg SHA) $(v_arg SHA))
cc_du_args+=( $(k_arg SLUG) $(v_arg SLUG))
cc_create_report_args=()
cc_cr_args+=( $(write_existing_args CC_CODE) )
cc_cr_args+=( $(k_arg CODE) $(v_arg CODE))
cc_cr_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
cc_cr_args+=( $(write_existing_args CC_GIT_SERVICE) )
cc_cr_args+=( $(write_existing_args CC_PR) )
cc_cr_args+=( $(write_existing_args CC_SHA) )
cc_cr_args+=( $(write_existing_args CC_SLUG) )
cc_cr_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_cr_args+=( $(k_arg PR) $(v_arg PR))
cc_cr_args+=( $(k_arg SHA) $(v_arg SHA))
cc_cr_args+=( $(k_arg SLUG) $(v_arg SLUG))
cc_du_args=()
cc_du_args+=( $(write_existing_args CC_ENV) )
cc_du_args+=( $(k_arg ENV) $(v_arg ENV))
OLDIFS=$IFS;IFS=,
cc_du_args+=( $(write_existing_args CC_BRANCH) )
cc_du_args+=( $(write_existing_args CC_BUILD) )
cc_du_args+=( $(write_existing_args CC_BUILD_URL) )
cc_du_args+=( $(write_existing_args CC_CODE) )
cc_du_args+=( $(write_existing_args CC_DIR) )
cc_du_args+=( $(k_arg BRANCH) $(v_arg BRANCH))
cc_du_args+=( $(k_arg BUILD) $(v_arg BUILD))
cc_du_args+=( $(k_arg BUILD_URL) $(v_arg BUILD_URL))
cc_du_args+=( $(k_arg CODE) $(v_arg CODE))
cc_du_args+=( $(k_arg DIR) $(v_arg DIR))
cc_du_args+=( $(write_truthy_args CC_DISABLE_FILE_FIXES) )
cc_du_args+=( $(write_truthy_args CC_DISABLE_SEARCH) )
cc_du_args+=( $(write_truthy_args CC_DRY_RUN) )
if [ -n "$CC_EXCLUDES" ];
then
for directory in $CC_EXCLUDES; do
cc_du_args+=( " --exclude " "$directory" )
cc_du_args+=( "--exclude" "$directory" )
done
fi
cc_du_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
if [ -n "$CC_FILES" ];
then
for file in $CC_FILES; do
cc_du_args+=( " --file " "$file" )
cc_du_args+=( "--file" "$file" )
done
fi
if [ -n "$CC_FLAGS" ];
then
for flag in $CC_FLAGS; do
cc_du_args+=( " --flag " "$flag" )
cc_du_args+=( "--flag" "$flag" )
done
fi
cc_du_args+=( $(write_existing_args CC_GCOV_ARGS) )
cc_du_args+=( $(write_existing_args CC_GCOV_EXECUTABLE) )
cc_du_args+=( $(write_existing_args CC_GCOV_IGNORE) )
cc_du_args+=( $(write_existing_args CC_GCOV_INCLUDE) )
cc_du_args+=( $(write_existing_args CC_GIT_SERVICE) )
cc_du_args+=( $(k_arg GCOV_ARGS) $(v_arg GCOV_ARGS))
cc_du_args+=( $(k_arg GCOV_EXECUTABLE) $(v_arg GCOV_EXECUTABLE))
cc_du_args+=( $(k_arg GCOV_IGNORE) $(v_arg GCOV_IGNORE))
cc_du_args+=( $(k_arg GCOV_INCLUDE) $(v_arg GCOV_INCLUDE))
cc_du_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_du_args+=( $(write_truthy_args CC_HANDLE_NO_REPORTS_FOUND) )
cc_du_args+=( $(write_existing_args CC_JOB_CODE) )
cc_du_args+=( $(k_arg JOB_CODE) $(v_arg JOB_CODE))
cc_du_args+=( $(write_truthy_args CC_LEGACY) )
if [ -n "$CC_NAME" ];
then
cc_du_args+=( "--name" "$CC_NAME" )
fi
cc_du_args+=( $(write_existing_args CC_NETWORK_FILTER) )
cc_du_args+=( $(write_existing_args CC_NETWORK_PREFIX) )
cc_du_args+=( $(write_existing_args CC_NETWORK_ROOT_FOLDER) )
cc_du_args+=( $(k_arg NETWORK_FILTER) $(v_arg NETWORK_FILTER))
cc_du_args+=( $(k_arg NETWORK_PREFIX) $(v_arg NETWORK_PREFIX))
cc_du_args+=( $(k_arg NETWORK_ROOT_FOLDER) $(v_arg NETWORK_ROOT_FOLDER))
if [ -n "$CC_PLUGINS" ];
then
for plugin in $CC_PLUGINS; do
cc_du_args+=( " --plugin " "$plugin" )
cc_du_args+=( "--plugin" "$plugin" )
done
fi
cc_du_args+=( $(write_existing_args CC_PR) )
cc_du_args+=( $(write_existing_args CC_REPORT_TYPE) )
cc_du_args+=( $(write_existing_args CC_SHA) )
cc_du_args+=( $(write_existing_args CC_SLUG) )
cc_du_args+=( $(write_existing_args CC_SWIFT_PROJECT) )
cc_du_args+=( $(k_arg PR) $(v_arg PR))
cc_du_args+=( $(k_arg REPORT_TYPE) $(v_arg REPORT_TYPE))
cc_du_args+=( $(k_arg SHA) $(v_arg SHA))
cc_du_args+=( $(k_arg SLUG) $(v_arg SLUG))
cc_du_args+=( $(k_arg SWIFT_PROJECT) $(v_arg SWIFT_PROJECT))
IFS=$OLDIFS
unset NODE_OPTIONS
# See https://github.com/codecov/uploader/issues/475
Expand All @@ -213,7 +219,7 @@ if ! ./$cc_filename \
${cc_cli_args[*]} \
create-commit \
${token_arg[*]} \
${cc_cc_args[*]};
"${cc_cc_args[@]}";
then
exit_if_error "Failed to create-commit"
fi
Expand All @@ -224,7 +230,7 @@ if ! ./$cc_filename \
${cc_cli_args[*]} \
create-report \
${token_arg[*]} \
${cc_cr_args[*]};
"${cc_cr_args[@]}";
then
exit_if_error "Failed to create-report"
fi
Expand Down
16 changes: 12 additions & 4 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def package_scripts(source_dir, source_root, outfile):
with open(outfile, 'w') as f:
f.write(BASH_LINE)
for line in lines:
cc_vars.update(_get_vars(line))
cc_vars.add(_get_vars(line))
f.write(line)

st = os.stat(outfile)
Expand All @@ -30,9 +30,17 @@ def package_scripts(source_dir, source_root, outfile):
exit(1)

def _get_vars(line):
matcher = r'(CC_[^\r\n\t\f\v=]+)*'
matcher = r'(CC_[\w_]+)*'
return re.findall(matcher, line)
matcher = r'(CC_[\w_]+)'
matches = re.search(matcher, line)
if matches and matches.groups():
return matches.groups()[0]

matcher = r'v_arg ([\w_]+)'
matches = re.search(matcher, line)
if matches and matches.groups():
return f"CC_{matches.groups()[0]}"

return ''

def _parse(file):
lines = []
Expand Down
6 changes: 3 additions & 3 deletions scripts/set_cli_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

codecov_cli_args=()

codecov_cli_args+=( $(write_existing_args CODECOV_AUTO_LOAD_PARAMS_FROM) )
codecov_cli_args+=( $(write_existing_args CODECOV_ENTERPRISE_URL) )
codecov_cli_args+=( $(write_existing_args CODECOV_YML_PATH) )
codecov_cli_args+=( $(k_arg AUTO_LOAD_PARAMS_FROM) $(v_arg AUTO_LOAD_PARAMS_FROM))
codecov_cli_args+=( $(k_arg ENTERPRISE_URL) $(v_arg ENTERPRISE_URL))
codecov_cli_args+=( $(k_arg YML_PATH) $(v_arg YML_PATH))
codecov_cli_args+=( $(write_truthy_args CODECOV_VERBOSE) )
10 changes: 5 additions & 5 deletions scripts/set_create_commit_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
codecov_cc_args=()

codecov_cc_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
codecov_cc_args+=( $(write_existing_args CODECOV_GIT_SERVICE) )
codecov_cc_args+=( $(write_existing_args CODECOV_PARENT_SHA) )
codecov_cc_args+=( $(write_existing_args CODECOV_PR) )
codecov_cc_args+=( $(write_existing_args CODECOV_SHA) )
codecov_cc_args+=( $(write_existing_args CODECOV_SLUG) )
codecov_du_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_du_args+=( $(k_arg PARENT_SHA) $(v_arg PARENT_SHA))
codecov_du_args+=( $(k_arg PR) $(v_arg PR))
codecov_du_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_du_args+=( $(k_arg SLUG) $(v_arg SLUG))
10 changes: 5 additions & 5 deletions scripts/set_create_report_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

codecov_create_report_args=()

codecov_cr_args+=( $(write_existing_args CODECOV_CODE) )
codecov_cr_args+=( $(k_arg CODE) $(v_arg CODE))
codecov_cr_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
codecov_cr_args+=( $(write_existing_args CODECOV_GIT_SERVICE) )
codecov_cr_args+=( $(write_existing_args CODECOV_PR) )
codecov_cr_args+=( $(write_existing_args CODECOV_SHA) )
codecov_cr_args+=( $(write_existing_args CODECOV_SLUG) )
codecov_cr_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_cr_args+=( $(k_arg PR) $(v_arg PR))
codecov_cr_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_cr_args+=( $(k_arg SLUG) $(v_arg SLUG))
15 changes: 11 additions & 4 deletions scripts/set_defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ lower() {
echo $(echo $1 | sed 's/CODECOV//' | sed 's/_/-/g' | tr '[:upper:]' '[:lower:]')
}

write_existing_args() {
if [ -n "$(eval echo \$$1)" ];
k_arg() {
if [ -n "$(eval echo \$"CODECOV_$1")" ];
then
echo " -$(lower "$1") $(eval echo \$$1)"
echo "--$(lower "$1")"
fi
}

v_arg() {
if [ -n "$(eval echo \$"CODECOV_$1")" ];
then
echo "$(eval echo \$"CODECOV_$1")"
fi
}

write_truthy_args() {
if [ "$(eval echo \$$1)" = "true" ] || [ "$(eval echo \$$1)" = "1" ];
then
echo " -$(lower $1)"
echo "-$(lower $1)"
fi
}

Expand Down
48 changes: 24 additions & 24 deletions scripts/set_do_upload_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

codecov_du_args=()

codecov_du_args+=( $(write_existing_args CODECOV_ENV) )
codecov_du_args+=( $(k_arg ENV) $(v_arg ENV))

OLDIFS=$IFS;IFS=,

codecov_du_args+=( $(write_existing_args CODECOV_BRANCH) )
codecov_du_args+=( $(write_existing_args CODECOV_BUILD) )
codecov_du_args+=( $(write_existing_args CODECOV_BUILD_URL) )
codecov_du_args+=( $(write_existing_args CODECOV_CODE) )
codecov_du_args+=( $(write_existing_args CODECOV_DIR) )
codecov_du_args+=( $(k_arg BRANCH) $(v_arg BRANCH))
codecov_du_args+=( $(k_arg BUILD) $(v_arg BUILD))
codecov_du_args+=( $(k_arg BUILD_URL) $(v_arg BUILD_URL))
codecov_du_args+=( $(k_arg CODE) $(v_arg CODE))
codecov_du_args+=( $(k_arg DIR) $(v_arg DIR))
codecov_du_args+=( $(write_truthy_args CODECOV_DISABLE_FILE_FIXES) )
codecov_du_args+=( $(write_truthy_args CODECOV_DISABLE_SEARCH) )
codecov_du_args+=( $(write_truthy_args CODECOV_DRY_RUN) )

if [ -n "$CODECOV_EXCLUDES" ];
then
for directory in $CODECOV_EXCLUDES; do
codecov_du_args+=( " --exclude " "$directory" )
codecov_du_args+=( "--exclude" "$directory" )
done
fi

Expand All @@ -27,44 +27,44 @@ codecov_du_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
if [ -n "$CODECOV_FILES" ];
then
for file in $CODECOV_FILES; do
codecov_du_args+=( " --file " "$file" )
codecov_du_args+=( "--file" "$file" )
done
fi

if [ -n "$CODECOV_FLAGS" ];
then
for flag in $CODECOV_FLAGS; do
codecov_du_args+=( " --flag " "$flag" )
codecov_du_args+=( "--flag" "$flag" )
done
fi

codecov_du_args+=( $(write_existing_args CODECOV_GCOV_ARGS) )
codecov_du_args+=( $(write_existing_args CODECOV_GCOV_EXECUTABLE) )
codecov_du_args+=( $(write_existing_args CODECOV_GCOV_IGNORE) )
codecov_du_args+=( $(write_existing_args CODECOV_GCOV_INCLUDE) )
codecov_du_args+=( $(write_existing_args CODECOV_GIT_SERVICE) )
codecov_du_args+=( $(k_arg GCOV_ARGS) $(v_arg GCOV_ARGS))
codecov_du_args+=( $(k_arg GCOV_EXECUTABLE) $(v_arg GCOV_EXECUTABLE))
codecov_du_args+=( $(k_arg GCOV_IGNORE) $(v_arg GCOV_IGNORE))
codecov_du_args+=( $(k_arg GCOV_INCLUDE) $(v_arg GCOV_INCLUDE))
codecov_du_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_du_args+=( $(write_truthy_args CODECOV_HANDLE_NO_REPORTS_FOUND) )
codecov_du_args+=( $(write_existing_args CODECOV_JOB_CODE) )
codecov_du_args+=( $(k_arg JOB_CODE) $(v_arg JOB_CODE))
codecov_du_args+=( $(write_truthy_args CODECOV_LEGACY) )
if [ -n "$CODECOV_NAME" ];
then
codecov_du_args+=( "--name" "$CODECOV_NAME" )
fi
codecov_du_args+=( $(write_existing_args CODECOV_NETWORK_FILTER) )
codecov_du_args+=( $(write_existing_args CODECOV_NETWORK_PREFIX) )
codecov_du_args+=( $(write_existing_args CODECOV_NETWORK_ROOT_FOLDER) )
codecov_du_args+=( $(k_arg NETWORK_FILTER) $(v_arg NETWORK_FILTER))
codecov_du_args+=( $(k_arg NETWORK_PREFIX) $(v_arg NETWORK_PREFIX))
codecov_du_args+=( $(k_arg NETWORK_ROOT_FOLDER) $(v_arg NETWORK_ROOT_FOLDER))

if [ -n "$CODECOV_PLUGINS" ];
then
for plugin in $CODECOV_PLUGINS; do
codecov_du_args+=( " --plugin " "$plugin" )
codecov_du_args+=( "--plugin" "$plugin" )
done
fi

codecov_du_args+=( $(write_existing_args CODECOV_PR) )
codecov_du_args+=( $(write_existing_args CODECOV_REPORT_TYPE) )
codecov_du_args+=( $(write_existing_args CODECOV_SHA) )
codecov_du_args+=( $(write_existing_args CODECOV_SLUG) )
codecov_du_args+=( $(write_existing_args CODECOV_SWIFT_PROJECT) )
codecov_du_args+=( $(k_arg PR) $(v_arg PR))
codecov_du_args+=( $(k_arg REPORT_TYPE) $(v_arg REPORT_TYPE))
codecov_du_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_du_args+=( $(k_arg SLUG) $(v_arg SLUG))
codecov_du_args+=( $(k_arg SWIFT_PROJECT) $(v_arg SWIFT_PROJECT))

IFS=$OLDIFS
4 changes: 2 additions & 2 deletions scripts/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ! ./$codecov_filename \
${codecov_cli_args[*]} \
create-commit \
${token_arg[*]} \
${codecov_cc_args[*]};
"${codecov_cc_args[@]}";
then
exit_if_error "Failed to create-commit"
fi
Expand All @@ -39,7 +39,7 @@ if ! ./$codecov_filename \
${codecov_cli_args[*]} \
create-report \
${token_arg[*]} \
${codecov_cr_args[*]};
"${codecov_cr_args[@]}";
then
exit_if_error "Failed to create-report"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
CODECOV_WRAPPER_VERSION="0.0.25"
CODECOV_WRAPPER_VERSION="0.0.26"

0 comments on commit 21e5116

Please sign in to comment.