#!/bin/bash
# dev/package/versions - package version management

set -e

lib_load 'dev/package/load'
lib_load 'dev/versions'


######
# Package Versions

package_version_build() {
	local version=$1
	shift
	for part in "$@"; do
		version="$version${part:+-$part}"
	done
	echo "$version"
}
package_version_build_full() {
	package_version_build "$VERSION" "$SITE_BRANCH" "$SITE_VERSION"
}


package_version_read() {
	has_args 1 "$@"
	local part=$1
	case "$part" in
	(package) echo "$VERSION" ;;
	(branch) echo "$SITE_BRANCH" ;;
	(site) echo "$SITE_VERSION" ;;
	(*) error "$part: unknown version part" ;;
	esac
}
package_version_read_full() { package_version_build_full; }

package_version_bump() {
	has_args 1 "$@"
	local part=${1:-micro}

	local var old new file
	case "$part" in
	(major|minor|micro)
		var='VERSION'
		file=$package_i7
		old=$(package_version_read package)
		new=$(version_bump "$old" "$part")
		;;
	(site-major|site-minor|site-micro)
		var='SITE_VERSION'
		file=$site_i7
		old=$(package_version_read site)
		new=$(version_bump "$old" "${part#*-}")
		;;
	(*)
		error "$part: unknown package version part"
		;;
	esac
	run sed -i -e "s,^$var=$old,$var=$new," "$file"

	local msg="${part/-/ } version bump: v$old -> v$new"
	app_echo "$msg"
	run git commit -m "package: $msg" "$file"
}

package_version_unbump() {
	has_args 0 "$@"
	local msg
	msg=$(git_commit_title HEAD)
	if echo "$msg" | egrep '^package: [^ ]* version bump'; then
		# drop the commit that bumped the version
		run git reset HEAD^
		run git checkout "$package_i7"
		run git checkout "$site_i7" || true
	else
		error "not a version bump: $msg"
	fi
}

package_version_tag() {
	has_args 0 "$@"
	local version
	version=$(package_version_read_full)
	app_echo "tagging v$version"
	run git tag "v$version"
}

package_version_untag() {
	has_args 0 "$@"
	local version
	version=$(package_version_read_full)
	run git tag -d "v$version"
}

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:35:30 PDT 2017 by mcsh d14 v0.23.0.