mas/script/version
Ross Goldberg f1a9cde9fd
Use double quotes around bash substitutions.
Use braces around bash variable uses.

Partial #638

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
2024-11-16 14:47:15 -05:00

30 lines
754 B
Bash
Executable file

#!/bin/bash -eu
#
# script/version
# mas
#
# Displays the current marketing version of mas.
#
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
if ! cd -- "${mas_dir}"; then
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
exit 1
fi
if [[ -z "${MAS_VERSION:-}" ]] && git describe >/dev/null 2>&1; then
# Use last tag if MAS_VERSION environment variable is unset or empty
MAS_VERSION="$(git describe --abbrev=0 --tags 2>/dev/null || true)"
fi
echo "${MAS_VERSION#v}"
if [[ "${#}" -ge 1 && "${1}" == '--write' ]]; then
# Write new version into swift package
cat <<EOF >Sources/mas/Package.swift
/// Generated by \`script/version\`.
enum Package {
static let version = "${MAS_VERSION#v}"
}
EOF
fi