release.sh 4.7 KB

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