Skip to content

Commit 1a22e09

Browse files
Merge 5ab530b into 0de2233
2 parents 0de2233 + 5ab530b commit 1a22e09

File tree

1 file changed

+24
-43
lines changed

1 file changed

+24
-43
lines changed

codacy-cli.sh

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,28 @@ download_file() {
2929

3030
download() {
3131
local url="$1"
32-
local file_name="$2"
33-
local output_folder="$3"
34-
local output_filename="$4"
35-
local checksum_url="$5"
36-
local original_folder
37-
original_folder="$(pwd)"
32+
local output_folder="$2"
3833

39-
cd "$output_folder"
40-
41-
download_file "$url"
42-
# checksum "$file_name" "$checksum_url"
43-
44-
cd "$original_folder"
34+
( cd "$output_folder" && download_file "$url" )
4535
}
4636

47-
download_reporter() {
37+
download_cli() {
4838
# OS name lower case
4939
suffix=$(echo "$os_name" | tr '[:upper:]' '[:lower:]')
5040

51-
local binary_name="codacy-cli-v2-$suffix"
52-
local reporter_path="$1"
53-
local reporter_folder="$2"
54-
local reporter_filename="$3"
41+
local bin_folder="$1"
42+
local bin_path="$2"
5543

56-
if [ ! -f "$reporter_path" ]
57-
then
58-
echo "$i" "Downloading the codacy cli v2 $binary_name... ($CODACY_CLI_V2_VERSION)"
44+
if [ ! -f "$bin_path" ]; then
45+
echo "Downloading the codacy cli v2 version ($CODACY_CLI_V2_VERSION)"
5946

6047
remote_file="codacy-cli-v2_${CODACY_CLI_V2_VERSION}_${suffix}_${arch}.tar.gz"
61-
binary_url="https://github.com/codacy/codacy-cli-v2/releases/download/${CODACY_CLI_V2_VERSION}/${remote_file}"
62-
# echo $binary_url
63-
# checksum_url="https://github.com/codacy/codacy-coverage-reporter/releases/download/$CODACY_CLI_V2_VERSION/$binary_name.SHA512SUM"
64-
65-
download "$binary_url" "$binary_name" "$reporter_folder" "$reporter_filename" "$checksum_url"
48+
url="https://github.com/codacy/codacy-cli-v2/releases/download/${CODACY_CLI_V2_VERSION}/${remote_file}"
6649

67-
echo "${reporter_folder}/${remote_file}"
68-
tar xzfv "${reporter_folder}/${remote_file}" -C "${reporter_folder}"
50+
download "$url" "$bin_folder"
51+
tar xzfv "${bin_folder}/${remote_file}" -C "${bin_folder}"
6952
else
70-
echo "$i" "Codacy reporter $binary_name already in cache"
53+
echo "$i" "Codacy cli v2 $binary_name already in cache"
7154
fi
7255
}
7356

@@ -82,36 +65,34 @@ if [ -z "$CODACY_CLI_V2_TMP_FOLDER" ]; then
8265
fi
8366
fi
8467

85-
reporter_filename="codacy-cli-v2"
86-
8768
# if no version is specified, we fetch the latest
8869
if [ -z "$CODACY_CLI_V2_VERSION" ]; then
8970
CODACY_CLI_V2_VERSION="$(curl -Lq "https://api.github.com/repos/codacy/codacy-cli-v2/releases/latest" 2>/dev/null | grep -m 1 tag_name | cut -d'"' -f4)"
9071
echo "Fetching latest version: ${CODACY_CLI_V2_VERSION}"
9172
fi
9273

9374
# Folder containing the binary
94-
reporter_folder="$CODACY_CLI_V2_TMP_FOLDER"/"$CODACY_CLI_V2_VERSION"
75+
bin_folder="${CODACY_CLI_V2_TMP_FOLDER}/${CODACY_CLI_V2_VERSION}"
76+
# Create the folder if not exists
77+
mkdir -p "$bin_folder"
9578

96-
# Create the reporter folder if not exists
97-
mkdir -p "$reporter_folder"
79+
# name of the binary
80+
bin_name="codacy-cli-v2"
9881

9982
# Set binary path
100-
reporter_path="$reporter_folder"/"$reporter_filename"
101-
102-
download_reporter "$reporter_path" "$reporter_folder" "$reporter_filename"
83+
bin_path="$bin_folder"/"$bin_name"
10384

104-
chmod +x "$reporter_path"
105-
run_command="$reporter_path"
85+
# download the tool
86+
download_cli "$bin_folder" "$bin_path"
87+
chmod +x "$bin_path"
10688

107-
if [ -z "$run_command" ]
108-
then
89+
run_command="$bin_path"
90+
if [ -z "$run_command" ]; then
10991
fatal "Codacy cli v2 binary could not be found."
11092
fi
11193

112-
if [ "$#" -eq 1 ] && [ "$1" = "download" ];
113-
then
114-
echo "$g" "Codacy reporter download succeeded";
94+
if [ "$#" -eq 1 ] && [ "$1" = "download" ]; then
95+
echo "$g" "Codacy cli v2 download succeeded";
11596
else
11697
eval "$run_command $*"
11798
fi

0 commit comments

Comments
 (0)