capture-build-details.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 current date and write it to BuildDetails.plist
  23. formatted_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
  24. plutil -replace com-LoopFollow-build-date -string "$formatted_date" "${info_plist_path}"
  25. # Retrieve the current branch
  26. git_branch=$(git symbolic-ref --short -q HEAD)
  27. # Attempt to retrieve the current tag
  28. git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
  29. # Retrieve the current SHA of the latest commit
  30. git_commit_sha=$(git log -1 --format="%h" --abbrev=7)
  31. # Determine the branch or tag information
  32. git_branch_or_tag="${git_branch:-${git_tag}}"
  33. # Update BuildDetails.plist with the branch or tag information
  34. plutil -replace com-LoopFollow-branch -string "${git_branch_or_tag}" "${info_plist_path}"
  35. # Update BuildDetails.plist with the SHA information
  36. plutil -replace com-LoopFollow-commit-sha -string "${git_commit_sha}" "${info_plist_path}"
  37. fi