Skip to content

Commit

Permalink
fix: make it smaller, and env, and 0.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov committed Oct 4, 2024
1 parent ad30c54 commit 3a22531
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 340 deletions.
210 changes: 56 additions & 154 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.13"
CC_WRAPPER_VERSION="0.0.14"
say() {
echo -e "$1"
}
Expand All @@ -11,6 +11,21 @@ exit_if_error() {
exit 1;
fi
}
lower() {
echo $(echo $1 | sed 's/CC//' | sed 's/_/-//' | tr '[:upper:]' '[:lower:]')
}
write_existing_args() {
if [ -n "$1" ];
then
echo " --$(lower $1) $(eval echo \$$1)"
fi
}
write_truthy_args() {
if [ "$1" = "true" ];
then
echo " --$(lower $1)"
fi
}
b="\033[0;36m" # variables/constants
g="\033[0;32m" # info/debug
r="\033[0;31m" # errors
Expand All @@ -25,7 +40,6 @@ say " _____ _
"
CC_VERSION="${CC_VERSION:-latest}"
CC_FAIL_ON_ERROR="${CC_FAIL_ON_ERROR:-false}"
say
if [ -n "$CC_BINARY" ];
then
if [ -f "$CC_BINARY" ];
Expand Down Expand Up @@ -90,113 +104,41 @@ CC_PUBLIC_PGP_KEY=$(curl https://keybase.io/codecovsecurity/pgp_keys.asc)
say
fi
cc_cli_args=()
if [ -n "$CC_AUTO_LOAD_PARAMS_FROM" ];
then
cc_cli_args+=( " --auto-load-params-from " "${CC_AUTO_LOAD_PARAMS_FROM}" )
fi
if [ -n "$CC_ENTERPRISE_URL" ];
then
cc_cli_args+=( " --enterprise-url " "${CC_ENTERPRISE_URL}" )
fi
unset CC_YML_PATH
if [ -n "$CC_YML_PATH" ];
then
cc_cli_args+=( " --codecov-yml-path " "${CC_YML_PATH}" )
fi
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_cc_args=()
if [ "$CC_FAIL_ON_ERROR" = "true" ];
then
cc_cc_args+=( " --fail-on-error" )
fi
if [ -n "$CC_GIT_SERVICE" ];
then
cc_cc_args+=( " --git-service " "${CC_GIT_SERVICE}" )
fi
if [ -n "$CC_PARENT_SHA" ];
then
cc_cc_args+=( " --parent-sha " "${CC_PARENT_SHA}" )
fi
if [ -n "$CC_PULL_REQUEST" ];
then
cc_cc_args+=( " --pr " "${CC_PULL_REQUEST}" )
fi
if [ -n "$CC_SHA" ];
then
cc_cc_args+=( " --sha " "${CC_SHA}" )
fi
if [ -n "$CC_SLUG" ];
then
cc_cc_args+=( " --slug " "${CC_SLUG}" )
fi
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_create_report_args=()
if [ -n "$CC_CODE" ];
then
cc_cr_args+=( " --code " "${CC_CODE}" )
fi
if [ "$CC_FAIL_ON_ERROR" = "true" ];
then
cc_cr_args+=( " --fail-on-error" )
fi
if [ -n "$CC_GIT_SERVICE" ];
then
cc_cr_args+=( " --git-service " "${CC_GIT_SERVICE}" )
fi
if [ -n "$CC_PULL_REQUEST" ];
then
cc_cr_args+=( " --pr " "${CC_PULL_REQUEST}" )
fi
if [ -n "$CC_SHA" ];
then
cc_cr_args+=( " --sha " "${CC_SHA}" )
fi
if [ -n "$CC_SLUG" ];
then
cc_cr_args+=( " --slug " "${CC_SLUG}" )
fi
cc_cr_args+=( $(write_existing_args CC_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_du_args=()
OLDIFS=$IFS;IFS=,
if [ -n "$CC_BRANCH" ];
then
cc_du_args+=( " --branch " "${CC_BRANCH}" )
fi
if [ -n "$CC_BUILD" ];
then
cc_du_args+=( " --build " "${CC_BUILD}" )
fi
if [ -n "$CC_BUILD_URL" ];
then
cc_du_args+=( " --build-url " "${CC_BUILD_URL}" )
fi
if [ -n "$CC_CODE" ];
then
cc_du_args+=( " --code " "${CC_CODE}" )
fi
if [ "$CC_DISABLE_FILE_FIXES" = "true" ];
then
cc_du_args+=( " --disable-file-fixes" )
fi
if [ "$CC_DISABLE_SEARCH" = "true" ];
then
cc_du_args+=( " --disable-search" )
fi
if [ "$CC_DRY_RUN" = "true" ];
then
cc_du_args+=( " --dry-run" )
fi
if [ -n "$CC_ENV" ];
then
cc_du_args+=( " --env " "${CC_ENV}" )
fi
if [ -n "$CC_EXCLUDE_DIRS" ];
then
for directory in $CC_EXCLUDE_DIRS; do
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+=( $(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) )
cc_du_args+=( $(write_existing_args CC_ENV) )
if [ -n "$CC_EXCLUDES" ];
then
for directory in $CC_EXCLUDES; do
cc_du_args+=( " --exclude " "$directory" )
done
fi
if [ "$CC_FAIL_ON_ERROR" = "true" ];
then
cc_du_args+=( " --fail-on-error" )
fi
cc_du_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
if [ -n "$CC_FILES" ];
then
for file in $CC_FILES; do
Expand All @@ -209,64 +151,24 @@ then
cc_du_args+=( " --flag " "$flag" )
done
fi
if [ -n "$CC_GIT_SERVICE" ];
then
cc_du_args+=( " --git-service " "${CC_GIT_SERVICE}" )
fi
if [ "$CC_HANDLE_NO_REPORTS_FOUND" = "true" ];
then
cc_du_args+=( " --handle-no-reports-found" )
fi
if [ -n "$CC_JOB_CODE" ];
then
cc_du_args+=( " --job-code " "${CC_JOB_CODE}" )
fi
if [ "$CC_LEGACY" = "true" ];
then
cc_du_args+=( " --legacy" )
fi
if [ -n "$CC_NAME" ];
then
cc_du_args+=( " --name " "${CC_NAME}" )
fi
if [ -n "$CC_NETWORK_FILTER" ];
then
cc_du_args+=( " --network-filter " "${CC_NETWORK_FILTER}" )
fi
if [ -n "$CC_NETWORK_PREFIX" ];
then
cc_du_args+=( " --network-prefix " "${CC_NETWORK_PREFIX}" )
fi
if [ -n "$CC_NETWORK_ROOT_FOLDER" ];
then
cc_du_args+=( " --network-root-folder " "${CC_NETWORK_ROOT_FOLDER}" )
fi
cc_du_args+=( $(write_existing_args CC_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+=( $(write_truthy_args CC_LEGACY) )
cc_du_args+=( $(write_existing_args CC_NAME) )
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) )
if [ -n "$CC_PLUGINS" ];
then
for plugin in $CC_PLUGINS; do
cc_du_args+=( " --plugin " "$plugin" )
done
fi
if [ -n "$CC_PULL_REQUEST" ];
then
cc_du_args+=( " --pr " "${CC_PULL_REQUEST}" )
fi
if [ -n "$CC_REPORT_TYPE" ];
then
cc_du_args+=( " --report-type " "${CC_REPORT_TYPE}" )
fi
if [ -n "$CC_SEARCH_DIR" ];
then
cc_du_args+=( " --coverage-files-search-root-folder " "${CC_SEARCH_DIR}" )
fi
if [ -n "$CC_SHA" ];
then
cc_du_args+=( " --sha " "${CC_SHA}" )
fi
if [ -n "$CC_SLUG" ];
then
cc_du_args+=( " --slug " "${CC_SLUG}" )
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) )
IFS=$OLDIFS
unset NODE_OPTIONS
# See https://github.com/codecov/uploader/issues/475
Expand Down
38 changes: 38 additions & 0 deletions env
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

CC_AUTO_LOAD_PARAMS_FROM
CC_BINARY
CC_BRANCH
CC_BUILD
CC_BUILD_URL
CC_CODE
CC_DIR
CC_DISABLE_FILE_FIXES
CC_DISABLE_SEARCH
CC_DRY_RUN
CC_ENTERPRISE_URL
CC_ENV
CC_EXCLUDES
CC_FAIL_ON_ERROR
CC_FILES
CC_FLAGS
CC_GIT_SERVICE
CC_HANDLE_NO_REPORTS_FOUND
CC_JOB_CODE
CC_LEGACY
CC_NAME
CC_NETWORK_FILTER
CC_NETWORK_PREFIX
CC_NETWORK_ROOT_FOLDER
CC_PARENT_SHA
CC_PLUGINS
CC_PR
CC_PUBLIC_PGP_KEY
CC_REPORT_TYPE
CC_SHA
CC_SKIP_VALIDATION
CC_SLUG
CC_TOKEN
CC_TOKEN_VAR
CC_VERSION
CC_WRAPPER_VERSION
CC_YML_PATH
12 changes: 12 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@ def package_scripts(source_dir, source_root, outfile):
cwd = os.getcwd()
lines = _parse(os.path.join(cwd, source_dir, source_root))

cc_vars = set()
with open(outfile, 'w') as f:
f.write(BASH_LINE)
for line in lines:
cc_vars.update(_get_vars(line))
f.write(line)

st = os.stat(outfile)
os.chmod(outfile, st.st_mode | stat.S_IEXEC)

with open('env', 'w') as f:
sorted_vars = sorted(list(cc_vars))
for var in sorted_vars:
f.write(f'{var}\n')

print(f"Current script is {len(''.join(lines))} chars.")
if len(''.join(lines)) > 8192:
print("Due to windows limitiations, script must be under 8192 chars.")
exit(1)

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

def _parse(file):
lines = []
with open(file, 'r') as f:
Expand Down
Empty file added scripts/envs
Empty file.
19 changes: 3 additions & 16 deletions scripts/set_cli_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@

codecov_cli_args=()

if [ -n "$CODECOV_AUTO_LOAD_PARAMS_FROM" ];
then
codecov_cli_args+=( " --auto-load-params-from " "${CODECOV_AUTO_LOAD_PARAMS_FROM}" )
fi

if [ -n "$CODECOV_ENTERPRISE_URL" ];
then
codecov_cli_args+=( " --enterprise-url " "${CODECOV_ENTERPRISE_URL}" )
fi

unset CODECOV_YML_PATH
if [ -n "$CODECOV_YML_PATH" ];
then
codecov_cli_args+=( " --codecov-yml-path " "${CODECOV_YML_PATH}" )
fi

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) )
35 changes: 6 additions & 29 deletions scripts/set_create_commit_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,9 @@

codecov_cc_args=()

if [ "$CODECOV_FAIL_ON_ERROR" = "true" ];
then
codecov_cc_args+=( " --fail-on-error" )
fi

if [ -n "$CODECOV_GIT_SERVICE" ];
then
codecov_cc_args+=( " --git-service " "${CODECOV_GIT_SERVICE}" )
fi

if [ -n "$CODECOV_PARENT_SHA" ];
then
codecov_cc_args+=( " --parent-sha " "${CODECOV_PARENT_SHA}" )
fi

if [ -n "$CODECOV_PULL_REQUEST" ];
then
codecov_cc_args+=( " --pr " "${CODECOV_PULL_REQUEST}" )
fi

if [ -n "$CODECOV_SHA" ];
then
codecov_cc_args+=( " --sha " "${CODECOV_SHA}" )
fi

if [ -n "$CODECOV_SLUG" ];
then
codecov_cc_args+=( " --slug " "${CODECOV_SLUG}" )
fi
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) )
Loading

0 comments on commit 3a22531

Please sign in to comment.