Skip to content

Commit

Permalink
fix: enable install with and without git
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Oct 16, 2024
1 parent 4c33046 commit 1189834
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
25 changes: 21 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
# shellcheck disable=SC2155
# shellcheck disable=SC2164

function is_git_installed() {
command -v git > /dev/null 2>&1
}

function get_latest_tag() {
local repository_url=$1

git ls-remote --tags "$repository_url" |
awk '{print $2}' |
sed 's|^refs/tags/||' |
sort -Vr |
head -n 1
}

function build_and_install_beta() {
echo "> Downloading non-stable version: 'beta'"

if ! command -v git >/dev/null 2>&1; then
if ! is_git_installed; then
echo "Error: git is not installed." >&2
exit 1
fi
Expand All @@ -20,8 +34,7 @@ function build_and_install_beta() {
local beta_version=$(printf "(non-stable) beta after %s [%s] 🐍 #%s" \
"$LATEST_BASHUNIT_VERSION" \
"$(date +'%Y-%m-%d')" \
"$latest_commit"
)
"$latest_commit")

sed -i -e 's/BASHUNIT_VERSION=".*"/BASHUNIT_VERSION="'"$beta_version"'"/g' temp_bashunit/bin/bashunit
cp temp_bashunit/bin/bashunit ./
Expand Down Expand Up @@ -53,8 +66,12 @@ function install() {
DIR=${1-lib}
VERSION=${2-latest}

LATEST_BASHUNIT_VERSION="0.17.0"
BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit"
if is_git_installed; then
LATEST_BASHUNIT_VERSION="$(get_latest_tag "$BASHUNIT_GIT_REPO")"
else
LATEST_BASHUNIT_VERSION="0.17.0"
fi
TAG="$LATEST_BASHUNIT_VERSION"

cd "$(dirname "$0")"
Expand Down
12 changes: 12 additions & 0 deletions tests/acceptance/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ function set_up_before_script() {
TEST_ENV_FILE="./tests/acceptance/fixtures/.env.default"
}

function set_up() {
rm -f ./lib/bashunit
rm -f ./deps/bashunit
}

function tear_down() {
rm -f ./lib/bashunit
rm -f ./deps/bashunit
Expand All @@ -19,6 +24,7 @@ function test_install_downloads_the_latest_version() {
assert_string_starts_with "$(printf "> Downloading the latest version: '")" "$output"
assert_string_ends_with "$(printf "\n> bashunit has been installed in the 'lib' folder")" "$output"
assert_file_exists "$installed_bashunit"

assert_string_starts_with\
"$(printf "\e[1m\e[32mbashunit\e[0m - ")"\
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
Expand All @@ -33,6 +39,7 @@ function test_install_downloads_in_given_folder() {
assert_string_starts_with "$(printf "> Downloading the latest version: '")" "$output"
assert_string_ends_with "$(printf "\n> bashunit has been installed in the 'deps' folder")" "$output"
assert_file_exists "$installed_bashunit"

assert_string_starts_with\
"$(printf "\e[1m\e[32mbashunit\e[0m - ")"\
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
Expand All @@ -47,6 +54,7 @@ function test_install_downloads_the_given_version() {
assert_same\
"$(printf "> Downloading a concrete version: '0.9.0'\n> bashunit has been installed in the 'lib' folder")"\
"$output"

assert_file_exists "$installed_bashunit"

assert_same\
Expand All @@ -65,11 +73,15 @@ function test_install_downloads_the_non_stable_beta_version() {
assert_contains\
"$(printf "> Downloading non-stable version: 'beta'\n> bashunit has been installed in the 'deps' folder")"\
"$output"

assert_file_exists "$installed_bashunit"

assert_matches\
"$(printf "\(non-stable\) beta after ([0-9]+\.[0-9]+\.[0-9]+) \[2023-11-13\] 🐍 \#[a-fA-F0-9]{7}")"\
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"

assert_directory_not_exists "./deps/temp_bashunit"

file_count_of_deps_directory=$(find ./deps -mindepth 1 -maxdepth 1 -print | wc -l | tr -d ' ')
assert_same "$file_count_of_deps_directory" "1"
assert_same "$(find ./deps -name 'bashunit')" "./deps/bashunit"
Expand Down

0 comments on commit 1189834

Please sign in to comment.