Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pforret/semver
Browse files Browse the repository at this point in the history
  • Loading branch information
pforret committed Apr 9, 2021
2 parents dae42da + a562977 commit 9c52f36
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ to bump the version
changelog: add chapter with latest changes to CHANGELOG.md
```

## Example:

> setver new patch
✔ version 1.12.0 -> 1.12.1
✔ set version in package.json
✔ set version in composer.json
✔ set version in .env.example
✔ set version in VERSION.md
✔ commit and push changed files
✔ push tags to [email protected]:pforret/setver.git
✔ to create a release, go to https://github.com/pforret/setver


## Installation

with [basher](https://github.com/basherpm/basher)
Expand All @@ -60,18 +73,6 @@ or the hard way
# if you want the script to be in your path
ln -s <cloned_folder>/setver /usr/local/bin/

## Example:

> setver new patch
✔ version 1.12.0 -> 1.12.1
✔ set version in package.json
✔ set version in composer.json
✔ set version in .env.example
✔ set version in VERSION.md
✔ commit and push changed files
✔ push tags to [email protected]:pforret/setver.git
✔ to create a release, go to https://github.com/pforret/setver

## References
* https://semver.org/

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
],
"require": {},
"version": "1.15.0"
"version": "1.14.4"
}
20 changes: 12 additions & 8 deletions setver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ env_example=".env.example"
verbose=0
check_in_root=1
usage=0
while getopts rvh option ; do
prefix="v"
while getopts rvhp: option ; do
case $option in
r) check_in_root=0 ;;
v) verbose=1 ;;
h) usage=1 ;;
p) prefix="$OPTARG" ;;
*) echo "Unknown option -$option"
esac
done
Expand Down Expand Up @@ -111,7 +113,7 @@ main() {

changes | changelog)
#USAGE: setver changelog: format new CHANGELOG.md chapter
add_to_changedebug "$(get_any_version)"
add_to_changelog "$(get_any_version)"
;;

history)
Expand Down Expand Up @@ -152,6 +154,7 @@ show_usage_and_quit() {
$script_fname [-h] [-v] [-s] [get/check/push/auto/skip/set/new/history/changelog] [version]
-h: extended help
-v: verbose mode (more output to stderr)
-p <prefix>: use as prefix for git tag (default: "v")
-s: add [skip_ci] flag to
get : get current version (from git tag and composer) -- can be used in scripts
check : compare versions of git tag and composer
Expand Down Expand Up @@ -205,6 +208,7 @@ get_version_tag() {
if [[ -n $(git tag) ]] ; then
git tag \
| sed 's/v//' \
| sed "s/$prefix//" \
| awk -F. '{printf("%04d.%04d.%04d\n",$1,$2,$3);}' \
| sort \
| tail -1 \
Expand Down Expand Up @@ -411,7 +415,7 @@ set_versions() {
if [[ $uses_npm -gt 0 ]]; then
# for NPM/node repos
# first change package.json
success "set version in package.json"
success "set version in package.json: $new_version"
wait 1
npm version "$new_version"
skip_git_tag=1 # npm also creates the tag
Expand All @@ -423,7 +427,7 @@ set_versions() {
if [[ $uses_composer -gt 0 ]]; then
# for PHP repos
# first change composer.json
success "set version in composer.json"
success "set version in composer.json: $new_version"

wait 1
composer config version "$new_version" 2> /dev/null
Expand All @@ -434,7 +438,7 @@ set_versions() {
### .env
if [[ $uses_env -gt 0 ]]; then
# for Ruby/PHP/bash/...
success "set version in $env_example"
success "set version in $env_example: $new_version"
wait 1
env_temp="$env_example.tmp"
awk -F= -v version="$new_version" '
Expand All @@ -460,7 +464,7 @@ set_versions() {
### VERSION.md
if [[ -f VERSION.md ]]; then
# for bash repos
success "set version in VERSION.md"
success "set version in VERSION.md: $new_version"
wait 1
echo "$new_version" >VERSION.md
git add VERSION.md
Expand All @@ -475,9 +479,9 @@ set_versions() {

# now create new version tag
if [[ $skip_git_tag == 0 ]]; then
success "set git version tag"
success "set git version tag: $prefix$new_version"
wait 1
git tag "v$new_version"
git tag "$prefix$new_version"
fi

# also push tags to github/bitbucket
Expand Down

0 comments on commit 9c52f36

Please sign in to comment.