@neferbyte/cherry-release-cli 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cherry-release +32 -27
  2. package/package.json +5 -2
@@ -3,7 +3,6 @@ set -e
3
3
 
4
4
  # ─── Constants ────────────────────────────────────────────────────────────────
5
5
 
6
- ALL_BRANCHES=(development staging production)
7
6
  ORIGINAL_BRANCH=$(git rev-parse --abbrev-ref HEAD)
8
7
  WORKTREE_DIR="/tmp/cherry-release-test"
9
8
  WORKTREES_TO_CLEAN=()
@@ -12,8 +11,9 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
12
11
  # ─── Parse --force flag ──────────────────────────────────────────────────────
13
12
 
14
13
  FORCE_ALL=false
15
- declare -A FORCE_BRANCH
16
- for b in "${ALL_BRANCHES[@]}"; do FORCE_BRANCH[$b]=false; done
14
+ FORCE_development=false
15
+ FORCE_staging=false
16
+ FORCE_production=false
17
17
 
18
18
  if [[ "$1" == "--force" ]]; then
19
19
  shift
@@ -21,18 +21,12 @@ if [[ "$1" == "--force" ]]; then
21
21
  FORCE_ALL=true
22
22
  else
23
23
  for arg in "$@"; do
24
- found=false
25
- for b in "${ALL_BRANCHES[@]}"; do
26
- if [[ "$arg" == "$b" ]]; then
27
- FORCE_BRANCH[$b]=true
28
- found=true
29
- break
30
- fi
31
- done
32
- if [[ "$found" == false ]]; then
33
- echo -e "\033[1;31mError:\033[0m Unknown branch '$arg'. Valid branches: ${ALL_BRANCHES[*]}" >&2
34
- exit 1
35
- fi
24
+ case "$arg" in
25
+ development) FORCE_development=true ;;
26
+ staging) FORCE_staging=true ;;
27
+ production) FORCE_production=true ;;
28
+ *) echo -e "\033[1;31mError:\033[0m Unknown branch '$arg'. Valid branches: development staging production" >&2; exit 1 ;;
29
+ esac
36
30
  done
37
31
  shift $#
38
32
  fi
@@ -53,11 +47,18 @@ check_ok() {
53
47
  echo -e " \033[1;32m✓\033[0m $1"
54
48
  }
55
49
 
50
+ is_forced() {
51
+ local branch=$1
52
+ [[ "$FORCE_ALL" == true ]] && return 0
53
+ local var="FORCE_$branch"
54
+ [[ "${!var}" == true ]] && return 0
55
+ return 1
56
+ }
57
+
56
58
  should_deploy() {
57
59
  local branch=$1
58
60
  local commit_count=$2
59
- [[ "$FORCE_ALL" == true ]] && return 0
60
- [[ "${FORCE_BRANCH[$branch]}" == true ]] && return 0
61
+ is_forced "$branch" && return 0
61
62
  [[ "$commit_count" -gt 0 ]] && return 0
62
63
  return 1
63
64
  }
@@ -133,31 +134,34 @@ done
133
134
  check_ok "No local-only commits on staging/production"
134
135
 
135
136
  # 7. Auto-discover commits to promote (per target branch)
136
- declare -A COMMITS_FOR
137
+ COMMITS_staging=""
138
+ COMMITS_production=""
139
+
137
140
  for branch in staging production; do
138
141
  hashes=$(git cherry "origin/$branch" origin/development | grep '^+' | awk '{print $2}')
139
142
 
140
143
  # Filter out version bump commits (commit-and-tag-version)
141
- filtered=()
144
+ filtered=""
142
145
  for hash in $hashes; do
143
146
  msg=$(git log -1 --format="%s" "$hash")
144
147
  if [[ ! "$msg" =~ ^chore\(release\): ]]; then
145
- filtered+=("$hash")
148
+ filtered="$filtered $hash"
146
149
  fi
147
150
  done
148
151
 
149
- COMMITS_FOR[$branch]="${filtered[*]}"
152
+ eval "COMMITS_${branch}=\"${filtered# }\""
150
153
  done
151
154
 
152
- staging_count=$(echo "${COMMITS_FOR[staging]}" | wc -w | tr -d ' ')
153
- production_count=$(echo "${COMMITS_FOR[production]}" | wc -w | tr -d ' ')
155
+ staging_count=$(echo $COMMITS_staging | wc -w | tr -d ' ')
156
+ production_count=$(echo $COMMITS_production | wc -w | tr -d ' ')
154
157
 
155
158
  # Check if there's anything to do
156
159
  has_work=false
157
- for branch in "${ALL_BRANCHES[@]}"; do
160
+ for branch in development staging production; do
158
161
  count=0
159
162
  [[ "$branch" == "staging" ]] && count=$staging_count
160
163
  [[ "$branch" == "production" ]] && count=$production_count
164
+ [[ "$branch" == "development" ]] && count=$staging_count # development deploys when downstream has work
161
165
  if should_deploy "$branch" "$count"; then
162
166
  has_work=true
163
167
  break
@@ -173,7 +177,8 @@ check_ok "Discovered commits to promote (staging: $staging_count, production: $p
173
177
 
174
178
  # 8. Dry-run cherry-picks in temporary worktrees
175
179
  for branch in staging production; do
176
- commits=(${COMMITS_FOR[$branch]})
180
+ commits_var="COMMITS_${branch}"
181
+ commits=(${!commits_var})
177
182
  if [[ ${#commits[@]} -eq 0 ]]; then
178
183
  continue
179
184
  fi
@@ -217,7 +222,7 @@ else
217
222
  fi
218
223
 
219
224
  # --- staging ---
220
- staging_commits=(${COMMITS_FOR[staging]})
225
+ staging_commits=($COMMITS_staging)
221
226
  if should_deploy "staging" "${#staging_commits[@]}"; then
222
227
  step "Deploying to staging (${#staging_commits[@]} commit(s))"
223
228
  git checkout staging
@@ -236,7 +241,7 @@ else
236
241
  fi
237
242
 
238
243
  # --- production ---
239
- production_commits=(${COMMITS_FOR[production]})
244
+ production_commits=($COMMITS_production)
240
245
  if should_deploy "production" "${#production_commits[@]}"; then
241
246
  step "Deploying to production (${#production_commits[@]} commit(s))"
242
247
  git checkout production
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neferbyte/cherry-release-cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Cherry-pick commits across environment branches and tag releases",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -9,5 +9,8 @@
9
9
  },
10
10
  "files": [
11
11
  "bin/"
12
- ]
12
+ ],
13
+ "peerDependencies": {
14
+ "commit-and-tag-version": ">=12.0.0"
15
+ }
13
16
  }