Skip to content

Commit

Permalink
feat: add create commit args
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov committed Oct 2, 2024
1 parent f492793 commit 3e23447
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
run: ./run.sh
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_FAIL_ON_ERROR: true

10 changes: 5 additions & 5 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,20 @@ 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}"
say "$g==>$x Finishing downloading $b${codecov_os}:${CODECOV_VERSION}$x"
echo ""
7 changes: 7 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env bash

CODECOV_YML_PATH="codecov.yml"

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

. ./set_cli_args.sh
. ./set_create_commit_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
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 /
\\_____\\___/ \\__,_|\\___|\\___\\___/ \\_/
Wrapper-$CODECOV_WRAPPER_VERSION
"

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
49 changes: 16 additions & 33 deletions upload.sh
Original file line number Diff line number Diff line change
@@ -1,58 +1,41 @@
#!/usr/bin/env bash

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

chmod +x $codecov_filename
[ -n "${CODECOV_FILE}" ] && \
set - "${@}" "-f" "${CODECOV_FILE}"
[ -n "${CODECOV_UPLOAD_ARGS}" ] && \
set - "${@}" "${CODECOV_UPLOAD_ARGS}"

FLAGS=""
OLDIFS=$IFS;IFS=,
for flag in $CODECOV_FLAGS; do
eval e="\$$flag"
for param in "${e}" "${flag}"; do
if [ -n "${param}" ]; then
if [ -n "${FLAGS}" ]; then
FLAGS="${FLAGS},${param}"
else
FLAGS="${param}"
fi
break
fi
done
done
IFS=$OLDIFS

if [ -n "$FLAGS" ]; then
FLAGS="-F ${FLAGS}"
fi

token="$(eval echo $CODECOV_TOKEN)"
say "$g ->$x Token of length ${#token} detected"

#create commit
echo "./\"$codecov_filename\" ${CODECOV_CLI_ARGS} create-commit -t $CODECOV_TOKEN"
say "$g==>$x Running create-commit"
say " $b./$codecov_filename$codecov_cli_args create-commit$codecov_create_commit_args$x"

./$codecov_filename \
${CODECOV_CLI_ARGS} \
$codecov_cli_args \
create-commit \
-t "$(eval echo $CODECOV_TOKEN)" \
${CODECOV_COMMIT_ARGS}
-t $token \
$codecov_create_commit_args

say

#create report
echo "./\"$codecov_filename\" ${CODECOV_CLI_ARGS} create-report -t <redacted>"
say "./\"$codecov_filename\" $codecov_cli_args create-report -t <redacted>"

./$codecov_filename \
${CODECOV_CLI_ARGS} \
$codecov_cli_args \
create-report \
-t "$(eval echo $CODECOV_TOKEN)" \
${CODECOV_REPORT_ARGS}

#upload reports
# alpine doesn't allow for indirect expansion

echo "./${codecov_filename} ${CODECOV_CLI_ARGS} do-upload -Z -t <redacted> ${CODECOV_UPLOAD_ARGS} ${@}"
say "./${codecov_filename} $codecov_cli_args do-upload -Z -t <redacted> ${CODECOV_UPLOAD_ARGS} ${@}"

./$codecov_filename \
${CODECOV_CLI_ARGS} \
$codecov_cli_args \
do-upload \
-Z \
-t "$(eval echo $CODECOV_TOKEN)" \
Expand Down
23 changes: 18 additions & 5 deletions validate.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#!/usr/bin/env bash

echo "${CODECOV_PUBLIC_PGP_KEY}" | \
gpg --no-default-keyring --import
# One-time step
say "$g==>$x Verifying GPG signature integrity"
sha_url="https://cli.codecov.io"
sha_url="${sha_url}/${codecov_version}/${codecov_os}"
sha_url="${sha_url}/${codecov_filename}.SHA256SUM"
echo "Downloading ${sha_url}"
say "$g ->$x Downloading $b${sha_url}$x"
say "$g ->$x Downloading $b${sha_url}.sig$x"
say ""
curl -Os "$sha_url"
curl -Os "${sha_url}.sig"

gpg --verify "${codecov_filename}.SHA256SUM.sig" "${codecov_filename}.SHA256SUM"
shasum -a 256 -c "${codecov_filename}.SHA256SUM" || \
sha256sum -c "${codecov_filename}.SHA256SUM"
echo ""
if ! gpg --verify "${codecov_filename}.SHA256SUM.sig" "${codecov_filename}.SHA256SUM";
then
exit_if_error "Could not verify signature. Please contact Codecov if problem continues"
fi

if ! shasum -a 256 -c "${codecov_filename}.SHA256SUM" && \
! sha256sum -c "${codecov_filename}.SHA256SUM";
then
exit_if_error "Could not verify SHASUM. Please contact Codecov if problem continues"
fi
say "$g==>$x CLI integrity verified"
say

0 comments on commit 3e23447

Please sign in to comment.