-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
2,870 additions
and
2,464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"cSpell.words": [ | ||
"nocasematch", | ||
"Pids" | ||
] | ||
], | ||
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;'\",.<>/?" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env bash | ||
# author: github.com/jcaillon | ||
# description: This script can be sourced by commands to provide convenient functions. | ||
|
||
# shellcheck source=lib-string | ||
source string | ||
|
||
# ## version::compare | ||
# | ||
# This function allows to compare two semantic versions formatted like: | ||
# major.minor.patch-prerelease+build | ||
# | ||
# - $1: **version1** _as string_: | ||
# the first version to compare | ||
# - $2: **version2** _as string_: | ||
# the second version to compare | ||
# | ||
# Returns: | ||
# | ||
# - `RETURNED_VALUE`: | ||
# - 0 if the versions are equal, | ||
# - 1 if version1 is greater, | ||
# - -1 if version2 is greater | ||
# | ||
# ```bash | ||
# version::compare "2.3.4-prerelease+build" "1.2.3-prerelease+build" | ||
# local comparison="${RETURNED_VALUE}" | ||
# ``` | ||
# | ||
# > The prerelease and build are ignored in the comparison. | ||
function version::compare() { | ||
local version1="${1#v}" | ||
local version2="${2#v}" | ||
|
||
local -i semVerIndex | ||
local semVerNumber1 semVerNumber2 | ||
for semVerIndex in {0..2}; do | ||
string::cutField "${version1}" "${semVerIndex}" "." | ||
semVerNumber1="${RETURNED_VALUE%%-*}" | ||
semVerNumber1="${semVerNumber1%%+*}" | ||
string::cutField "${version2}" "${semVerIndex}" "." | ||
semVerNumber2="${RETURNED_VALUE%%-*}" | ||
semVerNumber2="${semVerNumber2%%+*}" | ||
if [[ ! ${semVerNumber1} =~ ^[0-9]+$ || ! ${semVerNumber2} =~ ^[0-9]+$ ]]; then | ||
core::fail "Failed to compare versions ⌜${version1}⌝ and ⌜${version2}⌝ because they are not valid semantic versions." | ||
elif (( semVerNumber1 > semVerNumber2 )); then | ||
RETURNED_VALUE=1 | ||
return 0 | ||
elif (( semVerNumber1 < semVerNumber2 )); then | ||
RETURNED_VALUE=-1 | ||
return 0 | ||
fi | ||
done | ||
RETURNED_VALUE=0 | ||
} | ||
|
||
# ## version::bump | ||
# | ||
# This function allows to bump a semantic version formatted like: | ||
# major.minor.patch-prerelease+build | ||
# | ||
# - $1: **version** _as string_: | ||
# the version to bump | ||
# - $2: **level** _as string_: | ||
# the level to bump (major, minor, patch) | ||
# - $3: clear build and prerelease _as bool_: | ||
# (optional) clear the prerelease and build | ||
# (defaults to true) | ||
# | ||
# Returns: | ||
# | ||
# - `RETURNED_VALUE`: the new version string | ||
# | ||
# ```bash | ||
# version::bump "1.2.3-prerelease+build" "major" | ||
# local newVersion="${RETURNED_VALUE}" | ||
# ``` | ||
function version::bump() { | ||
local version level clearPreRelease | ||
version="${1}" | ||
bumpLevel="${2}" | ||
clearPreRelease="${3:-true}" | ||
|
||
local prerelease build modifiedVersion | ||
modifiedVersion="${version}-+" | ||
prerelease="${modifiedVersion#*-}" | ||
prerelease="${prerelease%%+*}" | ||
if [[ -n "${prerelease}" ]]; then prerelease="-${prerelease%-}"; fi | ||
build="${modifiedVersion#*+}" | ||
if [[ -n "${build}" ]]; then | ||
build="+${build%-+}" | ||
fi | ||
|
||
# bump the version | ||
local -i level semVerNumber semVerIndex | ||
level=2 | ||
if [[ ${bumpLevel:-} == "major" ]]; then level=0; fi | ||
if [[ ${bumpLevel:-} == "minor" ]]; then level=1; fi | ||
local newVersion semVerString | ||
for semVerIndex in {0..2}; do | ||
string::cutField "${version}" "${semVerIndex}" "." | ||
semVerString="${RETURNED_VALUE%-*}" | ||
if [[ ! ${semVerString} =~ ^[0-9]+$ ]]; then | ||
core::fail "Failed to bump the version ⌜${version}⌝ because it is not valid semantic version." | ||
fi | ||
semVerNumber="${semVerString%+}" | ||
if [[ semVerIndex -eq level ]]; then semVerNumber=$((semVerNumber + 1)); fi | ||
if [[ semVerIndex -gt level ]]; then semVerNumber=0; fi | ||
newVersion+="${semVerNumber}." | ||
done | ||
newVersion="${newVersion%.}" | ||
|
||
if [[ "${clearPreRelease}" != "true" ]]; then | ||
newVersion="${newVersion%.}${prerelease}${build}" | ||
fi | ||
|
||
RETURNED_VALUE="${newVersion}" | ||
} | ||
|
Oops, something went wrong.