release.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/usr/bin/env bash
  2. # ------------------------------------------------------------
  3. # release.sh – semi-automatic release helper
  4. # ------------------------------------------------------------
  5. set -euo pipefail
  6. set -o errtrace
  7. trap 'echo "❌ Error – aborting"; exit 1' ERR
  8. # -------- configurable -----------------
  9. APP_NAME="${1:-LoopFollow}"
  10. SECOND_DIR="${APP_NAME}_Second"
  11. THIRD_DIR="${APP_NAME}_Third"
  12. VERSION_FILE="Config.xcconfig"
  13. MARKETING_KEY="LOOP_FOLLOW_MARKETING_VERSION"
  14. DEV_BRANCH="dev"
  15. MAIN_BRANCH="main"
  16. PATCH_DIR="../${APP_NAME}_update_patches"
  17. # ---------------------------------------
  18. # --- functions here ---
  19. pause() { read -rp "▶▶ Press Enter to continue (Ctrl-C to abort)…"; }
  20. echo_run() { echo "+ $*"; "$@"; }
  21. push_cmds=()
  22. queue_push() { push_cmds+=("git -C \"$(pwd)\" $*"); echo "+ [queued] (in $(pwd)) git $*"; }
  23. queue_push_tag () {
  24. local tag="$1"
  25. queue_push push origin "refs/tags/$tag"
  26. }
  27. update_follower () {
  28. local DIR="$1"
  29. echo; echo "🔄 Updating $DIR …"
  30. cd "$DIR"
  31. echo; echo "If there are custom changes needed to the patch, make the change before continuing"
  32. pause
  33. # 1 · Make sure we’re on a clean, up-to-date main
  34. echo_run git switch "$MAIN_BRANCH"
  35. echo_run git fetch
  36. echo_run git pull
  37. # 2 · Apply the patch
  38. if ! git apply --whitespace=nowarn "$PATCH_FILE"; then
  39. echo "‼️ Some changes could not be applied, so no changes were made."
  40. echo "The command used was: git apply --whitespace=nowarn $PATCH_FILE"
  41. echo; echo "Use a different terminal to fix and apply the patch before continuing"
  42. pause
  43. fi
  44. # 3 · Pause if any conflict markers remain
  45. if git ls-files -u | grep -q .; then
  46. echo "⚠️ Conflicts detected."
  47. echo " If Fastfile or build_LoopFollow.yml were modified, these are expected."
  48. echo " Open your merge tool, resolve, then press Enter."
  49. pause
  50. fi
  51. # 4 · Single commit capturing all staged changes
  52. git add -u
  53. git add $(git ls-files --others --exclude-standard) 2>/dev/null || true
  54. git commit -m "transfer v${new_ver} updates from LF to ${DIR}"
  55. echo_run git status
  56. echo "💻 Build & test $DIR now."; pause # build & test checkpoint
  57. queue_push push origin "$MAIN_BRANCH"
  58. cd ..
  59. }
  60. # ---------- PRIMARY REPO ----------
  61. PRIMARY_ABS_PATH="$(pwd -P)"
  62. echo "🏁 Working in $PRIMARY_ABS_PATH …"
  63. # --- start out in main to capture old_ver ----
  64. echo_run git switch "$MAIN_BRANCH"
  65. echo_run git fetch
  66. echo_run git pull
  67. # -------- version bump logic (unchanged) -----------
  68. old_ver=$(grep -E "^${MARKETING_KEY}[[:space:]]*=" "$VERSION_FILE" | awk '{print $3}')
  69. major_candidate="$(awk -F. '{printf "%d.0.0", $1 + 1}' <<<"$old_ver")"
  70. minor_candidate="$(awk -F. '{printf "%d.%d.0", $1, $2 + 1}' <<<"$old_ver")"
  71. echo
  72. echo "Which version bump do you want?"
  73. echo " 1) Major → $major_candidate"
  74. echo " 2) Minor → $minor_candidate"
  75. read -rp "Enter 1 or 2 (default = 2): " choice
  76. echo
  77. case "$choice" in
  78. 1) new_ver="$major_candidate" ;; ""|2) new_ver="$minor_candidate" ;;
  79. *) echo "❌ Invalid choice – aborting."; exit 1 ;;
  80. esac
  81. echo "🔢 Bumping version: $old_ver → $new_ver"
  82. # --- switch to dev branch ----
  83. echo_run git switch "$DEV_BRANCH"
  84. echo_run git fetch
  85. echo_run git pull
  86. # --- update version number ----
  87. sed -i '' "s/${MARKETING_KEY}[[:space:]]*=.*/${MARKETING_KEY} = ${new_ver}/" "$VERSION_FILE"
  88. echo_run git diff "$VERSION_FILE"; pause
  89. echo_run git commit -m "update version to ${new_ver} [skip ci]" "$VERSION_FILE"
  90. echo "💻 Build & test dev branch now."; pause
  91. queue_push push origin "$DEV_BRANCH"
  92. # --- create a patch ---------------------------
  93. mkdir -p "$PATCH_DIR"
  94. PATCH_FILE="${PATCH_DIR}/LF_diff_${old_ver}_to_${new_ver}.patch"
  95. git diff -M --binary "$MAIN_BRANCH" "$DEV_BRANCH" \
  96. > "$PATCH_FILE"
  97. # --- merge dev into main for new release
  98. echo_run git switch "$MAIN_BRANCH"
  99. echo_run git merge "$DEV_BRANCH"
  100. echo "💻 Build & test main branch now."; pause
  101. queue_push push origin "$MAIN_BRANCH"
  102. cd ..
  103. update_follower "$SECOND_DIR"
  104. update_follower "$THIRD_DIR"
  105. # ---------- GitHub Actions Test ---------
  106. echo;
  107. echo "💻 Test GitHub Build Actions for all three repositories and then continue.";
  108. pause
  109. # --- return to primary path
  110. cd ${PRIMARY_ABS_PATH}
  111. # ---------- push queue ----------
  112. echo; echo "🚀 Ready to tag and push changes upstream."
  113. echo_run git log --oneline -2
  114. read -rp "▶▶ Ready to tag? (y/n): " confirm
  115. if [[ $confirm =~ ^[Yy]$ ]]; then
  116. git tag -a "v${new_ver}" -m "v${new_ver}"
  117. queue_push_tag "v${new_ver}"
  118. echo_run git log --oneline -2
  119. else
  120. echo "🚫 tag skipped, can add later"
  121. fi
  122. read -rp "▶▶ Push everything now? (y/n): " confirm
  123. if [[ $confirm =~ ^[Yy]$ ]]; then
  124. for cmd in "${push_cmds[@]}"; do echo "+ $cmd"; bash -c "$cmd"; done
  125. echo "🎉 All pushes completed."
  126. echo; echo "🎉 All repos updated to v${new_ver} (local)."
  127. echo "👉 Remember to create a GitHub release for tag v${new_ver}."
  128. else
  129. echo "🚫 Pushes skipped. Run manually if needed:"; printf ' %s\n' "${push_cmds[@]}"
  130. echo "🚫 Release not completed, pushes to GitHub were skipped"
  131. fi