Skip to content

Commit

Permalink
feat: add new commands for CLI usage
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov committed Jan 19, 2025
1 parent b795006 commit 063140d
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 121 deletions.
128 changes: 75 additions & 53 deletions dist/codecov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ say " _____ _
"
CC_VERSION="${CC_VERSION:-latest}"
CC_FAIL_ON_ERROR="${CC_FAIL_ON_ERROR:-false}"
CC_RUN_COMMAND="${CC_RUN_COMMAND:-upload-coverage}"
if [ -n "$CC_BINARY" ];
then
if [ -f "$CC_BINARY" ];
Expand Down Expand Up @@ -136,91 +137,112 @@ then
fi
cc_cli_args+=( $(write_truthy_args CC_DISABLE_TELEM) )
cc_cli_args+=( $(write_truthy_args CC_VERBOSE) )
cc_uc_args=()
if [ -n "$CC_TOKEN_VAR" ];
then
token="$(eval echo \$$CC_TOKEN_VAR)"
else
token="$(eval echo $CC_TOKEN)"
fi
say "$g ->$x Token of length ${#token} detected"
token_str=""
token_arg=()
if [ -n "$token" ];
then
token_str+=" -t <redacted>"
token_arg+=( " -t " "$token")
fi
if [ "$CC_RUN_COMMAND" == "upload-coverage" ]; then
cc_run_args=()
# Args for create commit
cc_uc_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
cc_uc_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_uc_args+=( $(k_arg PARENT_SHA) $(v_arg PARENT_SHA))
cc_uc_args+=( $(k_arg PR) $(v_arg PR))
cc_uc_args+=( $(k_arg SHA) $(v_arg SHA))
cc_uc_args+=( $(k_arg SLUG) $(v_arg SLUG))
cc_run_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
cc_run_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_run_args+=( $(k_arg PARENT_SHA) $(v_arg PARENT_SHA))
cc_run_args+=( $(k_arg PR) $(v_arg PR))
cc_run_args+=( $(k_arg SHA) $(v_arg SHA))
cc_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
# Args for create report
cc_uc_args+=( $(k_arg CODE) $(v_arg CODE))
cc_run_args+=( $(k_arg CODE) $(v_arg CODE))
# Args for do upload
cc_uc_args+=( $(k_arg ENV) $(v_arg ENV))
cc_run_args+=( $(k_arg ENV) $(v_arg ENV))
OLDIFS=$IFS;IFS=,
cc_uc_args+=( $(k_arg BRANCH) $(v_arg BRANCH))
cc_uc_args+=( $(k_arg BUILD) $(v_arg BUILD))
cc_uc_args+=( $(k_arg BUILD_URL) $(v_arg BUILD_URL))
cc_uc_args+=( $(k_arg DIR) $(v_arg DIR))
cc_uc_args+=( $(write_truthy_args CC_DISABLE_FILE_FIXES) )
cc_uc_args+=( $(write_truthy_args CC_DISABLE_SEARCH) )
cc_uc_args+=( $(write_truthy_args CC_DRY_RUN) )
cc_run_args+=( $(k_arg BRANCH) $(v_arg BRANCH))
cc_run_args+=( $(k_arg BUILD) $(v_arg BUILD))
cc_run_args+=( $(k_arg BUILD_URL) $(v_arg BUILD_URL))
cc_run_args+=( $(k_arg DIR) $(v_arg DIR))
cc_run_args+=( $(write_truthy_args CC_DISABLE_FILE_FIXES) )
cc_run_args+=( $(write_truthy_args CC_DISABLE_SEARCH) )
cc_run_args+=( $(write_truthy_args CC_DRY_RUN) )
if [ -n "$CC_EXCLUDES" ];
then
for directory in $CC_EXCLUDES; do
cc_uc_args+=( "--exclude" "$directory" )
cc_run_args+=( "--exclude" "$directory" )
done
fi
if [ -n "$CC_FILES" ];
then
for file in $CC_FILES; do
cc_uc_args+=( "--file" "$file" )
cc_run_args+=( "--file" "$file" )
done
fi
if [ -n "$CC_FLAGS" ];
then
for flag in $CC_FLAGS; do
cc_uc_args+=( "--flag" "$flag" )
cc_run_args+=( "--flag" "$flag" )
done
fi
cc_uc_args+=( $(k_arg GCOV_ARGS) $(v_arg GCOV_ARGS))
cc_uc_args+=( $(k_arg GCOV_EXECUTABLE) $(v_arg GCOV_EXECUTABLE))
cc_uc_args+=( $(k_arg GCOV_IGNORE) $(v_arg GCOV_IGNORE))
cc_uc_args+=( $(k_arg GCOV_INCLUDE) $(v_arg GCOV_INCLUDE))
cc_uc_args+=( $(write_truthy_args CC_HANDLE_NO_REPORTS_FOUND) )
cc_uc_args+=( $(k_arg JOB_CODE) $(v_arg JOB_CODE))
cc_uc_args+=( $(write_truthy_args CC_LEGACY) )
cc_run_args+=( $(k_arg GCOV_ARGS) $(v_arg GCOV_ARGS))
cc_run_args+=( $(k_arg GCOV_EXECUTABLE) $(v_arg GCOV_EXECUTABLE))
cc_run_args+=( $(k_arg GCOV_IGNORE) $(v_arg GCOV_IGNORE))
cc_run_args+=( $(k_arg GCOV_INCLUDE) $(v_arg GCOV_INCLUDE))
cc_run_args+=( $(write_truthy_args CC_HANDLE_NO_REPORTS_FOUND) )
cc_run_args+=( $(k_arg JOB_CODE) $(v_arg JOB_CODE))
cc_run_args+=( $(write_truthy_args CC_LEGACY) )
if [ -n "$CC_NAME" ];
then
cc_uc_args+=( "--name" "$CC_NAME" )
cc_run_args+=( "--name" "$CC_NAME" )
fi
cc_uc_args+=( $(k_arg NETWORK_FILTER) $(v_arg NETWORK_FILTER))
cc_uc_args+=( $(k_arg NETWORK_PREFIX) $(v_arg NETWORK_PREFIX))
cc_uc_args+=( $(k_arg NETWORK_ROOT_FOLDER) $(v_arg NETWORK_ROOT_FOLDER))
cc_run_args+=( $(k_arg NETWORK_FILTER) $(v_arg NETWORK_FILTER))
cc_run_args+=( $(k_arg NETWORK_PREFIX) $(v_arg NETWORK_PREFIX))
cc_run_args+=( $(k_arg NETWORK_ROOT_FOLDER) $(v_arg NETWORK_ROOT_FOLDER))
if [ -n "$CC_PLUGINS" ];
then
for plugin in $CC_PLUGINS; do
cc_uc_args+=( "--plugin" "$plugin" )
cc_run_args+=( "--plugin" "$plugin" )
done
fi
cc_uc_args+=( $(k_arg REPORT_TYPE) $(v_arg REPORT_TYPE))
cc_uc_args+=( $(k_arg SWIFT_PROJECT) $(v_arg SWIFT_PROJECT))
cc_run_args+=( $(k_arg REPORT_TYPE) $(v_arg REPORT_TYPE))
cc_run_args+=( $(k_arg SWIFT_PROJECT) $(v_arg SWIFT_PROJECT))
IFS=$OLDIFS
elif [ "$CC_RUN_COMMAND" == "empty-upload" ]; then
cc_run_args=()
cc_run_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
cc_run_args+=( $(write_truthy_args CC_FORCE) )
cc_run_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_run_args+=( $(k_arg SHA) $(v_arg SHA))
cc_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
elif [ "$CC_RUN_COMMAND" == "pr-base-picking" ]; then
cc_run_args=()
cc_run_args+=( $(k_arg BASE_SHA) $(v_arg BASE_SHA))
cc_run_args+=( $(k_arg PR) $(v_arg PR))
cc_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
cc_run_args+=( $(k_arg SERVICE) $(v_arg SERVICE))
elif [ "$CC_RUN_COMMAND" == "send-notifications" ]; then
cc_run_args=()
cc_run_args+=( $(k_arg SHA) $(v_arg SHA))
cc_run_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
cc_run_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
cc_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
fi
unset NODE_OPTIONS
# See https://github.com/codecov/uploader/issues/475
chmod +x $cc_command
if [ -n "$CC_TOKEN_VAR" ];
then
token="$(eval echo \$$CC_TOKEN_VAR)"
else
token="$(eval echo $CC_TOKEN)"
fi
say "$g ->$x Token of length ${#token} detected"
token_str=""
token_arg=()
if [ -n "$token" ];
then
token_str+=" -t <redacted>"
token_arg+=( " -t " "$token")
fi
say "$g==>$x Running upload-coverage"
say " $b$cc_command $(echo "${cc_cli_args[@]}") upload-coverage$token_str $(echo "${cc_uc_args[@]}")$x"
chmod +x "$cc_command"
say "$g==>$x Running $CC_RUN_COMMAND"
say " $b$cc_command $(echo "${cc_cli_args[@]}")$CC_RUN_COMMAND$token_str $(echo "${cc_run_args[@]}")$x"
if ! $cc_command \
${cc_cli_args[*]} \
upload-coverage \
${CC_RUN_COMMAND} \
${token_arg[*]} \
"${cc_uc_args[@]}";
"${cc_run_args[@]}";
then
exit_if_error "Failed to upload coverage"
exit_if_error "Failed to run $CC_RUN_COMMAND"
fi
4 changes: 4 additions & 0 deletions env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

CC_AUTO_LOAD_PARAMS_FROM
CC_BASE_SHA
CC_BINARY
CC_BINARY_LOCATION
CC_BRANCH
Expand All @@ -18,6 +19,7 @@ CC_EXCLUDES
CC_FAIL_ON_ERROR
CC_FILES
CC_FLAGS
CC_FORCE
CC_GCOV_ARGS
CC_GCOV_EXECUTABLE
CC_GCOV_IGNORE
Expand All @@ -36,6 +38,8 @@ CC_PLUGINS
CC_PR
CC_PUBLIC_PGP_KEY
CC_REPORT_TYPE
CC_RUN_COMMAND
CC_SERVICE
CC_SHA
CC_SKIP_VALIDATION
CC_SLUG
Expand Down
4 changes: 2 additions & 2 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
. ./validate.sh

. ./set_cli_args.sh
. ./set_upload_coverage_args.sh
. ./upload.sh
. ./set_token.sh
. ./run_command.sh
27 changes: 27 additions & 0 deletions scripts/run_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

if [ "$CODECOV_RUN_COMMAND" == "upload-coverage" ]; then
. ./set_upload_coverage_args.sh
elif [ "$CODECOV_RUN_COMMAND" == "empty-upload" ]; then
. ./set_empty_upload_args.sh
elif [ "$CODECOV_RUN_COMMAND" == "pr-base-picking" ]; then
. ./set_pr_base_picking_args.sh
elif [ "$CODECOV_RUN_COMMAND" == "send-notifications" ]; then
. ./set_send_notifications_args.sh
fi

unset NODE_OPTIONS
# See https://github.com/codecov/uploader/issues/475

chmod +x "$codecov_command"

say "$g==>$x Running $CODECOV_RUN_COMMAND"
say " $b$codecov_command $(echo "${codecov_cli_args[@]}")$CODECOV_RUN_COMMAND$token_str $(echo "${codecov_run_args[@]}")$x"
if ! $codecov_command \
${codecov_cli_args[*]} \
${CODECOV_RUN_COMMAND} \
${token_arg[*]} \
"${codecov_run_args[@]}";
then
exit_if_error "Failed to run $CODECOV_RUN_COMMAND"
fi
1 change: 1 addition & 0 deletions scripts/set_defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ say " _____ _

CODECOV_VERSION="${CODECOV_VERSION:-latest}"
CODECOV_FAIL_ON_ERROR="${CODECOV_FAIL_ON_ERROR:-false}"
CODECOV_RUN_COMMAND="${CODECOV_RUN_COMMAND:-upload-coverage}"
9 changes: 9 additions & 0 deletions scripts/set_empty_upload_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

codecov_run_args=()

codecov_run_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
codecov_run_args+=( $(write_truthy_args CODECOV_FORCE) )
codecov_run_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_run_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
8 changes: 8 additions & 0 deletions scripts/set_pr_base_picking_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

codecov_run_args=()

codecov_run_args+=( $(k_arg BASE_SHA) $(v_arg BASE_SHA))
codecov_run_args+=( $(k_arg PR) $(v_arg PR))
codecov_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
codecov_run_args+=( $(k_arg SERVICE) $(v_arg SERVICE))
8 changes: 8 additions & 0 deletions scripts/set_send_notifications_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

codecov_run_args=()

codecov_run_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_run_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
codecov_run_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_run_args+=( $(k_arg SLUG) $(v_arg SLUG))
17 changes: 17 additions & 0 deletions scripts/set_token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

if [ -n "$CODECOV_TOKEN_VAR" ];
then
token="$(eval echo \$$CODECOV_TOKEN_VAR)"
else
token="$(eval echo $CODECOV_TOKEN)"
fi

say "$g ->$x Token of length ${#token} detected"
token_str=""
token_arg=()
if [ -n "$token" ];
then
token_str+=" -t <redacted>"
token_arg+=( " -t " "$token")
fi
66 changes: 33 additions & 33 deletions scripts/set_upload_coverage_args.sh
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
#!/usr/bin/env bash

codecov_uc_args=()
codecov_run_args=()

# Args for create commit
codecov_uc_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
codecov_uc_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_uc_args+=( $(k_arg PARENT_SHA) $(v_arg PARENT_SHA))
codecov_uc_args+=( $(k_arg PR) $(v_arg PR))
codecov_uc_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_uc_args+=( $(k_arg SLUG) $(v_arg SLUG))
codecov_run_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
codecov_run_args+=( $(k_arg GIT_SERVICE) $(v_arg GIT_SERVICE))
codecov_run_args+=( $(k_arg PARENT_SHA) $(v_arg PARENT_SHA))
codecov_run_args+=( $(k_arg PR) $(v_arg PR))
codecov_run_args+=( $(k_arg SHA) $(v_arg SHA))
codecov_run_args+=( $(k_arg SLUG) $(v_arg SLUG))

# Args for create report
codecov_uc_args+=( $(k_arg CODE) $(v_arg CODE))
codecov_run_args+=( $(k_arg CODE) $(v_arg CODE))

# Args for do upload
codecov_uc_args+=( $(k_arg ENV) $(v_arg ENV))
codecov_run_args+=( $(k_arg ENV) $(v_arg ENV))

OLDIFS=$IFS;IFS=,

codecov_uc_args+=( $(k_arg BRANCH) $(v_arg BRANCH))
codecov_uc_args+=( $(k_arg BUILD) $(v_arg BUILD))
codecov_uc_args+=( $(k_arg BUILD_URL) $(v_arg BUILD_URL))
codecov_uc_args+=( $(k_arg DIR) $(v_arg DIR))
codecov_uc_args+=( $(write_truthy_args CODECOV_DISABLE_FILE_FIXES) )
codecov_uc_args+=( $(write_truthy_args CODECOV_DISABLE_SEARCH) )
codecov_uc_args+=( $(write_truthy_args CODECOV_DRY_RUN) )
codecov_run_args+=( $(k_arg BRANCH) $(v_arg BRANCH))
codecov_run_args+=( $(k_arg BUILD) $(v_arg BUILD))
codecov_run_args+=( $(k_arg BUILD_URL) $(v_arg BUILD_URL))
codecov_run_args+=( $(k_arg DIR) $(v_arg DIR))
codecov_run_args+=( $(write_truthy_args CODECOV_DISABLE_FILE_FIXES) )
codecov_run_args+=( $(write_truthy_args CODECOV_DISABLE_SEARCH) )
codecov_run_args+=( $(write_truthy_args CODECOV_DRY_RUN) )

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

if [ -n "$CODECOV_FILES" ];
then
for file in $CODECOV_FILES; do
codecov_uc_args+=( "--file" "$file" )
codecov_run_args+=( "--file" "$file" )
done
fi

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

codecov_uc_args+=( $(k_arg GCOV_ARGS) $(v_arg GCOV_ARGS))
codecov_uc_args+=( $(k_arg GCOV_EXECUTABLE) $(v_arg GCOV_EXECUTABLE))
codecov_uc_args+=( $(k_arg GCOV_IGNORE) $(v_arg GCOV_IGNORE))
codecov_uc_args+=( $(k_arg GCOV_INCLUDE) $(v_arg GCOV_INCLUDE))
codecov_uc_args+=( $(write_truthy_args CODECOV_HANDLE_NO_REPORTS_FOUND) )
codecov_uc_args+=( $(k_arg JOB_CODE) $(v_arg JOB_CODE))
codecov_uc_args+=( $(write_truthy_args CODECOV_LEGACY) )
codecov_run_args+=( $(k_arg GCOV_ARGS) $(v_arg GCOV_ARGS))
codecov_run_args+=( $(k_arg GCOV_EXECUTABLE) $(v_arg GCOV_EXECUTABLE))
codecov_run_args+=( $(k_arg GCOV_IGNORE) $(v_arg GCOV_IGNORE))
codecov_run_args+=( $(k_arg GCOV_INCLUDE) $(v_arg GCOV_INCLUDE))
codecov_run_args+=( $(write_truthy_args CODECOV_HANDLE_NO_REPORTS_FOUND) )
codecov_run_args+=( $(k_arg JOB_CODE) $(v_arg JOB_CODE))
codecov_run_args+=( $(write_truthy_args CODECOV_LEGACY) )
if [ -n "$CODECOV_NAME" ];
then
codecov_uc_args+=( "--name" "$CODECOV_NAME" )
codecov_run_args+=( "--name" "$CODECOV_NAME" )
fi
codecov_uc_args+=( $(k_arg NETWORK_FILTER) $(v_arg NETWORK_FILTER))
codecov_uc_args+=( $(k_arg NETWORK_PREFIX) $(v_arg NETWORK_PREFIX))
codecov_uc_args+=( $(k_arg NETWORK_ROOT_FOLDER) $(v_arg NETWORK_ROOT_FOLDER))
codecov_run_args+=( $(k_arg NETWORK_FILTER) $(v_arg NETWORK_FILTER))
codecov_run_args+=( $(k_arg NETWORK_PREFIX) $(v_arg NETWORK_PREFIX))
codecov_run_args+=( $(k_arg NETWORK_ROOT_FOLDER) $(v_arg NETWORK_ROOT_FOLDER))

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

codecov_uc_args+=( $(k_arg REPORT_TYPE) $(v_arg REPORT_TYPE))
codecov_uc_args+=( $(k_arg SWIFT_PROJECT) $(v_arg SWIFT_PROJECT))
codecov_run_args+=( $(k_arg REPORT_TYPE) $(v_arg REPORT_TYPE))
codecov_run_args+=( $(k_arg SWIFT_PROJECT) $(v_arg SWIFT_PROJECT))

IFS=$OLDIFS
Loading

0 comments on commit 063140d

Please sign in to comment.