resolve-version.sh 742 B

1234567891011121314151617181920212223
  1. #!/bin/sh
  2. set -eu
  3. SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
  4. BACKEND_DIR="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)"
  5. REPO_DIR="$(CDPATH= cd -- "$BACKEND_DIR/.." && pwd)"
  6. VERSION_FILE="$BACKEND_DIR/cmd/server/VERSION"
  7. # Prefer the exact release tag when building from a tagged checkout so
  8. # source builds from vX.Y.Z don't inherit the previous VERSION file value.
  9. if command -v git >/dev/null 2>&1; then
  10. TAG="$(
  11. git -C "$REPO_DIR" describe --tags --exact-match --match 'v[0-9]*' 2>/dev/null || \
  12. git -C "$REPO_DIR" describe --tags --exact-match --match '[0-9]*' 2>/dev/null || \
  13. true
  14. )"
  15. if [ -n "$TAG" ]; then
  16. printf '%s\n' "${TAG#v}"
  17. exit 0
  18. fi
  19. fi
  20. printf '%s\n' "$(tr -d '\r\n' < "$VERSION_FILE")"