]> gerrit.simantics Code Review - simantics/platform.git/blob - releng/doc/release-helper.sh
Possibility to open SCL-modules from plug-in in JAR-file
[simantics/platform.git] / releng / doc / release-helper.sh
1 #!/bin/bash
2
3 selfdir=$(dirname $(readlink -f $0))
4 self=`basename $0`
5 selfpath=$selfdir/$self
6 version=$1
7 version_xyz=`echo $version | awk 'BEGIN { FS="." } { printf("%d.%d.%d", $1, $2, $3); }'`
8 branch=$2
9 user=$3
10 action=$4
11 tagForVersion=v${version}
12 shift 4
13
14 rundir=`pwd`
15 versiondir=$rundir/$version
16
17 ###############################################################################
18
19 declare -a repositories=(
20    "simantics/third-party.git" "third-party"
21    "simantics/platform.git" "platform"
22    "simantics/fmil.git" "fmil"
23    "simantics/interop.git" "interop"
24    "simantics/district.git" "district"
25    "simantics/matlab.git" "matlab"
26    "simantics/python.git" "python"
27    "simantics/r.git" "r"
28    "simantics/sysdyn.git" "sysdyn"
29    "simantics/3d.git" "3d"
30    "members/fmi.git" "fmi"
31    "members/simupedia.git" "simupedia"
32    "gold-members/proteus.git" "proteus"
33 )
34
35 repositoryCount=$((${#repositories[@]} / 2))
36
37 function repo {
38         eval $1=\${repositories[$(($2 * 2))]}
39 }
40
41 function localPath {
42         eval $1=\${repositories[$(($2 * 2 + 1))]}
43 }
44
45 function version_xyz {
46         echo $version
47 }
48
49 ###############################################################################
50
51 function msg {
52         echo "[$(($1+1))/${repositoryCount}] $2"
53 }
54
55 function clone {
56         echo "git clone ssh://${user}@www.simantics.org:29418/$1"
57         git clone ssh://${user}@www.simantics.org:29418/$1
58 }
59
60 function add {
61         echo "git add $@"
62         git add $@
63 }
64
65 function branch {
66         echo "git branch $1"
67         git branch $1
68 }
69
70 function commit {
71         echo "git commit $@"
72         git commit $@
73 }
74
75 function fetch {
76         echo "git fetch --all"
77         git fetch --all
78 }
79
80 function pull {
81         echo "git pull --all"
82         git pull --all
83 }
84
85 function pushBranch {
86         echo "git push origin $1"
87         git push origin $1
88 }
89
90 function checkout {
91         echo "git checkout $1"
92         git checkout $1
93 }
94
95 function tag {
96         echo "git tag $1 -m \"Simantics $1 simultaneous release\""
97         git tag $1 -m "Simantics $1 simultaneous release"
98 }
99
100 function removeTag {
101         echo "git tag -d $1"
102         git tag -d $1
103 }
104
105 function pushTags {
106         echo "git push origin --tags"
107         git push origin --tags
108 }
109
110 function status {
111         git status $@
112 }
113
114 function diff {
115         git diff --stat --patch $@
116 }
117
118 function log {
119         git log --pretty --oneline --graph --decorate=full $@
120 }
121
122 function listTags {
123         git tag -l
124 }
125
126 function listBranches {
127         git branch -a
128 }
129
130 function repl {
131         local from=$1
132         local to=$2
133         shift 2
134         for i in $@; do
135                 echo "Replacing $from' with '$to' in file $i"
136                 cat $i | awk "{ gsub(\"$from\", \"$to\"); print }" > $i.tmp
137                 mv $i.tmp $i
138         done
139 }
140
141 function bumpSequenceNumber {
142         echo "bumpSequenceNumber '$1'"
143         cat $i | awk '
144 BEGIN {
145         regex="sequenceNumber=\"[0-9]+\"";
146         cmd = "date +%s"
147         cmd | getline epoch
148         close(cmd)
149 }
150 {
151         if (match($0, regex)) {
152                 before = substr($0,1,RSTART-1);
153                 after = substr($0,RSTART+RLENGTH);
154                 printf("%ssequenceNumber=\"%s\"%s\n", before, epoch, after);
155         } else {
156                 print;  
157         }
158 }
159 ' > $i.tmp
160         mv $i.tmp $i
161 }
162
163 ###############################################################################
164
165 case "$action" in
166         clone)
167                 mkdir -p $version
168                 pushd $version > /dev/null
169                 for (( i=0; i<${repositoryCount}; i++ )); do
170                         repo p $i
171                         msg $i "Clone $p"
172                         clone $p
173                 done
174                 popd > /dev/null
175                 exit 0
176         ;;
177 esac
178
179 if [ -n "$version" ] && [ -d $version ]; then
180         pushd $version >/dev/null || action="*"
181 elif [ -n "$version" ]; then
182         # The directory does not exist yet so don't do anything
183         action="*"
184 fi
185
186 case "$action" in
187         add)
188                 for (( i=0; i<${repositoryCount}; i++ )); do
189                         localPath lp $i
190                         msg $i "Stage changes in $lp"
191                         pushd $lp > /dev/null
192                         add $@
193                         popd > /dev/null
194                 done
195         ;;
196         branch)
197                 for (( i=0; i<${repositoryCount}; i++ )); do
198                         localPath lp $i
199                         msg $i "Create $branch branch in $lp"
200                         pushd $lp > /dev/null
201                         branch $branch
202                         popd > /dev/null
203                 done
204         ;;
205         checkout)
206                 for (( i=0; i<${repositoryCount}; i++ )); do
207                         localPath lp $i
208                         msg $i "Checkout $branch branch in $lp"
209                         pushd $lp > /dev/null
210                         checkout $branch
211                         popd > /dev/null
212                 done
213         ;;
214         commit)
215                 for (( i=0; i<${repositoryCount}; i++ )); do
216                         localPath lp $i
217                         msg $i "Checkout $branch branch in $lp"
218                         pushd $lp > /dev/null
219                         commit $@
220                         popd > /dev/null
221                 done
222         ;;
223         tag)
224                 for (( i=0; i<${repositoryCount}; i++ )); do
225                         localPath lp $i
226                         msg $i "Tag ${version} for $lp"
227                         pushd $lp > /dev/null
228                         checkout $branch
229                         tag ${tagForVersion}
230                         popd > /dev/null
231                 done
232         ;;
233         list-branches)
234                 for (( i=0; i<${repositoryCount}; i++ )); do
235                         localPath lp $i
236                         msg $i "List branches in $lp"
237                         pushd $lp > /dev/null
238                         listBranches
239                         popd > /dev/null
240                 done
241         ;;
242         list-tags)
243                 for (( i=0; i<${repositoryCount}; i++ )); do
244                         localPath lp $i
245                         msg $i "List tags in $lp"
246                         pushd $lp > /dev/null
247                         listTags
248                         popd > /dev/null
249                 done
250         ;;
251         remove-tag)
252                 for (( i=0; i<${repositoryCount}; i++ )); do
253                         localPath lp $i
254                         msg $i "Remove tag $tagForVersion from $lp"
255                         pushd $lp > /dev/null
256                         removeTag ${tagForVersion}
257                         popd > /dev/null
258                 done
259         ;;
260         fetch)
261                 for (( i=0; i<${repositoryCount}; i++ )); do
262                         localPath lp $i
263                         msg $i "Fetch from remote origin in $lp"
264                         pushd $lp > /dev/null
265                         fetch
266                         popd > /dev/null
267                 done
268         ;;
269         pull)
270                 for (( i=0; i<${repositoryCount}; i++ )); do
271                         localPath lp $i
272                         msg $i "Pull from remote origin in $lp"
273                         pushd $lp > /dev/null
274                         pull
275                         popd > /dev/null
276                 done
277         ;;
278         push)
279                 for (( i=0; i<${repositoryCount}; i++ )); do
280                         localPath lp $i
281                         msg $i "Push branch $branch to remote origin in $lp"
282                         pushd $lp > /dev/null
283                         pushBranch $branch
284                         popd > /dev/null
285                 done
286         ;;
287         push-tags)
288                 for (( i=0; i<${repositoryCount}; i++ )); do
289                         localPath lp $i
290                         msg $i "Push tags to remote origin in $lp"
291                         pushd $lp > /dev/null
292                         pushTags
293                         popd > /dev/null
294                 done
295         ;;
296         status)
297                 for (( i=0; i<${repositoryCount}; i++ )); do
298                         localPath lp $i
299                         msg $i "Status of $lp"
300                         pushd $lp > /dev/null
301                         status $@
302                         popd > /dev/null
303                 done
304         ;;
305         diff)
306                 for (( i=0; i<${repositoryCount}; i++ )); do
307                         localPath lp $i
308                         msg $i "Diff $branch branch in $lp"
309                         pushd $lp > /dev/null
310                         diff $@
311                         popd > /dev/null
312                 done
313         ;;
314         log)
315                 for (( i=0; i<${repositoryCount}; i++ )); do
316                         localPath lp $i
317                         msg $i "Log of $lp"
318                         pushd $lp > /dev/null
319                         log $@
320                         popd > /dev/null
321                 done
322         ;;
323         reset)
324                 for (( i=0; i<${repositoryCount}; i++ )); do
325                         localPath lp $i
326                         msg $i "'git reset $@' in $lp"
327                         pushd $lp > /dev/null
328                         git reset $@
329                         popd > /dev/null
330                 done
331         ;;
332         
333         prepare-release-branch)
334                 fromBranch=$1
335                 
336                 # Fix branch name from P2 repository locations
337                 for i in platform/releng/org.simantics.sdk.build.targetdefinition/*.{tpd,target} \
338                         simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
339                 do
340                         repl "/$fromBranch/" "/$branch/" $i
341                 done
342         
343                 # Bump .target file sequenceNumbers
344                 for i in platform/releng/org.simantics.sdk.build.targetdefinition/*.target \
345                         simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
346                 do
347                         bumpSequenceNumber $i
348                 done
349
350                 pushd platform
351                 git commit -a -m "Configured $branch branch for SDK builds"
352                 git commit --amend
353                 popd
354
355                 pushd simupedia
356                 git commit -a -m "Configured $branch branch for SDK builds"
357                 git commit --amend
358                 popd
359         ;;
360
361         bump-master-version)
362                 fromVersion=$1
363                 toVersion=$2
364
365                 bash $selfpath $version master $user checkout
366
367                 repl "$fromVersion" "$toVersion" platform/bundles/org.simantics.desktop.product/splash.svg
368                 repl "$fromVersion" "$toVersion" platform/features/org.simantics.sdk.feature/feature.xml
369                 repl "$fromVersion" "$toVersion" platform/releng/org.simantics.sdk.repository/pom.xml
370                 repl "Simantics $fromVersion" "Simantics $toVersion" platform/releng/org.simantics.sdk.build.targetdefinition/simantics.{tpd,target}
371                 repl "Simupedia $fromVersion" "Simupedia $toVersion" simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
372                 repl "Simupedia SDK $fromVersion" "Simupedia SDK $toVersion" simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
373
374                 pushd platform
375                 git commit -a -m "Bumped master version to $toVersion"
376                 git commit --amend
377                 popd
378
379                 pushd simupedia
380                 git commit -a -m "Bumped master version to $toVersion"
381                 git commit --amend
382                 popd
383         ;;
384
385         branch-release)
386                 fromBranch=$1
387                 popd > /dev/null
388                 bash $selfpath $version $fromBranch $user checkout
389                 bash $selfpath $version $branch $user branch
390                 bash $selfpath $version $branch $user checkout
391                 bash $selfpath $version $branch $user prepare-release-branch $fromBranch
392                 #$selfpath $version $branch $user push
393         ;;
394
395         *)
396                 if [ "$version" ] && [ ! -d $versiondir ]; then
397                         echo -e "Version directory ('$versiondir') does not exist yet. Run 'clone' action first.\n"
398                 fi
399                 echo "Usage: ${self} <version> <branch-name> <user-name> <command> [<command-arguments>]"
400                 echo ""
401                 echo "Commands:"
402                 echo "    clone                The first thing that needs to be done before anything else"
403                 echo "                         Clones all platform repositories under directory <version>"
404                 echo ""
405                 echo "Inspection commands:"
406                 echo "    diff [args]          Run git diff [args] for each platform repository"
407                 echo "    log [args]           Run git log [args] for each platform repository"
408                 echo "    status [args]        Run git status [args] for each platform repository"
409                 echo "    list-tags            Run git tag -l for each repository"
410                 echo ""
411                 echo "Action:"
412                 echo "    add                  "
413                 echo "    branch               Run git branch <branch-name> for each platform repository"
414                 echo "    checkout             Run git checkout <branch-name> for each repository"
415                 echo "    commit               "
416                 echo "    fetch                Run git fetch --all for each repository"
417                 echo "    pull                 Run git pull --all for each repository"
418                 echo "    push                 Run git push origin <branch> for each repository"
419                 echo "    push-tags            Run git push --tags for each repository"
420                 echo "    remove-tag           Run git tag -d v<branch> for each repository"
421                 echo "    reset [args]         Run git reset [args] for each repository"
422                 echo "    tag                  Run git checkout <branch> and"
423                 echo "                         git tag -a v<branch> -m \"Simantics <branch> simultaneous release\""
424                 echo "                         for each repository"
425                 echo ""
426                 echo "Compound release commands:"
427                 echo "    prepare-release-branch <from-branch>"
428                 echo "        <from-branch>    the name of the branch that the codebase is currently on"
429                 echo ""
430                 echo "Top-level release commands:"
431                 echo "    bump-master-version <from-version> <to-version>"
432                 echo "        <from-version>   the version string to replace"
433                 echo "        <to-version>     the replacing new version string"
434                 echo ""
435                 echo "    branch-release <from-branch>"
436                 echo "        <from-branch>    the branch to create the service branch from"
437                 echo "                         e.g. master or release/x.y.z"
438                 echo ""
439                 echo "Processed repositories:"
440                 for (( i=0; i<${repositoryCount}; i++ )); do
441                         repo p $i
442                         msg $i "$p"
443                 done
444         
445 ;;
446 esac