release.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. Do not use 3way because commit history is not in common
  38. if ! git apply --whitespace=nowarn "$PATCH_FILE"; then
  39. echo "‼️ Some hunks could not be merged automatically."
  40. echo; echo "Use a different terminal to fix files before continuing"
  41. pause
  42. fi
  43. # 3 · Pause if any conflict markers remain
  44. if git ls-files -u | grep -q .; then
  45. echo "⚠️ Conflicts detected."
  46. echo " If Fastfile or build_LoopFollow.yml were modified, these are expected."
  47. echo " Open your merge tool, resolve, then press Enter."
  48. pause
  49. fi
  50. # 4 · Single commit capturing all staged changes
  51. git add -u
  52. git add $(git ls-files --others --exclude-standard) 2>/dev/null || true
  53. git commit -m "transfer v${new_ver} updates from LF to ${DIR}"
  54. echo_run git status
  55. pause # build & test checkpoint
  56. queue_push push origin "$MAIN_BRANCH"
  57. cd ..
  58. }
  59. # ---------- PRIMARY REPO ----------
  60. PRIMARY_ABS_PATH="$(pwd -P)"
  61. echo "🏁 Working in $PRIMARY_ABS_PATH …"
  62. # --- start out in main to capture old_ver ----
  63. echo_run git switch "$MAIN_BRANCH"
  64. echo_run git fetch
  65. echo_run git pull
  66. # -------- version bump logic (unchanged) -----------
  67. old_ver=$(grep -E "^${MARKETING_KEY}[[:space:]]*=" "$VERSION_FILE" | awk '{print $3}')
  68. major_candidate="$(awk -F. '{printf "%d.0.0", $1 + 1}' <<<"$old_ver")"
  69. minor_candidate="$(awk -F. '{printf "%d.%d.0", $1, $2 + 1}' <<<"$old_ver")"
  70. echo
  71. echo "Which version bump do you want?"
  72. echo " 1) Major → $major_candidate"
  73. echo " 2) Minor → $minor_candidate"
  74. read -rp "Enter 1 or 2 (default = 2): " choice
  75. echo
  76. case "$choice" in
  77. 1) new_ver="$major_candidate" ;; ""|2) new_ver="$minor_candidate" ;;
  78. *) echo "❌ Invalid choice – aborting."; exit 1 ;;
  79. esac
  80. echo "🔢 Bumping version: $old_ver → $new_ver"
  81. # --- switch to dev branch ----
  82. echo_run git switch "$DEV_BRANCH"
  83. echo_run git fetch
  84. echo_run git pull
  85. # --- update version number ----
  86. sed -i '' "s/${MARKETING_KEY}[[:space:]]*=.*/${MARKETING_KEY} = ${new_ver}/" "$VERSION_FILE"
  87. echo_run git diff "$VERSION_FILE"; pause
  88. echo_run git commit -m "update version to ${new_ver} [skip ci]" "$VERSION_FILE"
  89. echo "💻 Build & test dev branch now."; pause
  90. queue_push push origin "$DEV_BRANCH"
  91. # --- create a patch ---------------------------
  92. mkdir -p "$PATCH_DIR"
  93. PATCH_FILE="${PATCH_DIR}/LF_diff_${old_ver}_to_${new_ver}.patch"
  94. git diff -M --binary "$MAIN_BRANCH" "$DEV_BRANCH" \
  95. > "$PATCH_FILE"
  96. # --- merge dev into main for new release
  97. echo_run git switch "$MAIN_BRANCH"
  98. echo_run git merge "$DEV_BRANCH"
  99. echo "💻 Build & test main branch now."; pause
  100. queue_push push origin "$MAIN_BRANCH"
  101. cd ..
  102. update_follower "$SECOND_DIR"
  103. update_follower "$THIRD_DIR"
  104. # ---------- GitHub Actions Test ---------
  105. echo; echo "💻 Test GitHub Build Actions and then continue."; pause
  106. # --- return to primary path
  107. cd ${PRIMARY_ABS_PATH}
  108. # ---------- push queue ----------
  109. echo; echo "🚀 Ready to tag and push changes upstream."
  110. echo_run git log --oneline -2
  111. read -rp "▶▶ Ready to tag? (y/N): " confirm
  112. if [[ $confirm =~ ^[Yy]$ ]]; then
  113. git tag -a "v${new_ver}" -m "v${new_ver}"
  114. queue_push_tag "v${new_ver}"
  115. echo_run git log --oneline -2
  116. else
  117. echo "🚫 tag skipped, can add later"
  118. fi
  119. read -rp "▶▶ Push everything now? (y/N): " confirm
  120. if [[ $confirm =~ ^[Yy]$ ]]; then
  121. for cmd in "${push_cmds[@]}"; do echo "+ $cmd"; bash -c "$cmd"; done
  122. echo "🎉 All pushes completed."
  123. echo; echo "🎉 All repos updated to v${new_ver} (local)."
  124. echo "👉 Remember to create a GitHub release for tag v${new_ver}."
  125. else
  126. echo "🚫 Pushes skipped. Run manually if needed:"; printf ' %s\n' "${push_cmds[@]}"
  127. echo "🚫 Release not completed, pushes to GitHub were skipped"
  128. fi