diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cbb8db0..6ec85f3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,6 +13,10 @@ jobs: pwd >> "$GITHUB_PATH" - run: sver version - run: tests/run_tests.sh + - run: | + # test Homebrew Formula + homebrew/make.sh + git diff --check - if: always() uses: actions/upload-artifact@v4 with: diff --git a/README.md b/README.md index 66ed1ad..c1bc53d 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ Semantic Version parsing and utility script and function library in pure bash ## Overview -`sver` is a self contained cli tool and function library implementing a Semantic -Versioning 2 [Semantic Versioning 2](https://semver.org) compliant parser and -utilities. Written in optimized, portable, pure bash (v3+) for simplicity & speed. +`sver` is a self contained cli tool and function library implementing a [Semantic +Versioning 2](https://semver.org) compliant parser and utilities. Written in +optimized, portable, pure bash (v3+) for simplicity & speed. ### Features - bump or get version identifiers (major, minor, patch, prerelease, build_metadata) @@ -75,7 +75,7 @@ Constraints: To use sver as a bash function library, source it with the `SVER_RUN=false` variable set. ```bash -SVER_RUN=false . ./sver +SVER_RUN=false . "$(command -v sver)" ``` The same commands and syntax are available as the CLI, but written as functions, with the syntax `sver_[_]`, ie: `sver_version`, @@ -86,7 +86,5 @@ Permissive [Creative Commons - CC BY 3.0](https://creativecommons.org/licenses/b license - same as Semantic Versioning itself. # TODO -- tests +- constraint testing - asdf plugin -- homebrew plugin -- github action diff --git a/homebrew/make.sh b/homebrew/make.sh new file mode 100755 index 0000000..5f3c211 --- /dev/null +++ b/homebrew/make.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +repo_path=$(git rev-parse --show-toplevel) +version=$(sed -n '/^SVER_VERSION=/s/.*=//p' "${repo_path}/sver") +sha256sum=$(shasum -a 256 "${repo_path}/sver" | cut -f1 -d\ ) + +cat <<_EOF_ >"${repo_path}/homebrew/sver.rb" +class Sver < Formula + desc "Semver (Semantic Version) parsing & utility script and function library in pure bash" + homepage "https://github.com/robzr/sver" + url "https://github.com/robzr/sver/releases/download/${version}/sver" + sha256 "${sha256sum}" + license "CC-BY-SA-3.0" + + def install + bin.install "sver" + end + + test do + assert_match "${version}", shell_output("#{bin}/sver version") + end +end +_EOF_ diff --git a/homebrew/sver.rb b/homebrew/sver.rb new file mode 100644 index 0000000..33fdeba --- /dev/null +++ b/homebrew/sver.rb @@ -0,0 +1,15 @@ +class Sver < Formula + desc "Semver (Semantic Version) parsing & utility script and function library in pure bash" + homepage "https://github.com/robzr/sver" + url "https://github.com/robzr/sver/releases/download/v1.0.0/sver" + sha256 "1f1c3b26e980f8b89d2c13030a63074b6af6784c067cd0e7f612d247d2384fa5" + license "CC-BY-SA-3.0" + + def install + bin.install "sver" + end + + test do + assert_match "v1.0.0", shell_output("#{bin}/sver version") + end +end diff --git a/sver b/sver index 1c2e66d..9e040d0 100755 --- a/sver +++ b/sver @@ -3,7 +3,7 @@ # shellcheck disable=SC1008,SC2015,SC2096 # shfmt -i 2 -ci -w -SVER_VERSION=v1.0.0-alpha +SVER_VERSION=v1.0.0 SVER_INTRO="\ sver ${SVER_VERSION} (https://github.com/robzr/sver) self contained cli tool and function library implementing a Semantic Versioning 2 compliant parser and utilities. @@ -501,6 +501,10 @@ if [ "${SVER_RUN:-true}" = true ]; then if [ $# = 0 ]; then COMP_WORDS=("" "help") else + if [[ "$1" =~ ^- ]]; then + echo "Error: Invalid argument syntax, run \"sver help\" for usage." >&2 + exit 1 + fi COMP_WORDS=("" "${@}") fi COMP_CWORD=1 diff --git a/tests/run_tests.sh b/tests/run_tests.sh index a3a75c2..e380f43 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -27,11 +27,11 @@ test_sort() { local random=$([ "$1" = "-r" ] && echo true || echo false) local sort_status=0 - presorted=$(sed 's/\+.*//') # filter out build metadata as it is not sorted + presorted=$(sed 's/\+.*//') # filter out build metadata as it is not sorted presorted_sha=$(_get_sha <<< "$presorted") cat > "sort-presorted-${presorted_sha}.txt" <<< "$presorted" - if $random ; then + if $random ; then unsorted=$(sort -R -t. -k1 -k2 -k3 <<< "$presorted") else unsorted=$(sort -rn -t. -k1 -k2 -k3 <<< "$presorted") @@ -47,14 +47,14 @@ test_sort() { cat > "sort-unsorted-${unsorted_sha}.txt" <<< "$unsorted" cat > "sort-sorted-${sorted_sha}.txt" <<< "$sorted" fi - + printf -- \ '- checking sort %s (%s) - %s\n' \ "$($random && echo "random" || echo "fixed")" \ "$unsorted_sha" \ "$([ "$sort_status" -eq 0 ] && echo 'passed.' || echo "failed ($sorted_sha)!")" - - return $sort_status + + return $sort_status } TESTS_JSON=$(mktemp) @@ -83,7 +83,7 @@ echo 'Testing sorts' sort_output=$(mktemp) test_sort <<< "$EXAMPLES_SORTED" & for ((x=0; x < 5; x++)) ; do - ( test_sort -r <<< "$EXAMPLES_SORTED" + ( test_sort -r <<< "$EXAMPLES_SORTED" echo $? > "${sort_output}.${x}" ) & done