You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

toolkit-release-make.pl 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/usr/bin/perl -w
  2. use strict;
  3. #
  4. # NOTE: tested only with Jani Laakso's environment
  5. #
  6. #
  7. # NOTE: if you need manual intervention at any point
  8. # edit this script at set an "breakpoint"
  9. # continue later with "goto STEP" and "STEP:"
  10. #
  11. # working directory to make releases
  12. my $WORKDIR = "/home/jani/crypt/tk";
  13. # directory prefix where release package zip file is stored
  14. my $SVN_ROOT = "https://svn.itmill.com/svn/itmill-toolkit";
  15. my $SVN_URL_BUILDS = $SVN_ROOT."/builds";
  16. my $usage =
  17. "Usage: toolkit-release-make.pl MERGE BRANCH VERSION TARGET [SOURCE]\n".
  18. " MERGE is of value nomerge, merge or continue\n".
  19. " BRANCH is new major.minor version, e.g. 4.0\n".
  20. " VERSION is new version, e.g. 4.0.1-rc3\n".
  21. " TARGET is directory to store release zip file, e.g. internal/4.0.1-rc/\n".
  22. " SOURCE is SVN URL used to create release, if omitted then trunk used\n".
  23. "\n".
  24. "Description of MERGE parameter\n".
  25. " nomerge : no merging is performed, build is fully based on SOURCE.\n".
  26. " merge : after BRANCH created, allows manual merging.\n".
  27. " continue : called after manual merging completed.\n\n".
  28. "Examples:\n\n".
  29. "No merging example:\n".
  30. "toolkit-release-make.pl nomerge 4.0 4.0.1-testing2 internal/4.0.1-rc\n".
  31. " Recreates 4.0 branch from trunk,\n".
  32. " continues automatically with build (no merging allowed),\n".
  33. " release is fully based on trunk.\n\n".
  34. "No merging example:\n".
  35. "toolkit-release-make.pl nomerge 4.1 4.1.0 release\n".
  36. " Recreates 4.1 branch from trunk,\n".
  37. " continues automatically with build (no merging allowed),\n".
  38. " release is fully based on trunk.\n\n".
  39. "Merging example (two phases required):\n".
  40. "Phase 1\n".
  41. " toolkit-release-make.pl merge 4.0 4.0.1-pre_mantis release tags/4.0.0\n".
  42. " Recreates 4.0 branch from tags/4.0.0,\n".
  43. " buildprocess is suspended,\n".
  44. " buildmaster performs merging manually,\n".
  45. " buildmaster executes script again (see below).\n".
  46. "Phase 2\n".
  47. " toolkit-release-make.pl continue 4.0 4.0.1-pre_mantis release tags/4.0.0\n".
  48. " Buildprocess continues (buildmaster has done merging).\n";
  49. my $MERGE = shift(@ARGV) || &failure($usage);
  50. my $BRANCH = shift(@ARGV) || &failure($usage);
  51. my $VERSION = shift(@ARGV) || &failure($usage);
  52. my $TARGET = shift(@ARGV) || &failure($usage);
  53. my $SOURCE = shift(@ARGV) || 'trunk';
  54. my $t = "";
  55. if (
  56. ($MERGE ne "merge" ) &&
  57. ($MERGE ne "continue" )
  58. ) {
  59. &failure ("\nMERGE must be of value merge or continue\n");
  60. }
  61. if (!$BRANCH =~ /([4-9]{1}\.[0-9]{1})/) {
  62. &failure ("\nBRANCH must be format {x}.{y} where {x}=major (4-9), ".
  63. "{y}=minor (0-9).\n");
  64. }
  65. if (
  66. (!$VERSION =~ /[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}/) &&
  67. (!$VERSION =~ /[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}-rc[0-9]{1,2}/)
  68. ) {
  69. &failure ("\nVERSION must be format {x}.{y}.{z} or x.y.z-rc{m} ".
  70. "where {x}=major (4-9), {y}=minor (0-99), {z}=revision ".
  71. "(0-999) and optional release candidate number {m}=(0-99).\n");
  72. }
  73. if (
  74. (!$TARGET =~ /release\/[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}/) &&
  75. (!$TARGET =~ /internal\/[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}-rc[0-9]{1,2}/)
  76. ) {
  77. &failure ("\nTARGET must be e.g. internal/4.0.1-rc/ or release/4.0.\n");
  78. }
  79. # Open log file
  80. open(LOG, ">>$WORKDIR/builds/$TARGET/itmill-toolkit-$VERSION.make.log");
  81. #
  82. # If MERGE=continue, buildmaster has performed merging and now asks
  83. # build script to continue making the release.
  84. #
  85. if ($MERGE eq "continue") {
  86. &message(" Buildprocess continued. Buildmaster has performed merging. ");
  87. goto CONTINUE;
  88. }
  89. # Make sure $WORKDIR directory exists
  90. &message(
  91. "\n MERGE [$MERGE]\n BRANCH [$BRANCH]\n VERSION [$VERSION]\n".
  92. " DIR [$SVN_URL_BUILDS/$TARGET]\n".
  93. " SOURCE [$SOURCE]\n"
  94. );
  95. # collect data from host
  96. &message(" Host information ");
  97. &execute("date -R");
  98. &execute("uname -a");
  99. &execute("java -version");
  100. &execute("ant -version");
  101. &message(" Initializing repositories ");
  102. # go to directory where repository working copies (WC) are
  103. chdir($WORKDIR) || &failure("Could not chdir to $WORKDIR.\n");
  104. # delete old repo
  105. &execute("rm -rf $BRANCH");
  106. # ensure that target directory exists
  107. &execute("svn mkdir $SVN_ROOT/builds/$TARGET -m \"Added $TARGET directory\"");
  108. &execute("svn ci $SVN_ROOT/builds/$TARGET");
  109. # checkout (if missing) build repository
  110. &execute("svn co $SVN_ROOT/builds | grep \"Checked out\"");
  111. # it's safest to replace $BRANCH from $SOURCE (but you could use also merging)
  112. &execute(
  113. "svn rm $SVN_ROOT/branches/$BRANCH ".
  114. "-m \"Recreating $BRANCH branch from $SOURCE. Removing old $BRANCH.\""
  115. );
  116. &execute(
  117. "svn copy $SVN_ROOT/$SOURCE $SVN_ROOT/branches/$BRANCH ".
  118. "-m \"Recreating $BRANCH branch from $SOURCE. Copying new $BRANCH.\""
  119. );
  120. # checkout $BRANCH
  121. &execute("svn co $SVN_ROOT/branches/$BRANCH | grep \"Checked out\"");
  122. # Use brakepoint if you need to do additional merging or
  123. # file based revision changes
  124. # BRAKEPOINT, disabled
  125. #
  126. # Check if buildmaster wishes to do merging at this point
  127. # or continue directly with building?
  128. #
  129. if ($MERGE eq "merge") {
  130. # Yes, merging required
  131. &message(" Buildprocess suspended. Buildmaster now performs merging manually ");
  132. print "".
  133. "Please now perform merging manually and after that execute:\n".
  134. "toolkit-release-make.pl continue $BRANCH $VERSION $TARGET $SOURCE\n".
  135. close(LOG);
  136. exit;
  137. } else {
  138. # No, merging not required
  139. # Either merging is complete and building is continued,
  140. # OR merging not even performed, build is based on e.g. trunk
  141. }
  142. CONTINUE:
  143. &message(" Changing VERSION");
  144. # go to $BRANCH directory
  145. chdir("$WORKDIR/$BRANCH");
  146. # fix links as VERSION changes
  147. &execute(
  148. "sed s/`cat build/VERSION | cut -f2 -d'='`/$VERSION/ ".
  149. "index.html >/tmp/index.html"
  150. );
  151. &execute("diff index.html /tmp/index.html");
  152. &execute("cp /tmp/index.html index.html");
  153. # increment VERSION
  154. &execute("echo \"version=$VERSION\" >build/VERSION");
  155. &message(" Commit changes ");
  156. # commit changes
  157. &execute("svn ci -m \"Building $VERSION release.\"");
  158. &message(" Executing ant ");
  159. # execute build script, takes 5-40 minutes depending on hw
  160. chdir("$WORKDIR/$BRANCH/build");
  161. &execute("ant");
  162. &message(" Copying branch $BRANCH under tags branch");
  163. # copy branch $BRANCH into tags directory (some may interpret this as tagging)
  164. &execute(
  165. "svn copy $SVN_ROOT/branches/$BRANCH $SVN_ROOT/tags/$VERSION ".
  166. "-m \"Copying $VERSION release into tags.\""
  167. );
  168. &message(" Committing release package zip file to builds dir ");
  169. # commit release package zip to SVN
  170. &execute("cp result/itmill-toolkit-$VERSION.zip $WORKDIR/builds/$TARGET");
  171. chdir("$WORKDIR/builds/$TARGET");
  172. &execute("svn add itmill-toolkit-$VERSION.zip");
  173. &execute(
  174. "svn ci itmill-toolkit-$VERSION.zip ".
  175. "-m \"Added $VERSION release package.\""
  176. );
  177. &message(" Done ");
  178. # store log to SVN
  179. close(LOG);
  180. `svn add $WORKDIR/builds/$TARGET/itmill-toolkit-$VERSION.make.log`;
  181. `svn ci $WORKDIR/builds/$TARGET/itmill-toolkit-$VERSION.make.log -m \"Release $VERSION build completed. See toolkit-release-make log file.\"`;
  182. exit;
  183. sub message() {
  184. my $msg = shift;
  185. $msg = "\n***".$msg."***\n";
  186. print $msg;
  187. print LOG $msg;
  188. }
  189. sub execute() {
  190. my $cmd = shift;
  191. print " $cmd\n";
  192. print LOG " $cmd\n";
  193. my $result = `$cmd 2>/dev/stdout`;
  194. print $result."\n";
  195. print LOG $result."\n";
  196. }
  197. sub failure() {
  198. my $msg = shift;
  199. print $msg."\n";
  200. exit;
  201. }