Remove bump & semver from src (BREAKING)

This commit is contained in:
Kevin van Zonneveld 2016-02-17 13:35:17 +01:00
parent 7fbf9ea8e5
commit 07ab2a95b4
3 changed files with 3 additions and 265 deletions

View File

@ -1,131 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2014, Transloadit Ltd.
#
# This file:
#
# - Bumps a semantic version as specified in first argument
# - Or: Bumps a semantic version in a file as specified in first argument
# - Returns the version if no levelName is provided in second argument
# - Only supports Go files ending in 'var Version = ...'
#
# Run as:
#
# ./bump.sh 0.0.1 patch
# ./bump.sh ./VERSION patch
# ./bump.sh ./VERSION patch
# ./bump.sh ./VERSION major 1
# ./bump.sh ./version.go patch 2
#
# Returns:
#
# v0.0.1
#
# Requires:
#
# - gsed on OSX (brew install gnu-sed)
#
# Authors:
#
# - Kevin van Zonneveld <kevin@transloadit.com>
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__root="$(cd "$(dirname "${__dir}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
gsed=""
[ -n "$(which sed)" ] && gsed="$(which sed)"
[ -n "$(which gsed)" ] && gsed="$(which gsed)"
. ${__dir}/semver.sh
function readFromFile() {
local filepath="${1}"
local extension="${filepath##*.}"
if [ "${extension}" = "go" ]; then
curVersion="$(awk -F'"' '/^var Version = / {print $2}' "${filepath}" | tail -n1)" || true
else
curVersion="$(echo $(cat "${filepath}"))" || true
fi
if [ -z "${curVersion}" ]; then
curVersion="v0.0.0"
fi
echo "${curVersion}"
}
function writeToFile() {
local filepath="${1}"
local newVersion="${2}"
local extension="${filepath##*.}"
if [ "${extension}" = "go" ]; then
buf="$(cat "${filepath}" |egrep -v '^var Version = ')" || true
echo -e "${buf}\nvar Version = \"${newVersion}\"" > "${filepath}"
else
echo "${newVersion}" > "${filepath}"
fi
}
function bump() {
local version="${1}"
local levelName="${2}"
local bump="${3}"
local major=0
local minor=0
local patch=0
local special=""
local newVersion=""
semverParseInto "${version}" major minor patch special
if [ "${levelName}" = "major" ]; then
let "major = major + ${bump}"
minor=0
patch=0
special=""
fi
if [ "${levelName}" = "minor" ]; then
let "minor = minor + ${bump}"
patch=0
special=""
fi
if [ "${levelName}" = "patch" ]; then
let "patch = patch + ${bump}"
special=""
fi
if [ "${levelName}" = "special" ]; then
special="${bump}"
fi
newVersion="v${major}.${minor}.${patch}"
if [ -n "${special}" ]; then
newVersion=".${newVersion}"
fi
echo "${newVersion}"
}
if [ -f "${1}" ]; then
filepath="${1}"
curVersion="$(readFromFile "${filepath}")"
else
curVersion="${1}"
fi
newVersion=$(bump "${curVersion}" "${2:-}" "${3:-1}")
echo "${newVersion}"
if [ -n "${filepath:-}" ]; then
writeToFile "${filepath}" "${newVersion}"
fi

View File

@ -2,12 +2,15 @@
# BASH3 Boilerplate: ini_val
#
# This file:
#
# - Can read and write .ini files using pure bash
#
# Limitations:
#
# - All keys inside the .ini file must be unique, regardless of the use of sections
#
# More info:
#
# - https://github.com/kvz/bash3boilerplate
# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/
#
@ -15,8 +18,6 @@
#
# Authors:
# - Kevin van Zonneveld (http://kvz.io)
# - Izaak Beekman (https://izaakbeekman.com/)
# - Alexander Rathai (Alexander.Rathai@gmail.com)
#
# Usage as a function:
#

View File

@ -1,132 +0,0 @@
#!/usr/bin/env sh
# From: https://github.com/cloudflare/semver_bash
# https://raw.githubusercontent.com/cloudflare/semver_bash/master/semver.sh
function semverParseInto() {
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
#MAJOR
eval $2=`echo $1 | sed -e "s#$RE#\1#"`
#MINOR
eval $3=`echo $1 | sed -e "s#$RE#\2#"`
#MINOR
eval $4=`echo $1 | sed -e "s#$RE#\3#"`
#SPECIAL
eval $5=`echo $1 | sed -e "s#$RE#\4#"`
}
function semverEQ() {
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0
local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
if [ $MAJOR_A -ne $MAJOR_B ]; then
return 1
fi
if [ $MINOR_A -ne $MINOR_B ]; then
return 1
fi
if [ $PATCH_A -ne $PATCH_B ]; then
return 1
fi
if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then
return 1
fi
return 0
}
function semverLT() {
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0
local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
if [ $MAJOR_A -lt $MAJOR_B ]; then
return 0
fi
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then
return 0
fi
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then
return 0
fi
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
return 1
fi
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then
return 1
fi
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
return 0
fi
if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then
return 0
fi
return 1
}
function semverGT() {
semverEQ $1 $2
local EQ=$?
semverLT $1 $2
local LT=$?
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then
return 0
else
return 1
fi
}
if [ "___semver.sh" == "___`basename $0`" ]; then
MAJOR=0
MINOR=0
PATCH=0
SPECIAL=""
semverParseInto $1 MAJOR MINOR PATCH SPECIAL
echo "$1 -> M: $MAJOR m:$MINOR p:$PATCH s:$SPECIAL"
semverParseInto $2 MAJOR MINOR PATCH SPECIAL
echo "$2 -> M: $MAJOR m:$MINOR p:$PATCH s:$SPECIAL"
semverEQ $1 $2
echo "$1 == $2 -> $?."
semverLT $1 $2
echo "$1 < $2 -> $?."
semverGT $1 $2
echo "$1 > $2 -> $?."
fi