Skip to content

Commit

Permalink
Merge pull request #31 from codecov/gio/logging-to-stderr
Browse files Browse the repository at this point in the history
redirect error messages to STDERR
  • Loading branch information
giovanni-guidini authored Dec 28, 2023
2 parents 8633d98 + 8b9bf39 commit bb85483
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions dist/codecov_ats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ say() {
echo -e "$1"
}

error() {
echo -e "${r}$*${e}" >&2
}

# Set up token variables
if [[ -n $INPUTS_CODECOV_TOKEN ]]; then
CODECOV_TOKEN=$INPUTS_CODECOV_TOKEN
fi
if [[ -z $CODECOV_TOKEN ]]; then
say "${r}Token not provided or could not be found in environment. Exiting${x}"
error "Token not provided or could not be found in environment. Exiting"
exit 1
else
say "$b==>$x Token of length ${#CODECOV_TOKEN} detected"
Expand All @@ -29,7 +32,7 @@ if [[ -n $INPUTS_CODECOV_STATIC_TOKEN ]]; then
CODECOV_STATIC_TOKEN=$INPUTS_CODECOV_STATIC_TOKEN
fi
if [[ -z $CODECOV_STATIC_TOKEN ]]; then
say "${r}Static token not provided or could not be found in environment. Exiting${x}"
error "Static token not provided or could not be found in environment. Exiting"
exit 1
else
say "$b==>$x Static token of length ${#CODECOV_STATIC_TOKEN} detected"
Expand Down Expand Up @@ -73,22 +76,22 @@ label_analysis_args=""
if $(codecovcli ${codecovcli_args}create-commit ${create_commit_args}-t ${CODECOV_TOKEN}); then
say "${g}Codecov: Successfully created commit record$x"
else
say "${r}Codecov: Failed to properly create commit$x"
error "Codecov: Failed to properly create commit"
exit 1
fi

if $(codecovcli ${codecovcli_args}create-report ${create_report_args}-t ${CODECOV_TOKEN}); then
say "${g}Codecov: Successfully created report record$x"
else
say "${r}Codecov: Failed to properly create report$x"
error "Codecov: Failed to properly create report"
exit 1
fi

codecovcli ${codecovcli_args}static-analysis ${static_analysis_args}--token ${CODECOV_STATIC_TOKEN}
if [[ $? == 0 ]]; then
say "${g}Codecov: Successfully ran static analysis$x"
else
say "${r}Codecov: Failed to run static analysis$x"
error "Codecov: Failed to run static analysis"
exit 1
fi

Expand All @@ -110,7 +113,7 @@ do
done

if [[ -z $response && -n $INPUTS_OVERRIDE_BASE_COMMIT ]]; then
say "${r}Codecov: Failed to run label analysis. Please select a different base commit.$x"
error "Codecov: Failed to run label analysis. Please select a different base commit."
exit 1
fi

Expand Down
15 changes: 9 additions & 6 deletions src/codecov_ats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ say() {
echo -e "$1"
}

error() {
echo -e "${r}$*${e}" >&2
}

# Set up token variables
if [[ -n $INPUTS_CODECOV_TOKEN ]]; then
CODECOV_TOKEN=$INPUTS_CODECOV_TOKEN
fi
if [[ -z $CODECOV_TOKEN ]]; then
say "${r}Token not provided or could not be found in environment. Exiting${x}"
error "Token not provided or could not be found in environment. Exiting"
exit 1
else
say "$b==>$x Token of length ${#CODECOV_TOKEN} detected"
Expand All @@ -29,7 +32,7 @@ if [[ -n $INPUTS_CODECOV_STATIC_TOKEN ]]; then
CODECOV_STATIC_TOKEN=$INPUTS_CODECOV_STATIC_TOKEN
fi
if [[ -z $CODECOV_STATIC_TOKEN ]]; then
say "${r}Static token not provided or could not be found in environment. Exiting${x}"
error "Static token not provided or could not be found in environment. Exiting"
exit 1
else
say "$b==>$x Static token of length ${#CODECOV_STATIC_TOKEN} detected"
Expand Down Expand Up @@ -73,22 +76,22 @@ label_analysis_args=""
if $(codecovcli ${codecovcli_args}create-commit ${create_commit_args}-t ${CODECOV_TOKEN}); then
say "${g}Codecov: Successfully created commit record$x"
else
say "${r}Codecov: Failed to properly create commit$x"
error "Codecov: Failed to properly create commit"
exit 1
fi

if $(codecovcli ${codecovcli_args}create-report ${create_report_args}-t ${CODECOV_TOKEN}); then
say "${g}Codecov: Successfully created report record$x"
else
say "${r}Codecov: Failed to properly create report$x"
error "Codecov: Failed to properly create report"
exit 1
fi

codecovcli ${codecovcli_args}static-analysis ${static_analysis_args}--token ${CODECOV_STATIC_TOKEN}
if [[ $? == 0 ]]; then
say "${g}Codecov: Successfully ran static analysis$x"
else
say "${r}Codecov: Failed to run static analysis$x"
error "Codecov: Failed to run static analysis"
exit 1
fi

Expand All @@ -110,7 +113,7 @@ do
done

if [[ -z $response && -n $INPUTS_OVERRIDE_BASE_COMMIT ]]; then
say "${r}Codecov: Failed to run label analysis. Please select a different base commit.$x"
error "Codecov: Failed to run label analysis. Please select a different base commit."
exit 1
fi

Expand Down

0 comments on commit bb85483

Please sign in to comment.