capture-build-details.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh -e
  2. # capture-build-details.sh
  3. # Trio
  4. #
  5. # Created by Jonas Björkert on 2024-05-08.
  6. # Enable debugging if needed
  7. #set -x
  8. info_plist_path="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/BuildDetails.plist"
  9. # Ensure the path to BuildDetails.plist is valid.
  10. if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then
  11. echo "BuildDetails.plist file does not exist at path: ${info_plist_path}" >&2
  12. exit 1
  13. else
  14. echo "Gathering build details..."
  15. # Capture the current date and write it to BuildDetails.plist
  16. plutil -replace com-trio-build-date -string "$(date)" "${info_plist_path}"
  17. # Retrieve the current branch
  18. git_branch=$(git symbolic-ref --short -q HEAD)
  19. # Attempt to retrieve the current tag
  20. git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
  21. # Retrieve the current SHA of the latest commit
  22. git_commit_sha=$(git log -1 --format="%h" --abbrev=7)
  23. # Determine the branch or tag information
  24. git_branch_or_tag="${git_branch:-${git_tag}}"
  25. # Update BuildDetails.plist with the branch or tag information
  26. plutil -replace com-trio-branch -string "${git_branch_or_tag}" "${info_plist_path}"
  27. # Update BuildDetails.plist with the SHA information
  28. plutil -replace com-trio-commit-sha -string "${git_commit_sha}" "${info_plist_path}"
  29. fi