capture-build-details.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh -e
  2. # capture-build-details.sh
  3. # LoopFollow
  4. #
  5. # Created by Jonas Björkert on 2024-05-08.
  6. # Enable debugging if needed
  7. #set -x
  8. # Define the base path for the BuildDetails.plist
  9. info_plist_base="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}"
  10. # Adjust the path for macOS Catalyst builds to include the Resources directory
  11. if [[ "$PLATFORM_NAME" == *"macosx"* ]]; then
  12. info_plist_base+="/Resources"
  13. fi
  14. info_plist_path="${info_plist_base}/BuildDetails.plist"
  15. # Ensure the path to BuildDetails.plist is valid.
  16. if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then
  17. echo "$PLATFORM_NAME"
  18. echo "BuildDetails.plist file does not exist at path: ${info_plist_path}" >&2
  19. exit 1
  20. else
  21. echo "Gathering build details..."
  22. # Capture the Development Team ID and write it to BuildDetails.plist
  23. plutil -replace com-LoopFollow-development-team -string "${DEVELOPMENT_TEAM}" "${info_plist_path}"
  24. # Capture the current date and write it to BuildDetails.plist
  25. formatted_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
  26. plutil -replace com-LoopFollow-build-date -string "$formatted_date" "${info_plist_path}"
  27. # Retrieve the current branch
  28. git_branch=$(git symbolic-ref --short -q HEAD 2>/dev/null || echo "")
  29. # Attempt to retrieve the current tag
  30. git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
  31. # Retrieve the current SHA of the latest commit
  32. git_commit_sha=$(git log -1 --format="%h" --abbrev=7 2>/dev/null || echo "")
  33. # Determine the branch or tag information, defaulting to "detached" if neither is available
  34. if [ -z "$git_branch" ] && [ -z "$git_tag" ]; then
  35. git_branch_or_tag="detached"
  36. else
  37. git_branch_or_tag="${git_branch:-${git_tag}}"
  38. fi
  39. # Update BuildDetails.plist with the branch or tag information
  40. plutil -replace com-LoopFollow-branch -string "${git_branch_or_tag}" "${info_plist_path}"
  41. # Update BuildDetails.plist with the SHA information
  42. plutil -replace com-LoopFollow-commit-sha -string "${git_commit_sha}" "${info_plist_path}"
  43. fi