forked from nocobase/nocobase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·171 lines (157 loc) · 4.2 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·171 lines (157 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
set -e
branch=$(git branch --show-current)
current_version=$(jq -r '.version' lerna.json)
IFS='.-' read -r major minor patch label pre <<< "$current_version"
DRY_RUN=false
ONLY_VERSION=false
LERNA_VERSION_ONLY=false
COMMIT_TAG_ONLY=false
EXPLICIT_VERSION=""
IS_FEAT=""
ADD_MINOR=""
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=true
shift
;;
--only-version)
ONLY_VERSION=true
shift
;;
--lerna-version-only)
LERNA_VERSION_ONLY=true
shift
;;
--commit-tag-only)
COMMIT_TAG_ONLY=true
shift
;;
--version)
EXPLICIT_VERSION="$2"
shift 2
;;
--is-feat)
IS_FEAT="--is-feat"
shift
;;
--add-minor)
ADD_MINOR="--add-minor"
shift
;;
*)
# backward compatible: allow passing flags positionally
if [[ "$1" == "--is-feat" ]]; then
IS_FEAT="--is-feat"
shift
else
shift
fi
;;
esac
done
if [[ "$LERNA_VERSION_ONLY" == "true" && "$COMMIT_TAG_ONLY" == "true" ]]; then
echo "Cannot combine --lerna-version-only with --commit-tag-only." >&2
exit 1
fi
if [[ "$COMMIT_TAG_ONLY" != "true" ]]; then
if [[ -n "$EXPLICIT_VERSION" ]]; then
new_version="$EXPLICIT_VERSION"
elif [[ "$branch" == "main" || "$branch" == "v1" ]]; then
# rc/latest-style bump
if [[ "$IS_FEAT" == "--is-feat" ]]; then
new_version="$major.$minor.0"
else
new_patch=$((patch + 1))
new_version="$major.$minor.$new_patch"
fi
elif [[ "$branch" == "next" ]]; then
# beta
if [[ "$IS_FEAT" == "--is-feat" ]]; then
if [[ "$ADD_MINOR" == "--add-minor" ]]; then
minor=$((minor + 1))
fi
new_version="$major.$minor.0-beta.1"
else
new_pre=$((pre + 1))
new_version="$major.$minor.$patch-beta.$new_pre"
fi
elif [[ "$branch" == "develop" ]]; then
# alpha
if [[ "$IS_FEAT" == "--is-feat" ]]; then
new_minor=$((minor + 1))
new_version="$major.$new_minor.0-alpha.1"
else
new_pre=$((pre + 1))
new_version="$major.$minor.$patch-alpha.$new_pre"
fi
else
echo "Unsupported branch: $branch" >&2
exit 1
fi
fi
if [[ "$ONLY_VERSION" == "true" ]]; then
echo "$new_version"
exit 0
fi
if [[ "$COMMIT_TAG_ONLY" == "true" ]]; then
VERSION=$(jq -r '.version' lerna.json)
else
if [[ "$DRY_RUN" == "true" ]]; then
echo "DRY_RUN: computed version = $new_version"
echo "DRY_RUN: would tag v$new_version in:"
echo "- nocobase/nocobase"
echo "- nocobase/pro-plugins"
if [[ -n "${PRO_PLUGIN_REPOS:-}" ]]; then
echo "$PRO_PLUGIN_REPOS" | jq -r '.[]' | while read -r i; do
echo "- nocobase/$i"
done
fi
if [[ -n "${CUSTOM_PRO_PLUGIN_REPOS:-}" ]]; then
echo "$CUSTOM_PRO_PLUGIN_REPOS" | jq -r '.[]' | while read -r i; do
echo "- nocobase/$i"
done
fi
exit 0
fi
echo "Releasing version: $new_version"
lerna version "$new_version" --preid alpha --force-publish=* --no-git-tag-version -y
if [[ "$LERNA_VERSION_ONLY" == "true" ]]; then
exit 0
fi
VERSION=$(jq -r '.version' lerna.json)
fi
commit_and_tag_if_changed() {
# `git commit` exits 1 when there is nothing to commit; with `set -e` that would abort release.
# Also, if there are no changes, we should NOT create a new version tag pointing at an old commit.
# So we only commit+tag when there are staged changes.
local version="$1"
local msg="chore(versions): 😊 publish v${version}"
local tag="v${version}"
if ! git diff --cached --quiet; then
git commit -m "$msg"
git tag "$tag"
else
echo "Skip commit+tag (no staged changes): $(pwd)"
fi
}
echo $PRO_PLUGIN_REPOS | jq -r '.[]' | while read i; do
cd ./packages/pro-plugins/@nocobase/$i
git add package.json
commit_and_tag_if_changed "$VERSION"
cd ../../../../
done
echo $CUSTOM_PRO_PLUGIN_REPOS | jq -r '.[]' | while read i; do
cd ./packages/pro-plugins/@nocobase/$i
git add package.json
commit_and_tag_if_changed "$VERSION"
cd ../../../../
done
cd ./packages/pro-plugins
git add .
commit_and_tag_if_changed "$VERSION"
#git push --atomic origin main v$VERSION
cd ../../
git add .
commit_and_tag_if_changed "$VERSION"
# git push --atomic origin main v$VERSION