-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement semver --increment to remove dependency #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,11 @@ Options: | |
'X.Y.Z' acts as a placeholder for the version number. | ||
'Version X.Y.Z' is assumed if this option is omitted. | ||
|
||
--prerelease-label <label> | ||
Specify the label to be used in the version number when publishing | ||
a pre-release version (e.g. 'beta' is the label in '2.0.0-beta.0'). | ||
'rc' is assumed if this option is omitted. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addition shows that we have never fully supported the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Avaq, do you agree with |
||
--publish-command <command> | ||
Specify the command to be run to publish the package. It may refer | ||
to the VERSION and PREVIOUS_VERSION environment variables. A no-op | ||
|
@@ -60,27 +65,70 @@ Options: | |
Print xyz's version number and exit. | ||
" | ||
|
||
# http://stackoverflow.com/a/246128/312785 | ||
unset CDPATH | ||
path="${BASH_SOURCE[0]}" | ||
while [ -h "$path" ] ; do | ||
dir="$(cd -P "$(dirname "$path")" && pwd)" | ||
path="$(readlink "$path")" | ||
[[ $path == /* ]] || path="$dir/$path" | ||
done | ||
dir="$(cd -P "$(dirname "$path")" && pwd)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to see this code go! |
||
inc() { | ||
local prerelease_label="$1" increment="$2" version="$3" | ||
local number='0|[1-9][0-9]*' | ||
local part="$number|[-0-9A-Za-z]+" | ||
local pattern="^($number)[.]($number)[.]($number)(-(($part)([.]($part))*))?$" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should match the grammar. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've missed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's true. I've never used it. Have you, Aldwin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've never used it either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's omit |
||
if ! [[ $version =~ $pattern ]] ; then | ||
printf 'Invalid version: %s\n' "$version" >&2 | ||
return 1 | ||
fi | ||
local -i x=${BASH_REMATCH[1]} | ||
local -i y=${BASH_REMATCH[2]} | ||
local -i z=${BASH_REMATCH[3]} | ||
local qual=${BASH_REMATCH[5]} | ||
|
||
local -a parts=("$prerelease_label" 0) | ||
case $increment in | ||
major) (( y + z == 0 )) && [[ -n $qual ]] || x+=1 ; y=0 ; z=0 ;; | ||
minor) (( z == 0 )) && [[ -n $qual ]] || y+=1 ; z=0 ;; | ||
patch) [[ -n $qual ]] || z+=1 ;; | ||
premajor) x+=1 ; y=0 ; z=0 ;; | ||
preminor) y+=1 ; z=0 ;; | ||
prepatch) z+=1 ;; | ||
prerelease) | ||
case ${BASH_REMATCH[6]} in | ||
'') z+=1 ;; | ||
$prerelease_label) | ||
local idx | ||
local -a xs | ||
IFS=. read -r -a xs <<<"$qual" | ||
for (( idx = ${#xs[@]} - 1 ; idx > 0 ; idx -= 1 )) ; do | ||
pattern="^($number)$" | ||
if [[ ${xs[idx]} =~ $pattern ]] ; then | ||
parts=(${xs[@]}) | ||
(( parts[idx] += 1 )) | ||
break | ||
fi | ||
done | ||
esac | ||
;; | ||
*) | ||
echo "Invalid --increment" >&2 | ||
return 1 | ||
esac | ||
|
||
version="$x.$y.$z" | ||
if [[ $increment =~ ^pre ]] ; then | ||
join() { local IFS=. ; echo "$*" ; } | ||
version+="-$(join "${parts[@]}")" | ||
fi | ||
printf %s "$version" | ||
} | ||
|
||
branch=master | ||
edit=false | ||
increment=patch | ||
message_template='Version X.Y.Z' | ||
prerelease_label=rc | ||
publish_command='npm publish' | ||
repo=origin | ||
declare -a scripts | ||
tag_template=vX.Y.Z | ||
dry_run=false | ||
|
||
while (($# > 0)) ; do | ||
while (( $# > 0 )) ; do | ||
option="$1" | ||
shift | ||
|
||
|
@@ -90,29 +138,25 @@ while (($# > 0)) ; do | |
exit | ||
;; | ||
-v|--version) | ||
node -p "require('$dir/package.json').version" | ||
node -p 'require("xyz/package.json").version' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change means |
||
exit | ||
;; | ||
-b|--branch) branch="$1" ; shift ;; | ||
-e|--edit) edit=true ;; | ||
-i|--increment) increment="$1" ; shift ;; | ||
-m|--message) message_template="$1" ; shift ;; | ||
--publish-command) publish_command="$1" ; shift ;; | ||
-r|--repo) repo="$1" ; shift ;; | ||
-s|--script) scripts+=("$1") ; shift ;; | ||
-t|--tag) tag_template="$1" ; shift ;; | ||
--dry-run) dry_run=true ;; | ||
-b|--branch) branch="$1" ; shift ;; | ||
-e|--edit) edit=true ;; | ||
-i|--increment) increment="$1" ; shift ;; | ||
-m|--message) message_template="$1" ; shift ;; | ||
--prerelease-label) prerelease_label="$1" ; shift ;; | ||
--publish-command) publish_command="$1" ; shift ;; | ||
-r|--repo) repo="$1" ; shift ;; | ||
-s|--script) scripts+=("$1") ; shift ;; | ||
-t|--tag) tag_template="$1" ; shift ;; | ||
--dry-run) dry_run=true ;; | ||
*) | ||
echo "Unrecognized option $option" >&2 | ||
exit 1 | ||
esac | ||
done | ||
|
||
case "$increment" in | ||
major|minor|patch|premajor|preminor|prepatch|prerelease) ;; | ||
*) echo "Invalid --increment" >&2 ; exit 1 ;; | ||
esac | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
[[ $(git rev-parse --abbrev-ref HEAD) == "$branch" ]] || | ||
(echo "Current branch does not match specified --branch" >&2 ; exit 1) | ||
|
||
|
@@ -125,8 +169,7 @@ name=$(node -p "require('./package.json').name" 2>/dev/null) || | |
version=$(node -p "require('./package.json').version" 2>/dev/null) || | ||
(echo "Cannot read package version" >&2 ; exit 1) | ||
|
||
next_version=$("$dir/node_modules/.bin/semver" -i "$increment" "$version") || | ||
(echo "Cannot increment version number" >&2 ; exit 1) | ||
next_version=$(inc "$prerelease_label" "$increment" "$version") | ||
|
||
message="${message_template//X.Y.Z/$next_version}" | ||
tag="${tag_template//X.Y.Z/$next_version}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉