@neferbyte/cherry-release-cli 1.0.1 → 1.0.2
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.
- package/bin/cherry-release.sh +6 -5
- package/bin/release.sh +113 -0
- package/package.json +3 -2
package/bin/cherry-release.sh
CHANGED
|
@@ -7,6 +7,7 @@ BRANCHES=(staging production)
|
|
|
7
7
|
ORIGINAL_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
8
8
|
WORKTREE_DIR="/tmp/cherry-release-test"
|
|
9
9
|
WORKTREES_TO_CLEAN=()
|
|
10
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
10
11
|
|
|
11
12
|
# ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
12
13
|
|
|
@@ -55,12 +56,12 @@ fi
|
|
|
55
56
|
check_ok "Working tree is clean"
|
|
56
57
|
|
|
57
58
|
# 3. Required tools available
|
|
58
|
-
for tool in jq sed commit-and-tag-version
|
|
59
|
+
for tool in jq sed commit-and-tag-version; do
|
|
59
60
|
if ! command -v "$tool" &>/dev/null; then
|
|
60
61
|
fail "Required tool '$tool' is not installed or not in PATH."
|
|
61
62
|
fi
|
|
62
63
|
done
|
|
63
|
-
check_ok "Required tools available (jq, sed, commit-and-tag-version
|
|
64
|
+
check_ok "Required tools available (jq, sed, commit-and-tag-version)"
|
|
64
65
|
|
|
65
66
|
# 4. Remote write access
|
|
66
67
|
if ! git push --dry-run origin HEAD &>/dev/null; then
|
|
@@ -150,7 +151,7 @@ step "Deploying to development"
|
|
|
150
151
|
|
|
151
152
|
git checkout development
|
|
152
153
|
git pull --ff-only
|
|
153
|
-
|
|
154
|
+
"$SCRIPT_DIR/release.sh" patch
|
|
154
155
|
git push --follow-tags origin development
|
|
155
156
|
echo -e " \033[1;32m✓\033[0m development released"
|
|
156
157
|
|
|
@@ -163,7 +164,7 @@ for hash in "$@"; do
|
|
|
163
164
|
git cherry-pick "$hash"
|
|
164
165
|
done
|
|
165
166
|
git push origin staging
|
|
166
|
-
|
|
167
|
+
"$SCRIPT_DIR/release.sh" patch
|
|
167
168
|
git push --follow-tags origin staging
|
|
168
169
|
echo -e " \033[1;32m✓\033[0m staging released"
|
|
169
170
|
|
|
@@ -176,7 +177,7 @@ for hash in "$@"; do
|
|
|
176
177
|
git cherry-pick "$hash"
|
|
177
178
|
done
|
|
178
179
|
git push origin production
|
|
179
|
-
|
|
180
|
+
"$SCRIPT_DIR/release.sh" patch
|
|
180
181
|
git push --follow-tags origin production
|
|
181
182
|
echo -e " \033[1;32m✓\033[0m production released"
|
|
182
183
|
|
package/bin/release.sh
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
if [[ -n $1 && ! $1 =~ ^(major|minor|patch)$ ]]; then
|
|
6
|
+
echo "Usage: $0 [major|minor|patch]"
|
|
7
|
+
exit 1
|
|
8
|
+
fi
|
|
9
|
+
|
|
10
|
+
for cmd in jq git sed commit-and-tag-version; do
|
|
11
|
+
command -v $cmd >/dev/null 2>&1 || {
|
|
12
|
+
echo "$cmd is required but not installed. Aborting."
|
|
13
|
+
exit 1
|
|
14
|
+
}
|
|
15
|
+
done
|
|
16
|
+
|
|
17
|
+
removePrerelease() {
|
|
18
|
+
newVersion=$(echo "$currentVersion" | sed 's/-.*//')
|
|
19
|
+
jq ".version = \"$newVersion\"" package.json >package.json.tmp
|
|
20
|
+
mv package.json.tmp package.json
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
currentVersion=$(jq -r '.version' package.json)
|
|
24
|
+
branch=$(git branch --show-current)
|
|
25
|
+
|
|
26
|
+
if [[ $currentVersion =~ ^[0-9]+\.[0-9]+\.[0-9]+-(dev|rc)\.[0-9]+$ ]]; then
|
|
27
|
+
currentRelease="${BASH_REMATCH[1]}"
|
|
28
|
+
mainVersion="${currentVersion%%-*}"
|
|
29
|
+
else
|
|
30
|
+
currentRelease=""
|
|
31
|
+
mainVersion="${currentVersion}"
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
case $1 in
|
|
35
|
+
major)
|
|
36
|
+
releaseType="--release-as major"
|
|
37
|
+
;;
|
|
38
|
+
|
|
39
|
+
minor)
|
|
40
|
+
releaseType="--release-as minor"
|
|
41
|
+
;;
|
|
42
|
+
|
|
43
|
+
patch)
|
|
44
|
+
releaseType="--release-as patch"
|
|
45
|
+
;;
|
|
46
|
+
|
|
47
|
+
*)
|
|
48
|
+
releaseType=""
|
|
49
|
+
;;
|
|
50
|
+
esac
|
|
51
|
+
|
|
52
|
+
case $branch in
|
|
53
|
+
development)
|
|
54
|
+
# No change - it comes from development release
|
|
55
|
+
if [[ $currentRelease = 'dev' ]]; then
|
|
56
|
+
# Release type is explicitly defined; remove prerelease to enforce it
|
|
57
|
+
if [[ -n $releaseType ]]; then
|
|
58
|
+
removePrerelease
|
|
59
|
+
fi
|
|
60
|
+
# Carry out operation; variations depend on $releaseType's value
|
|
61
|
+
commit-and-tag-version --tag-prefix "" --prerelease dev $releaseType
|
|
62
|
+
# It comes from a later stage release; pump up is mandatory; remove prerelease
|
|
63
|
+
else
|
|
64
|
+
removePrerelease
|
|
65
|
+
# No explicitly defined release type; go forward with minor
|
|
66
|
+
if [[ -z $releaseType ]]; then
|
|
67
|
+
commit-and-tag-version --tag-prefix "" --prerelease dev --release-as minor
|
|
68
|
+
# Explicitly defined release type; just go forward with it
|
|
69
|
+
else
|
|
70
|
+
commit-and-tag-version --tag-prefix "" --prerelease dev $releaseType
|
|
71
|
+
fi
|
|
72
|
+
fi
|
|
73
|
+
;;
|
|
74
|
+
|
|
75
|
+
staging)
|
|
76
|
+
# No change - it comes from staging release
|
|
77
|
+
if [[ $currentRelease = 'rc' ]]; then
|
|
78
|
+
if [[ -n $releaseType ]]; then
|
|
79
|
+
removePrerelease
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
commit-and-tag-version --tag-prefix "" --prerelease rc $releaseType
|
|
83
|
+
# It comes from dev; several things could happen
|
|
84
|
+
elif [[ $currentRelease = 'dev' ]]; then
|
|
85
|
+
# No explicitly defined release type; adopts main version by just replacing dev with rc
|
|
86
|
+
if [[ -z $releaseType ]]; then
|
|
87
|
+
commit-and-tag-version --tag-prefix "" --prerelease rc --release-as $mainVersion
|
|
88
|
+
# Explicitly defined release type; just go forward with it
|
|
89
|
+
else
|
|
90
|
+
commit-and-tag-version --tag-prefix "" --prerelease rc $releaseType
|
|
91
|
+
fi
|
|
92
|
+
# It comes from production; pump up is mandatory; remove prerelease
|
|
93
|
+
else
|
|
94
|
+
removePrerelease
|
|
95
|
+
# No explicitly defined release type; continue with minor
|
|
96
|
+
if [[ -z $releaseType ]]; then
|
|
97
|
+
commit-and-tag-version --tag-prefix "" --prerelease rc --release-as minor
|
|
98
|
+
# Explicitly defined release type; just go forward with it
|
|
99
|
+
else
|
|
100
|
+
commit-and-tag-version --tag-prefix "" --prerelease rc $releaseType
|
|
101
|
+
fi
|
|
102
|
+
fi
|
|
103
|
+
;;
|
|
104
|
+
|
|
105
|
+
production)
|
|
106
|
+
commit-and-tag-version --tag-prefix "" $releaseType
|
|
107
|
+
;;
|
|
108
|
+
|
|
109
|
+
*)
|
|
110
|
+
echo "Release is not allowed in the current branch"
|
|
111
|
+
exit 1
|
|
112
|
+
;;
|
|
113
|
+
esac
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neferbyte/cherry-release-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Cherry-pick commits across environment branches and tag releases",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
7
|
-
"cherry-release": "./bin/cherry-release.sh"
|
|
7
|
+
"cherry-release": "./bin/cherry-release.sh",
|
|
8
|
+
"cherry-release-version": "./bin/release.sh"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
11
|
"bin/"
|