Skip to content

Commit

Permalink
Merge pull request #2 from robzr/dev
Browse files Browse the repository at this point in the history
add home-brew, update to v1.0.0
  • Loading branch information
robzr committed Feb 22, 2024
2 parents 7becbab + 37554ac commit 4799c90
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_<command>[_<subcommand>]`, ie: `sver_version`,
Expand All @@ -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
23 changes: 23 additions & 0 deletions homebrew/make.sh
Original file line number Diff line number Diff line change
@@ -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_
15 changes: 15 additions & 0 deletions homebrew/sver.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion sver
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4799c90

Please sign in to comment.