Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add create commit args #5

Merged
merged 12 commits into from
Oct 2, 2024
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ jobs:
run: ./run.sh
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_FAIL_ON_ERROR: true
CODECOV_FLAGS: flag1,flag2

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__/
.py[oc]
codecov
codecov.SHA256SUM*
13 changes: 7 additions & 6 deletions download.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
echo "Codecov wrapper version: ${CODECOV_WRAPPER_VERSION}"
#!/usr/bin/env bash

family=$(uname -s | tr '[:upper:]' '[:lower:]')
codecov_os="windows"
Expand All @@ -9,20 +9,21 @@ codecov_os="windows"
osID=$(grep -e "^ID=" /etc/os-release | cut -c4-)
[[ $osID == "alpine" ]] && codecov_os="alpine"
[[ $(arch) == "aarch64" && $family == "linux" ]] && codecov_os+="-arm64"
echo "Detected ${codecov_os}"
say "$g==>$x Detected $b${codecov_os}$x"
export codecov_os=${codecov_os}
export codecov_version=${CODECOV_VERSION}

codecov_filename="codecov"
[[ $codecov_os == "windows" ]] && codecov_filename+=".exe"
export codecov_filename=${codecov_filename}
[[ $codecov_os == "macos" ]] && \
[[ $codecov_os == "macos" ]] && \
! command -v gpg 2>&1 >/dev/null && \
HOMEBREW_NO_AUTO_UPDATE=1 brew install gpg
codecov_url="https://cli.codecov.io"
codecov_url="$codecov_url/${CODECOV_VERSION}"
codecov_url="$codecov_url/${codecov_os}/${codecov_filename}"
echo "Downloading ${codecov_url}"
say "$g ->$x Downloading $b${codecov_url}$x"
curl -Os $codecov_url

echo "Finishing downloading CLI ${CODECOV_VERSION}"
echo ""
say "$g==>$x Finishing downloading $b${codecov_os}:${CODECOV_VERSION}$x"
say " "
9 changes: 9 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/usr/bin/env bash

CODECOV_FLAGS="meow,rawr"

. ./set_defaults.sh
. ./download.sh
. ./validate.sh

. ./set_cli_args.sh
. ./set_create_commit_args.sh
. ./set_create_report_args.sh
. ./set_do_upload_args.sh
. ./upload.sh
20 changes: 20 additions & 0 deletions set_cli_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

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

38 changes: 38 additions & 0 deletions set_create_commit_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

codecov_create_commit_args=()

if [ -n "$CODECOV_BRANCH" ];
then
codecov_create_commit_args+=( " --branch " "${CODECOV_BRANCH}" )
fi

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

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

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

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

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

if [ -n "$CODECOV_SLUG" ];
then
codecov_create_commit_args+=( " --slug " "${CODECOV_SLUG}" )
fi
33 changes: 33 additions & 0 deletions set_create_report_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

codecov_create_report_args=()

if [ -n "$CODECOV_CODE" ];
then
codecov_create_report_args+=( " --code " "${CODECOV_CODE}" )
fi

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

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

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

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

if [ -n "$CODECOV_SLUG" ];
then
codecov_create_report_args+=( " --slug " "${CODECOV_SLUG}" )
fi
48 changes: 32 additions & 16 deletions set_defaults.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
home_dir=$(bash -c "cd ~$(printf %q $USER) && pwd")
CODECOV_BASH_ENV="${CODECOV_BASH_ENV:-$home_dir/.bashrc}"
#!/usr/bin/env bash

CODECOV_WRAPPER_VERSION="0.0.1"
CODECOV_VERSION="${CODECOV_VERSION:-latest}"
CODECOV_UPLOAD_NAME="${CODECOV_UPLOAD_NAME:-$CIRCLE_BUILD_NUM}"

codecov_vars=(
CODECOV_WRAPPER_VERSION
CODECOV_VERSION
)
say() {
echo -e "$1"
}

exit_if_error() {
say "$r==> $1$x"
if [ $CODECOV_FAIL_ON_ERROR = true ];
then
say "$r Exiting...$x"
exit 1;
fi
}

echo "Running wrapper version $CODECOV_WRAPPER_VERSION"
for value in "${codecov_vars[@]}"
do
echo "==> \$$value=${!value}"
export $value=${!value}
done
b="\033[0;36m" # variables/constants
g="\033[0;32m" # info/debug
r="\033[0;31m" # errors
y="\033[0;33m" # warnings
x="\033[0m"

echo "Finishing setting env variables"
echo ""
say " _____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \\ / _\` |/ _ \\/ __/ _ \\ \\ / /
| |___| (_) | (_| | __/ (_| (_) \\ V /
\\_____\\___/ \\__,_|\\___|\\___\\___/ \\_/
$r Wrapper-$CODECOV_WRAPPER_VERSION$x
"

CODECOV_VERSION="${CODECOV_VERSION:-latest}"
CODECOV_FAIL_ON_ERROR="${CODECOV_FAIL_ON_ERROR:-false}"
say "$g ->$x$b CODECOV_VERSION$x = $CODECOV_VERSION"
say "$g ->$x$b CODECOV_FAIL_ON_ERROR$x = $CODECOV_FAIL_ON_ERROR"
say
145 changes: 145 additions & 0 deletions set_do_upload_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/usr/bin/env bash

codecov_do_upload_args=()

OLDIFS=$IFS;IFS=,

if [ -n "$CODECOV_BRANCH" ];
then
codecov_do_upload_args+=( " --branch " "${CODECOV_BRANCH}" )
fi

if [ -n "$CODECOV_BUILD" ];
then
codecov_do_upload_args+=( " --build " "${CODECOV_BUILD}" )
fi

if [ -n "$CODECOV_BUILD_URL" ];
then
codecov_do_upload_args+=( " --build-url " "${CODECOV_BUILD_URL}" )
fi

if [ -n "$CODECOV_CODE" ];
then
codecov_do_upload_args+=( " --code " "${CODECOV_CODE}" )
fi

if [ "$CODECOV_DISABLE_FILE_FIXES" = "true" ];
then
codecov_do_upload_args+=( " --disable-file-fixes" )
fi

if [ "$CODECOV_DISABLE_SEARCH" = "true" ];
then
codecov_do_upload_args+=( " --disable-search" )
fi

if [ "$CODECOV_DRY_RUN" = "true" ];
then
codecov_do_upload_args+=( " --dry-run" )
fi

if [ -n "$CODECOV_ENV" ];
then
codecov_do_upload_args+=( " --env " "${CODECOV_ENV}" )
fi

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

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

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

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

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

if [ "$CODECOV_HANDLE_NO_REPORTS_FOUND" = "true" ];
then
codecov_do_upload_args+=( " --handle-no-reports-found" )
fi

if [ -n "$CODECOV_JOB_CODE" ];
then
codecov_do_upload_args+=( " --job-code " "${CODECOV_JOB_CODE}" )
fi

if [ "$CODECOV_LEGACY" = "true" ];
then
codecov_do_upload_args+=( " --legacy" )
fi

if [ -n "$CODECOV_NAME" ];
then
codecov_do_upload_args+=( " --name " "${CODECOV_NAME}" )
fi

if [ -n "$CODECOV_NETWORK_FILTER" ];
then
codecov_do_upload_args+=( " --network-filter " "${CODECOV_NETWORK_FILTER}" )
fi

if [ -n "$CODECOV_NETWORK_PREFIX" ];
then
codecov_do_upload_args+=( " --network-prefix " "${CODECOV_NETWORK_PREFIX}" )
fi

if [ -n "$CODECOV_NETWORK_ROOT_FOLDER" ];
then
codecov_do_upload_args+=( " --network-root-folder " "${CODECOV_NETWORK_ROOT_FOLDER}" )
fi

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

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

if [ -n "$CODECOV_REPORT_TYPE" ];
then
codecov_do_upload_args+=( " --report-type " "${CODECOV_REPORT_TYPE}" )
fi

if [ -n "$CODECOV_SEARCH_DIR" ];
then
codecov_do_upload_args+=( " --coverage-files-search-root-folder " "${CODECOV_SEARCH_DIR}" )
fi

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

if [ -n "$CODECOV_SLUG" ];
then
codecov_do_upload_args+=( " --slug " "${CODECOV_SLUG}" )
fi

IFS=$OLDIFS
Loading
Loading