Skip to content

Commit

Permalink
Prepare the release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Ghionoiu committed Oct 16, 2015
1 parent 9d7814c commit f01aaf7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
tdl-client-ruby (0.0.5)
tdl-client-ruby (0.1.1)
logging (= 2.0.0)
stomp (= 1.3.4)

Expand Down Expand Up @@ -82,9 +82,9 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.9)
coveralls (~> 0.8.2)
cucumber (~> 2.0.0)
cucumber (>= 2.0.0, < 2.1.0)
debase (~> 0.1.4)
json (~> 1.8.3)
json (~> 1.8.3, ~> 1.8)
minitest (= 5.4.1)
minitest-reporters (~> 1.0, >= 1.0.19)
rake (~> 10.0)
Expand Down
2 changes: 1 addition & 1 deletion features/spec
Submodule spec updated 1 files
+1 −21 README.md
4 changes: 3 additions & 1 deletion lib/tdl/version.rb
@@ -1,3 +1,5 @@
module TDL
VERSION = '0.0.5'
PREVIOUS_VERSION = '0.0.4'
# the current MAJOR.MINOR version is dynamically computed from the version of the Spec
CURRENT_PATCH_VERSION = '0'
end
47 changes: 31 additions & 16 deletions release.sh
Expand Up @@ -2,11 +2,30 @@

SCRIPT_FOLDER="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION_FILE="${SCRIPT_FOLDER}/lib/tdl/version.rb"
SPEC_FOLDER="${SCRIPT_FOLDER}/features/spec/"

CURRENT_VERSION=`cat ${VERSION_FILE} | grep "VERSION" | cut -d "=" -f2 | tr -d " '"`
function get_version_from_tag() {
local target_folder=$1
git --git-dir ${target_folder}/.git describe --all | cut -d "/" -f 2 | tr -d "v"
}

function get_property() {
local property=$1
cat ${VERSION_FILE} | grep "${property}" | cut -d "=" -f2 | tr -d " '"
}

# Current
CURRENT_MAJOR_MINOR_VERSION=`get_version_from_tag ${SPEC_FOLDER}`
CURRENT_PATCH_VERSION=`get_property "CURRENT_PATCH_VERSION"`
CURRENT_VERSION="${CURRENT_MAJOR_MINOR_VERSION}.${CURRENT_PATCH_VERSION}"

# Previous
PREVIOUS_MAJOR_MINOR_VERSION=`get_property "PREVIOUS_VERSION" | cut -d "." -f 1,2`
PREVIOUS_PATCH_VERSION=`get_property "PREVIOUS_VERSION" | cut -d "." -f 2`
PREVIOUS_VERSION=`get_property "PREVIOUS_VERSION"`

# Prompt for version confirmation
read -p "Going to release version ${CURRENT_VERSION}. Proceed ? [y/n] "
read -p "Going to release version ${CURRENT_VERSION} (previous ${PREVIOUS_VERSION}). Proceed ? [y/n] "
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Aborting."
Expand All @@ -19,27 +38,23 @@ git push origin "v${CURRENT_VERSION}"
echo "Pushed tag to Git origin. It will now trigger the deployment pipeline."

# Increment version
increment_version() {
local v=$1
if [ -z $2 ]; then
local rgx='^((?:[0-9]+\.)*)([0-9]+)($)'
next_patch_version() {
if [ "$CURRENT_MAJOR_MINOR_VERSION" == "$PREVIOUS_MAJOR_MINOR_VERSION" ]; then
patch=$((CURRENT_PATCH_VERSION+1))
else
local rgx='^((?:[0-9]+\.){'$(($2-1))'})([0-9]+)(\.|$)'

for (( p=`grep -o "\."<<<".$v"|wc -l`; p<$2; p++)); do
v+=.0;
done;
patch="0"
fi
val=`echo -e "$v" | perl -pe 's/^.*'$rgx'.*$/$2/'`
echo "$v" | perl -pe s/$rgx.*$'/${1}'`printf %0${#val}s $(($val+1))`/
echo ${patch}
}

# Switch to next version
NEXT_VERSION=`increment_version ${CURRENT_VERSION}`
echo "Next version is: $NEXT_VERSION"
NEXT_PATCH_VERSION=`next_patch_version`
echo "Next patch version is: $NEXT_PATCH_VERSION"

cat > "${VERSION_FILE}" <<-EOF
module TDL
VERSION = '$NEXT_VERSION'
PREVIOUS_VERSION = '$CURRENT_VERSION'
# the current MAJOR.MINOR version is dynamically computed from the version of the Spec
CURRENT_PATCH_VERSION = '$NEXT_PATCH_VERSION'
end
EOF
10 changes: 7 additions & 3 deletions tdl-client-ruby.gemspec
Expand Up @@ -3,9 +3,13 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'tdl/version'

SPEC_FOLDER = File.expand_path('../features/spec',__FILE__).to_s
MAJOR_MINOR_VERSION = `git --git-dir #{SPEC_FOLDER}/.git describe --all | cut -d '/' -f 2 | tr -d 'v'`.strip
VERSION = "#{MAJOR_MINOR_VERSION}.#{TDL::CURRENT_PATCH_VERSION}"

Gem::Specification.new do |spec|
spec.name = 'tdl-client-ruby'
spec.version = TDL::VERSION
spec.version = VERSION
spec.authors = ['Julian Ghionoiu']
spec.email = ['iulian.ghionoiu@gmail.com']

Expand All @@ -27,7 +31,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'minitest-reporters', '~> 1.0', '>= 1.0.19'
spec.add_development_dependency 'simplecov', '~>0.10.0'
spec.add_development_dependency 'coveralls', '~>0.8.2'
spec.add_development_dependency 'json', '~>1.8.3'
spec.add_development_dependency 'cucumber', '~>2.0.0'
spec.add_development_dependency 'json', '~> 1.8', '~>1.8.3'
spec.add_development_dependency 'cucumber', '>= 2.0.0', '<2.1.0'
spec.add_development_dependency 'debase', '~>0.1.4'
end

0 comments on commit f01aaf7

Please sign in to comment.