-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfrontend-release.sh
More file actions
executable file
·244 lines (169 loc) · 9.23 KB
/
frontend-release.sh
File metadata and controls
executable file
·244 lines (169 loc) · 9.23 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
set -e
echo "Starting frontend release script"
if [[ $GIT_NAME == "volto-addon-template" ]]; then
echo "No release flow for templates, skipping all steps"
exit 0
fi
if [ -z "$GIT_NAME" ] || [ -z "$GIT_BRANCH" ]; then
echo "GIT repo name and branch not given"
exit 1
fi
if [ -z "$GIT_TOKEN" ]; then
echo "GIT token not given"
exit 1
fi
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
#NODEJS_VERSION=${NODEJS_VERSION:-18}
if [ -n "$NODEJS_VERSION" ]; then
echo "Received NODEJS_VERSION $NODEJS_VERSION, will use it instead of default version"
if [ $(nvm list "$NODEJS_VERSION" | grep "$NODEJS_VERSION" | wc -l) -eq 0 ]; then
echo "Did not find this version installed, will install it"
nvm install $NODEJS_VERSION
npm install -g yarn release-it yarn-deduplicate yo
fi
nvm use $NODEJS_VERSION
fi
GIT_ORG=${GIT_ORG:-'eea'}
GIT_USER=${GIT_USER:-'eea-jenkins'}
GIT_USERNAME=${GIT_USERNAME:-'EEA Jenkins'}
GIT_EMAIL=${GIT_EMAIL:-'eea-jenkins@users.noreply.github.com'}
export GITHUB_TOKEN="${GIT_TOKEN}"
GIT_SRC=https://$GIT_USER:$GIT_TOKEN@github.com/${GIT_ORG}/${GIT_NAME}.git
git config --global user.name "${GIT_USERNAME}"
git config --global user.email "${GITHUB_USER}@users.noreply.github.com"
git clone $GIT_SRC
cd $GIT_NAME
if [ -n "$GIT_CHANGE_ID" ] && [[ "$GIT_CHANGE_TARGET" == "master" ]] && [[ "$GIT_CHANGE_BRANCH" == "develop" ]]; then
git checkout $GIT_CHANGE_BRANCH
fi
cd ..
if [ ! -f $GIT_NAME/package.json ]; then
rm -rf $GIT_NAME
echo "Not a javascript package, the check was wrong"
/docker-entrypoint.sh $@
exit 0
fi
if [[ ! "${GIT_NAME,,}" =~ ^.*frontend$ ]] && [[ ! "${GIT_NAME,,}" =~ ^.*storybook$ ]]; then
rm -rf $GIT_NAME
echo "Not a frontend package, the check was wrong"
/docker-entrypoint.sh $@
exit 0
fi
cd "$GIT_NAME"
#if PR
if [ -n "$GIT_CHANGE_ID" ] && [[ "$GIT_CHANGE_TARGET" == "master" ]] && [[ "$GIT_CHANGE_BRANCH" == "develop" ]]; then
git checkout $GIT_CHANGE_BRANCH
existing_tags=$(git tag)
echo "Check if CHANGELOG exists, if not, create it"
if [ ! -f CHANGELOG.md ]; then
touch CHANGELOG.md
git add CHANGELOG.md
git commit -m "Add empty CHANGELOG.md file"
git push
fi
echo "Starting pre-release on PULL REQUEST"
if [ -z "$existing_tags" ]; then
echo "There are no tags, we need to first release initial version"
git checkout master
version=$(grep '"version"' package.json | awk -F'"' '{print $4}')
git tag -a $version -m "Initial release"
git push origin tag $version
git checkout $GIT_CHANGE_BRANCH
fi
version=$(grep '"version"' package.json | awk -F'"' '{print $4}')
#check if version was already updated
git fetch --tags
#if [ $(git diff --name-status ${GIT_CHANGE_BRANCH}..${GIT_CHANGE_TARGET} | wc -l) -eq 0 ]; then
# echo "There are no changes to release"
# exit 0
#fi
echo "Check if format is x.y.z, x.y.z-beta.[0-9]*, or x.y.z-alpha.[0-9]*"
if [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | wc -l) -eq 0 ] && [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9\.]+$' | wc -l) -eq 0 ] && [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9\.]+$' | wc -l) -eq 0 ]; then
echo "Current package.json version $version format is not major.minor.patch nor beta format major.minor.patch-beta.version nor alpha format major.minor.patch-alpha.version"
echo "Please manually update the format to a correct version ( major.minor.patch ) "
exit 1
fi
/wait_jenkins_branch_status.sh
if [ $(git tag | grep ^${version}$ | wc -l) -eq 1 ] || [ $(git tag | grep ^v${version}$ | wc -l) -eq 1 ] || [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$' | wc -l) -eq 1 ]; then
echo "Current version is either already released or a beta version"
echo "Start release with changelog update on new version"
#echo "Starting the update yarn.lock from a clean plone/volto"
#volto_version=$(cat package.json | jq -r '.dependencies["@plone/volto"]')
#echo "Found volto version $volto_version"
#yo @plone/volto --volto=$volto_version --no-interactive clean-frontend
#cp clean-frontend/yarn.lock .
#rm -rf clean-frontend
#yarn
if [ $(yarn -v | grep ^1 | wc -l) -eq 1 ]; then
echo "Running yarn-deduplicate"
yarn-deduplicate yarn.lock
fi
if [ $(git diff yarn.lock | wc -l) -gt 0 ]; then
echo "Found changes in yarn.lock, will now update it"
git add yarn.lock
git commit -m "chore: [YARN] Automated update of yarn.lock using clean volto"
fi
new_version=$(echo $version | awk -F'[.\-]' '{ print $1"."$2+1".0"}')
sed -i "s/%2F[0-9]\+\.[0-9]\+\.[0-9]\+\&build=last\&subject=release%20v[0-9]\+\.[0-9]\+\.[0-9]\+%20pipeline/%2F${new_version}\&build=last\&subject=release%20v${new_version}%20pipeline/" README.md
sed -i "s#job/[0-9]\+\.[0-9]\+\.[0-9]\+/lastBuild/display#job/$new_version/lastBuild/display#" README.md
if [ $(git diff README.md | wc -l) -gt 0 ]; then
echo "Updating README.md with the next release link"
git add README.md
git commit -m "docs: [JENKINS] Automated badge update of README.md"
fi
release-it version=$new_version --config /release-it.json --no-git.tag -i patch --ci
else
echo "Existing version is not yet released, will only auto-update changelog"
sed -i "s/%2F[0-9]\+\.[0-9]\+\.[0-9]\+\&build=last\&subject=release%20v[0-9]\+\.[0-9]\+\.[0-9]\+%20pipeline/%2F${version}\&build=last\&subject=release%20v${version}%20pipeline/" README.md
sed -i "s#job/[0-9]\+\.[0-9]\+\.[0-9]\+/lastBuild/display#job/$version/lastBuild/display#" README.md
to_push=""
if [ $(git diff README.md | wc -l) -gt 0 ]; then
echo "Updating README.md with the next release link"
git add README.md
git commit -m "docs: [JENKINS] Automated badge update of README.md"
to_push="yes"
fi
npx_command=$(grep after:bump /release-it.json | awk -F'"' '{print $4}' | awk -F';' '{print $1}' )
sh -c "$npx_command"
sed -i '/ Automated release [0-9\.]\+ \|Autobuild of storybook docs\|Add Sonarqube tag using .* addons list\|\[[jJ][eE][nN][kK][iI][nN][sS]\]\|\[[yY][aA][rR][nN]\]/d' CHANGELOG.md
if [ $(git diff CHANGELOG.md | tail -n +5 | grep ^+ | grep -Eiv '\- Automated release [0-9\.]+|Autobuild of storybook docs|Add Sonarqube tag using .* addons list|\[[jJ][eE][nN][kK][iI][nN][sS]\]|\[[yY][aA][rR][nN]\]' | wc -l ) -gt 0 ]; then
# there were other commits besides the automated release ones"
git add CHANGELOG.md
git commit -m "Automated release $version"
git push
else
echo "Did not find any new commits beside the automated ones, will not add them"
git checkout -- CHANGELOG.md
if [[ "$to_push" == "yes" ]]; then
echo "Will not regenerate CHANGELOG.md, but will update README.md with the new version"
git push
fi
fi
fi
fi
if [ -z "$GIT_CHANGE_ID" ] && [[ "$GIT_BRANCH" == "master" ]] ; then
echo "Starting release on github"
version=$(grep '"version"' package.json | awk -F'"' '{print $4}')
echo "Check if format is x.y.z, x.y.z-beta.[0-9]*, or x.y.z-alpha.[0-9]*"
if [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | wc -l) -eq 0 ] && [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9\.]+$' | wc -l) -eq 0 ] && [ $(echo $version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9\.]+$' | wc -l) -eq 0 ]; then
echo "Version format is not major.minor.patch(-(alpha|beta).version), will skip automated tag creation, please check the error"
exit 1
fi
#check if version was already updated
git fetch --tags
if [ $(git tag | grep ^${version}$ | wc -l) -eq 1 ]; then
echo "GitHub release already done, skipping tag creation"
else
#echo "Starting GitHub release of version ${version}"
#release-it -v
#sed -i 's/"release": false,/"release": true,/' /release-it.json
#release-it --no-increment --no-git --github.release --config /release-it.json --ci
echo "Create release on $GIT_BRANCH using GitHub API"
/releaseChangelog.sh
body=$(cat releasefile | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' | sed 's/"/\\\"/g' | sed 's/[R|r]efs #\([0-9]*\)/Refs \[#\1\]\(https:\/\/taskman.eionet.europa.eu\/issues\/\1\)/g' | sed 's/\\\*/\\\\\*/' | head -c 124850)
echo "{\"tag_name\": \"$version\",\"name\": \"$version\", \"target_commitish\":\"${GIT_BRANCH}\", \"body\": \"$body\"}" > releasefile
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: bearer $GITHUB_TOKEN" -d @releasefile https://api.github.com/repos/${GIT_ORG}/${GIT_NAME}/releases
fi
fi