Skip to content

Commit

Permalink
Merge pull request #211 from TypedDevs/feat/210-allow-install-main
Browse files Browse the repository at this point in the history
Allow install beta
  • Loading branch information
khru authored Nov 9, 2023
2 parents 3c0658d + 2197c2f commit 21e9197
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Improve data provider output
- Add .env variable `DEFAULT_PATH`
- Improve duplicated function names output
- Allow installing (non-stable) beta using the installer

## [0.9.0](https://github.com/TypedDevs/bashunit/compare/0.8.0...0.9.0) - 2023-10-15

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ cat bashunit >> bin/temp.sh
grep -v '^source' bin/temp.sh > bin/bashunit
rm bin/temp.sh

chmod +x bin/bashunit
chmod u+x bin/bashunit

echo "Build complete. bashunit has been generated in the bin folder."
5 changes: 5 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ curl -s https://bashunit.typeddevs.com/install.sh | bash -s [dir] [version]
- `[dir]`: the destiny directory to save the executable bashunit; `lib` by default
- `[version]`: the [release](https://github.com/TypedDevs/bashunit/releases) to download, for instance `{{ pkg.version }}`; `latest` by default

::: tip
You can use `beta` as `[version]` to get the next non-stable preview release.
We try to keep it stable, but there is no promise that we won't change functions or their signatures without prior notice.
:::

::: tip
Committing (or not) this file to your project it's up to you. In the end, it is a dev dependency.
:::
Expand Down
31 changes: 25 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,38 @@ DIR=${1-lib}
VERSION=${2-latest}
TAG="$LATEST_BASHUNIT_VERSION"

function build_and_install_beta() {
echo "> Downloading non-stable version: 'beta'"
git clone --depth 1 --no-tags https://github.com/TypedDevs/bashunit temp_bashunit 2>/dev/null
cd temp_bashunit
./build.sh >/dev/null
cd ..
cp temp_bashunit/bin/bashunit ./
sed -i -e 's/BASHUNIT_VERSION=".*"/BASHUNIT_VERSION="(non-stable) beta"/g' bashunit
rm -rf temp_bashunit
}

function install() {
if [[ $VERSION != 'latest' ]]; then
TAG="$VERSION"
echo "> Downloading a concrete version: '$TAG'"
else
echo "> Downloading the latest version: '$TAG'"
fi

curl -L -O -J "https://github.com/TypedDevs/bashunit/releases/download/$TAG/bashunit" 2>/dev/null
chmod u+x "bashunit"
}

cd "$(dirname "$0")"
rm -f "$DIR"/bashunit
[ -d "$DIR" ] || mkdir "$DIR"
cd "$DIR"

if [[ $VERSION != 'latest' ]]; then
TAG="$VERSION"
echo "> Downloading a concrete version: '$TAG'"
if [[ $VERSION == 'beta' ]]; then
build_and_install_beta
else
echo "> Downloading the latest version: '$TAG'"
install
fi

curl -L -O -J "https://github.com/TypedDevs/bashunit/releases/download/$TAG/bashunit" 2>/dev/null
chmod u+x "bashunit"
echo "> bashunit has been installed in the '$DIR' folder"
34 changes: 25 additions & 9 deletions tests/acceptance/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,61 @@ function tear_down() {
}

function test_install_downloads_the_latest_version() {
local install_dir="./lib/bashunit"
local installed_bashunit="./lib/bashunit"
local output

output="$(./install.sh)"

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 "$install_dir"
assert_file_exists "$installed_bashunit"
assert_string_starts_with\
"$(printf "\e[1m\e[32mbashunit\e[0m - ")"\
"$("$install_dir" --env "$TEST_ENV_FILE" --version)"
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
}

function test_install_downloads_in_given_folder() {
local install_dir="./deps/bashunit"
local installed_bashunit="./deps/bashunit"
local output

output="$(./install.sh deps)"

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 "$install_dir"
assert_file_exists "$installed_bashunit"
assert_string_starts_with\
"$(printf "\e[1m\e[32mbashunit\e[0m - ")"\
"$("$install_dir" --env "$TEST_ENV_FILE" --version)"
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
}

function test_install_downloads_the_given_version() {
local install_dir="./lib/bashunit"
local installed_bashunit="./lib/bashunit"
local output

output="$(./install.sh lib 0.9.0)"

assert_equals\
"$(printf "> Downloading a concrete version: '0.9.0'\n> bashunit has been installed in the 'lib' folder")"\
"$output"
assert_file_exists "$install_dir"
assert_file_exists "$installed_bashunit"

assert_equals\
"$(printf "\e[1m\e[32mbashunit\e[0m - 0.9.0")"\
"$("$install_dir" --env "$TEST_ENV_FILE" --version)"
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
}

function test_install_downloads_the_non_stable_beta_version() {
local installed_bashunit="./deps/bashunit"
local output

output="$(./install.sh deps beta)"

assert_contains\
"$(printf "> Downloading non-stable version: 'beta'\n> bashunit has been installed in the 'deps' folder")"\
"$output"
assert_file_exists "$installed_bashunit"
assert_equals\
"$(printf "\e[1m\e[32mbashunit\e[0m - (non-stable) beta")"\
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
assert_directory_not_exists "./deps/temp_bashunit"
}

0 comments on commit 21e9197

Please sign in to comment.