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

Allow install beta #211

Merged
merged 13 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘πŸ»


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make senses to add header on the curl to track the version requested as well as the OS that is using?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
}
antonio-gg-dev marked this conversation as resolved.
Show resolved Hide resolved