build.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
  6. source "${ROOT_DIR}/hack/lib/init.sh"
  7. function build() {
  8. uv build
  9. }
  10. function prepare_dependencies() {
  11. DEPS_ONLY=true bash "${ROOT_DIR}/hack/install.sh"
  12. }
  13. function set_version() {
  14. local version_file="${ROOT_DIR}/gpustack/__init__.py"
  15. local pyproject_file="${ROOT_DIR}/pyproject.toml"
  16. local git_commit="${GIT_COMMIT:-HEAD}"
  17. local git_commit_short="${git_commit:0:7}"
  18. gpustack::log::info "setting version to $GIT_VERSION"
  19. gpustack::log::info "setting git commit to $git_commit_short"
  20. # Replace the __version__ variable in the __init__.py file
  21. gpustack::util::sed "s/__version__ = .*/__version__ = '${GIT_VERSION}'/" "${version_file}"
  22. gpustack::util::sed "s/__git_commit__ = .*/__git_commit__ = '${git_commit_short}'/" "${version_file}"
  23. # Update the version in pyproject.toml
  24. gpustack::util::sed "s/^version = .*/version = \"${GIT_VERSION}\"/" "${pyproject_file}"
  25. }
  26. function restore_version_file() {
  27. local version_file="${ROOT_DIR}/gpustack/__init__.py"
  28. local pyproject_file="${ROOT_DIR}/pyproject.toml"
  29. git checkout -- "${version_file}" "${pyproject_file}"
  30. }
  31. #
  32. # main
  33. #
  34. gpustack::log::info "+++ BUILD +++"
  35. prepare_dependencies
  36. set_version
  37. build
  38. restore_version_file
  39. gpustack::log::info "--- BUILD ---"