Skip to content

Instantly share code, notes, and snippets.

@lobre
Created December 4, 2019 16:09
Show Gist options
  • Save lobre/6850ff5968f6be2e1489f00d826a3d6c to your computer and use it in GitHub Desktop.
Save lobre/6850ff5968f6be2e1489f00d826a3d6c to your computer and use it in GitHub Desktop.
Minor upgrade in composer.json
#!/bin/bash
# This script takes a composer.json file as first parameter
# and will increase the minor number of the semantic version.
# e.g. From 1.3.3 to 1.4.0.
oops() {
echo "$0:" "$@" >&2
exit 1
}
require_util() {
command -v "$1" > /dev/null 2>&1 ||
oops "you do not have '$1' installed, which I need to $2"
}
# check deps
require_util jq "parse json files"
composer="$1"
if ! [ -f "$composer" ]; then
oops "wrong composer file given as parameter"
fi
version=$(jq --raw-output '.version' "$composer")
# build array out of version
a=( ${version//./ } )
# increment minor
result="${a[0]}.$((a[1]+1)).0"
# override version in composer.json file
output=$(jq --indent 4 --arg version "$result" '.version = $version' "$composer")
echo "$output" > "$composer"
echo "version upgraded from $version to $result"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment