release.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. update_follower () {
  24. local DIR="$1"
  25. echo; echo "🔄 Updating $DIR …"
  26. cd "$DIR"
  27. echo; echo "If there are custom changes needed to the patch, make the change before continuing"
  28. pause
  29. # 1 · Make sure we’re on a clean, up-to-date main
  30. echo_run git switch "$MAIN_BRANCH"
  31. echo_run git fetch
  32. echo_run git pull
  33. # 2 · Apply the patch
  34. if ! git apply --whitespace=nowarn "$PATCH_FILE"; then
  35. echo "‼️ Some changes could not be applied, so no changes were made."
  36. echo "The command used was: git apply --whitespace=nowarn $PATCH_FILE"
  37. echo; echo "Use a different terminal to fix and apply the patch before continuing"
  38. pause
  39. fi
  40. # 3 · Pause if any conflict markers remain
  41. if git ls-files -u | grep -q .; then
  42. echo "⚠️ Conflicts detected."
  43. echo " If Fastfile or build_LoopFollow.yml were modified, these are expected."
  44. echo " Open your merge tool, resolve, then press Enter."
  45. pause
  46. fi
  47. # 4 · Single commit capturing all staged changes
  48. git add -u
  49. git add $(git ls-files --others --exclude-standard) 2>/dev/null || true
  50. git commit -m "transfer v${new_ver} updates from LF to ${DIR}"
  51. echo_run git status
  52. echo "💻 Build & test $DIR now."; pause # build & test checkpoint
  53. queue_push push origin "$MAIN_BRANCH"
  54. cd ..
  55. }
  56. # ---------- PRIMARY REPO ----------
  57. PRIMARY_ABS_PATH="$(pwd -P)"
  58. echo "🏁 Working in $PRIMARY_ABS_PATH …"
  59. # --- start out in main to capture old_ver ----
  60. echo_run git switch "$MAIN_BRANCH"
  61. echo_run git fetch
  62. echo_run git pull
  63. # -------- version bump logic (unchanged) -----------
  64. old_ver=$(grep -E "^${MARKETING_KEY}[[:space:]]*=" "$VERSION_FILE" | awk '{print $3}')
  65. major_candidate="$(awk -F. '{printf "%d.0.0", $1 + 1}' <<<"$old_ver")"
  66. minor_candidate="$(awk -F. '{printf "%d.%d.0", $1, $2 + 1}' <<<"$old_ver")"
  67. echo
  68. echo "Which version bump do you want?"
  69. echo " 1) Major → $major_candidate"
  70. echo " 2) Minor → $minor_candidate"
  71. read -rp "Enter 1 or 2 (default = 2): " choice
  72. echo
  73. case "$choice" in
  74. 1) new_ver="$major_candidate" ;; ""|2) new_ver="$minor_candidate" ;;
  75. *) echo "❌ Invalid choice – aborting."; exit 1 ;;
  76. esac
  77. echo "🔢 Bumping version: $old_ver → $new_ver"
  78. # --- switch to dev so the release branch is cut from latest dev ----
  79. echo_run git switch "$DEV_BRANCH"
  80. echo_run git fetch
  81. echo_run git pull
  82. # --- create release branch from dev's tip ----
  83. RELEASE_BRANCH="release/v${new_ver}"
  84. echo_run git switch -c "$RELEASE_BRANCH"
  85. # --- bump version on the release branch ----
  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 release branch now."; pause
  90. queue_push push origin "$RELEASE_BRANCH"
  91. # --- create a patch from main..release branch (includes the bump) -----
  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" "$RELEASE_BRANCH" \
  95. > "$PATCH_FILE"
  96. cd ..
  97. update_follower "$SECOND_DIR"
  98. update_follower "$THIRD_DIR"
  99. # ---------- GitHub Actions Test ---------
  100. echo;
  101. echo "💻 Test GitHub Build Actions for all three repositories and then continue.";
  102. pause
  103. # --- return to primary path
  104. cd ${PRIMARY_ABS_PATH}
  105. # ---------- push queue ----------
  106. echo; echo "🚀 Ready to push changes upstream and open the release PR."
  107. echo_run git log --oneline -2
  108. read -rp "▶▶ Push everything now? (y/n): " confirm
  109. if [[ $confirm =~ ^[Yy]$ ]]; then
  110. for cmd in "${push_cmds[@]}"; do echo "+ $cmd"; bash -c "$cmd"; done
  111. echo "🎉 All pushes completed."
  112. echo; echo "📝 Opening sync PR ${RELEASE_BRANCH} → ${DEV_BRANCH} …"
  113. gh pr create \
  114. --base "$DEV_BRANCH" \
  115. --head "$RELEASE_BRANCH" \
  116. --title "Sync v${new_ver} version bump to dev" \
  117. --body "Syncs the v${new_ver} version bump from the release branch back to \`dev\` so subsequent auto-bumps on \`dev\` continue from the released minor.
  118. \`auto_version_dev\` detects that \`Config.xcconfig\` was changed in this push and skips re-bumping.
  119. ⚠️ **Use rebase-merge** (not squash or merge-commit) so \`dev\` and \`main\` end up at the same commit SHA after the release."
  120. echo; echo "📝 Opening release PR ${RELEASE_BRANCH} → ${MAIN_BRANCH} …"
  121. gh pr create \
  122. --base "$MAIN_BRANCH" \
  123. --head "$RELEASE_BRANCH" \
  124. --title "Release v${new_ver}" \
  125. --body "Release v${new_ver}.
  126. Merging this PR triggers the tagging workflow, which creates tag \`v${new_ver}\` from \`LOOP_FOLLOW_MARKETING_VERSION\` in \`Config.xcconfig\`.
  127. ⚠️ **Use rebase-merge** (not squash or merge-commit) so \`dev\` and \`main\` end up at the same commit SHA after the release."
  128. echo; echo "🎉 All repos updated to v${new_ver} (local). Release PRs opened (sync → dev, release → main)."
  129. echo "👉 Review and merge both PRs — the tag will be created automatically by .github/workflows/tag_on_main.yml."
  130. echo "👉 Remember to create a GitHub release for tag v${new_ver} after the tag exists."
  131. else
  132. echo "🚫 Pushes skipped. Run manually if needed:"; printf ' %s\n' "${push_cmds[@]}"
  133. echo "🚫 Release not completed, pushes to GitHub were skipped"
  134. fi