#!/bin/bash
# Shared settings for build.sh, package.sh and test.sh. Source this, don't run it.
#
# Previously each script derived these on its own, and they drifted: build.sh
# hardcoded 1.1 while package.sh read the git tag, so a DMG named 1.0 shipped an
# app that reported 1.1 in the About panel.
MIN_MACOS_VERSION="${MIN_MACOS_VERSION:-14.0}"
# The newest git tag is the source of truth (v1.2.3 -> 1.2.3). A build that isn't
# sitting exactly on a tag, or that has uncommitted changes, gets a -dev suffix so
# a local rebuild is visibly distinct from the released build in the About panel.
# Override with VERSION=... in the environment.
menubrowser_version() {
if [ -n "${VERSION:-}" ]; then
printf '%s' "${VERSION}"
return
fi
local tag
tag=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || true)
if [ -z "${tag}" ]; then
printf '%s' "0.0.0-dev"
return
fi
# --untracked-files=no on purpose: a stray scratch file in the checkout must not
# turn a tagged release build into a -dev build.
if [ -n "$(git status --porcelain --untracked-files=no 2>/dev/null || true)" ] \
|| [ -n "$(git log "v${tag}..HEAD" --oneline 2>/dev/null || true)" ]; then
printf '%s' "${tag}-dev"
else
printf '%s' "${tag}"
fi
}