Skip to content

Instantly share code, notes, and snippets.

@oojacoboo
Created August 5, 2017 03:31
Show Gist options
  • Save oojacoboo/106a9addeb81d388baf249324d27714e to your computer and use it in GitHub Desktop.
Save oojacoboo/106a9addeb81d388baf249324d27714e to your computer and use it in GitHub Desktop.
# Validates that the version string is a valid Semantic Version Number
Validate.semver() {
local version="$1"
if [[ ! $version =~ ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$ ]]; then
die "Version, '$version', must be a valid semantic version (semver)"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment