Skip to content

Commit

Permalink
Add prefix with :: for sourced utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
undergroundwires committed Feb 4, 2022
1 parent 0d9f50b commit 4a6e343
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 63 deletions.
12 changes: 6 additions & 6 deletions scripts/bump-and-tag-version.sh
Expand Up @@ -42,7 +42,7 @@ increase_patch_version() {
is_latest_commit_tagged() {
local latest_commit
if ! latest_commit=$(git rev-parse HEAD) \
|| ! has_value "$latest_commit"; then
|| ! utilities::has_value "$latest_commit"; then
echo "Could not read latest commit"
exit 1
fi
Expand All @@ -51,18 +51,18 @@ is_latest_commit_tagged() {
echo "Could not check the tags of the commit $latest_commit"
exit 1
fi
if ! has_value "$tag_of_latest_commit"; then
if ! utilities::has_value "$tag_of_latest_commit"; then
return 1;
fi
if ! is_valid_semantic_version_string "$tag_of_latest_commit"; then
if ! utilities::is_valid_semantic_version_string "$tag_of_latest_commit"; then
echo "Latest commit tag \"$tag_of_latest_commit\" in commit \"$latest_commit\" is not a version string"
exit 1
fi
return 0
}

main() {
if ! repository_has_any_tags; then
if ! utilities::repository_has_any_tags; then
echo "No tag is present in the repository."
tag_and_push "$DEFAULT_VERSION"
exit 0
Expand All @@ -72,13 +72,13 @@ main() {
exit 0
fi
local last_version
if ! last_version=$(print_latest_version); then
if ! last_version=$(utilities::print_latest_version); then
echo "Could not retrieve latest version. $last_version"
exit 1
fi
local new_version
if ! new_version=$(increase_patch_version "$last_version") \
|| is_empty_or_null "$new_version"; then
|| utilities::is_empty_or_null "$new_version"; then
echo "Could not increase the version"
exit 1
fi
Expand Down
22 changes: 11 additions & 11 deletions scripts/bump-everywhere.sh
Expand Up @@ -36,7 +36,7 @@ clone () {
echo "Cloning $repository"
local temp_directory
if ! temp_directory=$(mktemp -d) \
|| is_empty_or_null "$temp_directory"; then
|| utilities::is_empty_or_null "$temp_directory"; then
echo "Could not create a temporary directory"
exit 1;
fi
Expand All @@ -46,7 +46,7 @@ clone () {
|| { echo "Could not locate folder $temp_directory"; exit 1; }
local latest_commit_sha
if ! latest_commit_sha=$(git log -1 --format="%H") \
|| is_empty_or_null "$latest_commit_sha"; then
|| utilities::is_empty_or_null "$latest_commit_sha"; then
echo "Could not retrieve latest commit sha"
exit 1
fi
Expand Down Expand Up @@ -95,7 +95,7 @@ create_changelog() {
local -r repository="$1"
local logs
if ! logs=$(bash "$SCRIPTS_DIRECTORY/print-changelog.sh" --repository "$repository") \
|| is_empty_or_null "$logs"; then
|| utilities::is_empty_or_null "$logs"; then
printf "print-changelog.sh has failed\n%s" "$logs"
exit 1;
fi
Expand All @@ -121,7 +121,7 @@ has_uncommited_changes() {
echo "git status has failed";
exit 1;
fi
if is_empty_or_null "$status"; then return 0; else return 1; fi
if utilities::is_empty_or_null "$status"; then return 0; else return 1; fi
}

commit_and_push() {
Expand Down Expand Up @@ -149,12 +149,12 @@ create_release() {

validate_parameters() {
local -r repository="$1" git_user="$2" git_token="$3" release_type="$4" release_token="$5" commit_message="$6"
if is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if is_empty_or_null "$git_user"; then echo "Git user is not set."; exit 1; fi;
if is_empty_or_null "$git_token"; then echo "Git access token is not set."; exit 1; fi;
if is_empty_or_null "$release_type"; then echo "Release type is not set."; exit 1; fi;
if is_empty_or_null "$release_token"; then echo "Release access token is not set."; exit 1; fi;
if is_empty_or_null "$commit_message"; then echo "Commit message is not set."; exit 1; fi;
if utilities::is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if utilities::is_empty_or_null "$git_user"; then echo "Git user is not set."; exit 1; fi;
if utilities::is_empty_or_null "$git_token"; then echo "Git access token is not set."; exit 1; fi;
if utilities::is_empty_or_null "$release_type"; then echo "Release type is not set."; exit 1; fi;
if utilities::is_empty_or_null "$release_token"; then echo "Release access token is not set."; exit 1; fi;
if utilities::is_empty_or_null "$commit_message"; then echo "Commit message is not set."; exit 1; fi;
}

main() {
Expand All @@ -170,7 +170,7 @@ main() {
update_readme
create_changelog "$repository"
local version_tag
if ! version_tag="$(print_latest_version)"; then
if ! version_tag="$(utilities::print_latest_version)"; then
echo "Could not retrieve latest version. $version_tag"
exit 1
fi
Expand Down
4 changes: 2 additions & 2 deletions scripts/bump-npm-version.sh
Expand Up @@ -39,14 +39,14 @@ bump_npm_package_version() {

main() {
local new_version
if ! new_version=$(print_latest_version); then
if ! new_version=$(utilities::print_latest_version); then
echo "Could not retrieve the new version. $new_version"
exit 1;
fi
local -r -a file_names=('package.json' 'package-lock.json')
for file_name in "${file_names[@]}"
do
if ! file_exists "$file_name"; then
if ! utilities::file_exists "$file_name"; then
echo "Skipping.. No $file_name file exists."
continue
fi
Expand Down
8 changes: 4 additions & 4 deletions scripts/bump-readme-versions.sh
Expand Up @@ -38,17 +38,17 @@ file_content_contains() {
}

main() {
if has_single_version; then
if utilities::has_single_version; then
echo "Skipping.. There were no versions before."
return 0
fi
local version_before
if ! version_before=$(print_previous_version); then
if ! version_before=$(utilities::print_previous_version); then
echo "Could not get the version before. $version_before"
exit 1;
fi
local -r file_name="README.md"
if ! file_exists "$file_name"; then
if ! utilities::file_exists "$file_name"; then
echo "Skipping.. No $file_name file exists."
exit 0;
fi
Expand All @@ -57,7 +57,7 @@ main() {
exit 0;
fi
local new_version
if ! new_version=$(print_latest_version); then
if ! new_version=$(utilities::print_latest_version); then
echo "Could not retrieve the new version. $new_version"
exit 1;
fi
Expand Down
6 changes: 3 additions & 3 deletions scripts/configure-github-repo.sh
Expand Up @@ -36,9 +36,9 @@ set_user() {

validate_parameters() {
local -r repository="$1" access_token="$2" git_user="$3"
if is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if is_empty_or_null "$access_token"; then echo "Access token is not set."; exit 1; fi;
if is_empty_or_null "$git_user"; then echo "Git user is not set."; exit 1; fi;
if utilities::is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if utilities::is_empty_or_null "$access_token"; then echo "Access token is not set."; exit 1; fi;
if utilities::is_empty_or_null "$git_user"; then echo "Git user is not set."; exit 1; fi;
}

main() {
Expand Down
22 changes: 11 additions & 11 deletions scripts/create-github-release.sh
Expand Up @@ -52,12 +52,12 @@ release_exists() {

print_release_notes() {
local -r version="$1" repository="$2"
if has_single_version; then
if utilities::has_single_version; then
echo "Initial release"
return 0
fi
local version_before
if ! version_before=$(print_previous_version); then
if ! version_before=$(utilities::print_previous_version); then
echo "Could not get the previous version. $version_before"
exit 1
fi
Expand All @@ -69,7 +69,7 @@ print_release_notes() {
echo "$LOG_COMMITS_SCRIPT_PATH has failed"
exit 1;
fi
if ! is_empty_or_null "$changes"; then
if ! utilities::is_empty_or_null "$changes"; then
printf "%s\n\n" "$changes"
fi
printf "[compare](https://github.com/%s/compare/%s...%s)" \
Expand Down Expand Up @@ -105,15 +105,15 @@ create_release() {
--fail
}

is_release_type_draft() { equals_case_insensitive "$1" "draft"; }
is_release_type_none() { equals_case_insensitive "$1" "none"; }
is_release_type_prerelease() { equals_case_insensitive "$1" "prerelease"; }
is_release_type_release() { equals_case_insensitive "$1" "release"; }
is_release_type_draft() { utilities::equals_case_insensitive "$1" "draft"; }
is_release_type_none() { utilities::equals_case_insensitive "$1" "none"; }
is_release_type_prerelease() { utilities::equals_case_insensitive "$1" "prerelease"; }
is_release_type_release() { utilities::equals_case_insensitive "$1" "release"; }

validate_parameters() {
local repository="$1" access_token="$2" release_type="$3"
if is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if is_empty_or_null "$release_type"; then echo "Release type is not set."; exit 1; fi;
if utilities::is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if utilities::is_empty_or_null "$release_type"; then echo "Release type is not set."; exit 1; fi;
if ! (is_release_type_draft "$release_type" \
|| is_release_type_none "$release_type" \
|| is_release_type_prerelease "$release_type" \
Expand All @@ -122,7 +122,7 @@ validate_parameters() {
exit 1;
fi;
if (! is_release_type_none "$release_type") \
&& is_empty_or_null "$access_token"; then
&& utilities::is_empty_or_null "$access_token"; then
echo "Access token is not set.";
exit 1;
fi;
Expand All @@ -136,7 +136,7 @@ main() {
exit 0;
fi;
local latest_version
if ! latest_version=$(print_latest_version); then
if ! latest_version=$(utilities::print_latest_version); then
echo "Could not get the latest version. $latest_version"
exit 1;
fi
Expand Down
12 changes: 6 additions & 6 deletions scripts/print-changelog.sh
Expand Up @@ -25,7 +25,7 @@ print_title() {
local -r tag="$1"
local tag_date
if ! tag_date=$(git log -1 --pretty=format:'%ad' --date=short "$tag") \
|| is_empty_or_null "$tag_date"; then
|| utilities::is_empty_or_null "$tag_date"; then
echo "Cannot get tag date for $tag"
exit 1
fi
Expand Down Expand Up @@ -85,20 +85,20 @@ print_first_tag() {
local -r repository="$1"
local first_tag
if ! first_tag=$(print_first_version) \
|| is_empty_or_null "$first_tag"; then
|| utilities::is_empty_or_null "$first_tag"; then
echo "Cannot get the first tag"
exit 1
fi
print_title "$first_tag"
local first_commit_with_tag_sha
if ! first_commit_with_tag_sha=$(print_commit_sha_of_tag "$first_tag") \
|| is_empty_or_null "$first_commit_with_tag_sha"; then
|| utilities::is_empty_or_null "$first_commit_with_tag_sha"; then
echo "Cannot get first commit with tag: $first_tag"
exit 1
fi
local initial_commit_sha
if ! initial_commit_sha=$(print_initial_commit_sha) \
|| is_empty_or_null "$initial_commit_sha"; then
|| utilities::is_empty_or_null "$initial_commit_sha"; then
echo "Cannot get initial commit";
exit 1;
fi
Expand All @@ -115,7 +115,7 @@ print_first_tag() {
echo "$LOG_COMMITS_SCRIPT_PATH has failed"
exit 1;
fi
if ! is_empty_or_null "$changes"; then
if ! utilities::is_empty_or_null "$changes"; then
printf "%s\n" "$changes"
fi
printf "[compare](https://github.com/%s/compare/%s...%s)" \
Expand All @@ -124,7 +124,7 @@ print_first_tag() {

main() {
local -r repository="$1"
if is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
if utilities::is_empty_or_null "$repository"; then echo "Repository name is not set."; exit 1; fi;
printf "# Changelog\n"
print_tags_except_first "$repository"
print_first_tag "$repository"
Expand Down
8 changes: 4 additions & 4 deletions scripts/shared/log-commits.sh
Expand Up @@ -20,12 +20,12 @@ while [[ "$#" -gt 0 ]]; do case $1 in
*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done

is_empty_or_null() { local -r text="$1"; [[ -z "$text" ]]; }
utilities::is_empty_or_null() { local -r text="$1"; [[ -z "$text" ]]; }

# Validate parameters
if is_empty_or_null "$CURRENT"; then echo "Current tag is missing"; exit 1; fi;
if is_empty_or_null "$PREVIOUS"; then echo "Previous tag is missing"; exit 1; fi;
if is_empty_or_null "$REPOSITORY"; then echo "Repository is missing"; exit 1; fi;
if utilities::is_empty_or_null "$CURRENT"; then echo "Current tag is missing"; exit 1; fi;
if utilities::is_empty_or_null "$PREVIOUS"; then echo "Previous tag is missing"; exit 1; fi;
if utilities::is_empty_or_null "$REPOSITORY"; then echo "Repository is missing"; exit 1; fi;

escape_regex() {
local -r text="$1"
Expand Down
32 changes: 16 additions & 16 deletions scripts/shared/utilities.sh
@@ -1,29 +1,29 @@
#!/usr/bin/env bash

has_value() {
utilities::has_value() {
local -r text="$1"
[[ -n "$text" ]]
}

is_empty_or_null() {
utilities::is_empty_or_null() {
local -r text="$1"
[[ -z "$text" ]]
}

count_tags() {
utilities::count_tags() {
git tag | wc -l
}

repository_has_any_tags() {
utilities::repository_has_any_tags() {
local -i total_tags
if ! total_tags=$(count_tags); then
if ! total_tags=$(utilities::count_tags); then
echo "Could not count tags"
exit 1
fi
[[ "$total_tags" -ne 0 ]]
}

is_valid_semantic_version_string() {
utilities::is_valid_semantic_version_string() {
local version="$1"
local -i -r MAX_LENGTH=256 # for package.json compatibility: https://github.com/npm/node-semver/blob/master/internal/constants.js
if (( ${#version} > MAX_LENGTH )); then
Expand All @@ -38,20 +38,20 @@ is_valid_semantic_version_string() {
}

# Prints latest version, exists with positive code if it cannot
print_latest_version() {
if ! repository_has_any_tags; then
utilities::print_latest_version() {
if ! utilities::repository_has_any_tags; then
exit 1;
fi
local -r latest_tag=$(git tag | sort -V | tail -1)
if ! is_valid_semantic_version_string "$latest_tag"; then
if ! utilities::is_valid_semantic_version_string "$latest_tag"; then
exit 1;
fi
echo "$latest_tag"
}

has_single_version() {
utilities::has_single_version() {
local -i total_tags
if ! total_tags=$(count_tags); then
if ! total_tags=$(utilities::count_tags); then
echo "Could not count tags"
exit 1
fi
Expand All @@ -62,9 +62,9 @@ has_single_version() {
}

# Prints latest version, exists with positive code if it cannot
print_previous_version() {
utilities::print_previous_version() {
local -i total_tags
if ! total_tags=$(count_tags); then
if ! total_tags=$(utilities::count_tags); then
echo "Could not count tags"
exit 1
fi
Expand All @@ -73,17 +73,17 @@ print_previous_version() {
exit 1;
fi
local -r previous_tag=$(git tag | sort -V | tail -2 | head -1)
if ! is_valid_semantic_version_string "$previous_tag"; then
if ! utilities::is_valid_semantic_version_string "$previous_tag"; then
exit 1;
fi
echo "$previous_tag"
}

file_exists() {
utilities::file_exists() {
local -r file=$1;
[[ -f $file ]];
}

equals_case_insensitive() {
utilities::equals_case_insensitive() {
[[ "${1,,}" = "${2,,}" ]];
}

0 comments on commit 4a6e343

Please sign in to comment.