#!/usr/bin/env bash set -euo pipefail parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P ) cd "$parent_path" || exit if [ $# -ne 1 ]; then echo "Usage: $0 " exit 1 fi if git describe --exact-match --tags HEAD >/dev/null 2>&1; then existing_tag=$(git describe --exact-match --tags HEAD) echo "Current commit is already tagged with $existing_tag. Skipping tag creation." new_version=${existing_tag#v} else current_version=$(git describe --tags --abbrev=0 | sed 's/^v//') IFS='.' read -r major minor patch <<< "$current_version" if [ "$1" == "major" ]; then major=$((major + 1)); minor=0; patch=0 new_version="${major}.${minor}.${patch}" elif [ "$1" == "minor" ]; then minor=$((minor + 1)); patch=0 new_version="${major}.${minor}.${patch}" elif [ "$1" == "patch" ]; then patch=$((patch + 1)) new_version="${major}.${minor}.${patch}" elif [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then new_version="$1" else echo "Invalid argument: must be 'major', 'minor', 'patch', or a specific version (e.g. 1.2.3)" exit 1 fi echo "Tagging v$new_version" git tag "v$new_version" fi git push git push --tags make build-production TAG="$new_version" cd "$parent_path/ansible" || exit ansible-playbook --inventory=hosts playbook.yml