summaryrefslogtreecommitdiffstats
path: root/build/toolkit-release-make.pl
blob: 041886672e7ef848db792d54a828f750ecf80fd5 (plain)
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
#!/usr/bin/perl -w

use strict;

#
# NOTE: tested only with Jani Laakso's environment
#

#
# NOTE: if you need manual intervention at any point
# edit this script at set an "breakpoint"
# continue later with "goto STEP" and "STEP:"
#

# working directory to make releases
my $WORKDIR = "/home/jani/crypt/tk";

# directory prefix where release package zip file is stored
my $SVN_ROOT = "https://svn.itmill.com/svn/itmill-toolkit";
my $SVN_URL_BUILDS = $SVN_ROOT."/builds";

my $usage = 
  "Usage: toolkit-release-make.pl MERGE BRANCH VERSION TARGET [SOURCE]\n".
  " MERGE is of value nomerge, merge or continue\n".
  " BRANCH is new major.minor version, e.g. 4.0\n".
  " VERSION is new version, e.g. 4.0.1-rc3\n".
  " TARGET is directory to store release zip file, e.g. internal/4.0.1-rc/\n".
  " SOURCE is SVN URL used to create release, if omitted then trunk used\n".
  "\n".
  "Description of MERGE parameter\n".
  " nomerge  : no merging is performed, build is fully based on SOURCE.\n".
  " merge    : after BRANCH created, allows manual merging.\n".
  " continue : called after manual merging completed.\n\n".
  "Examples:\n\n".
  "No merging example:\n".
  "toolkit-release-make.pl nomerge 4.1 4.1.0 release\n".
  "  Recreates 4.1 branch from trunk,\n".
  "  continues automatically with build (no merging allowed),\n".
  "  release is fully based on trunk.\n\n".
  "Merging example (two phases required):\n".
  "Phase 1\n".
  " toolkit-release-make.pl merge 4.0 4.0.1-pre_mantis release tags/4.0.0\n".
  "  Recreates 4.0 branch from tags/4.0.0,\n".
  "  buildprocess is suspended,\n".
  "  buildmaster performs merging manually,\n".
  "  buildmaster executes script again (see below).\n".
  "Phase 2\n".
  " toolkit-release-make.pl continue 4.0 4.0.1-pre_mantis release tags/4.0.0\n".
  "  Buildprocess continues (buildmaster has done merging).\n";

my $MERGE = shift(@ARGV) || &failure($usage);
my $BRANCH = shift(@ARGV) || &failure($usage);
my $VERSION = shift(@ARGV) || &failure($usage);
my $TARGET = shift(@ARGV) || &failure($usage);
my $SOURCE = shift(@ARGV) || 'trunk';
  
my $t = "";

if (
  ($MERGE ne "nomerge" ) &&
  ($MERGE ne "merge" ) &&
  ($MERGE ne "continue" )
  ) {
  &failure ("\nMERGE must be of value nomerge, merge or continue\n");
}
if (!$BRANCH =~ /([4-9]{1}\.[0-9]{1})/) {
  &failure ("\nBRANCH must be format {x}.{y} where {x}=major (4-9), ".
      "{y}=minor (0-9).\n");
}
if ( 
  (!$VERSION =~ /[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}/) &&
  (!$VERSION =~ /[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}-rc[0-9]{1,2}/)
  ) {
  &failure ("\nVERSION must be format {x}.{y}.{z} or x.y.z-rc{m} ".
      "where {x}=major (4-9), {y}=minor (0-99), {z}=revision ".
      "(0-999) and optional release candidate number {m}=(0-99).\n");
}
if (
  (!$TARGET =~ /release\/[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}/) &&
  (!$TARGET =~ /internal\/[4-9]{1}\.[0-9]{1,2}.[0-9]{1,3}-rc[0-9]{1,2}/)
  ) {
  &failure ("\nTARGET must be e.g. internal/4.0.1-rc/ or release/4.0.\n");
}

# Open log file
open(LOG, ">>$WORKDIR/builds/$TARGET/itmill-toolkit-$VERSION.make.log");

#
# If MERGE=continue, buildmaster has performed merging and now asks
# build script to continue making the release.
#
if ($MERGE eq "continue") {
  &message(" Buildprocess continued. Buildmaster has performed merging. ");
  goto CONTINUE;
}


# Make sure $WORKDIR directory exists
&message(
  "\n  MERGE [$MERGE]\n  BRANCH [$BRANCH]\n  VERSION [$VERSION]\n".
  "  DIR [$SVN_URL_BUILDS/$TARGET]\n".
  "  SOURCE [$SOURCE]\n"
);

# collect data from host
&message("Host information");
&execute("date -R");
&execute("uname -a");
&execute("java -version");
&execute("ant -version");

&message(" Initializing repositories ");
# go to directory where repository working copies (WC) are
chdir($WORKDIR) || &failure("Could not chdir to $WORKDIR.\n");
# delete old repo
&execute("rm -rf $BRANCH");
# checkout (if missing) build repository
&execute("svn co $SVN_ROOT/builds | grep \"Checked out\"");
# it's safest to replace $BRANCH from $SOURCE (but you could use also merging)
&execute(
  "svn rm $SVN_ROOT/branches/$BRANCH ".
  "-m \"Recreating $BRANCH branch from $SOURCE. Removing old $BRANCH.\""
);
&execute(
  "svn copy $SVN_ROOT/$SOURCE $SVN_ROOT/branches/$BRANCH ".
  "-m \"Recreating $BRANCH branch from $SOURCE. Copying new $BRANCH.\""
);
# checkout $BRANCH
&execute("svn co $SVN_ROOT/branches/$BRANCH | grep \"Checked out\"");

# Use brakepoint if you need to do additional merging or 
# file based revision changes
# BRAKEPOINT, disabled

#
# Check if buildmaster wishes to do merging at this point
# or continue directly with building?
#
if ($MERGE eq "merge") {
  # Yes, merging required
  &message(" Buildprocess suspended. Buildmaster now performs merging manually ");
  print "".
      "Please now perform merging manually and after that execute:\n".
      "toolkit-release-make.pl continue $BRANCH $VERSION $TARGET $SOURCE\n".
  close(LOG);
  exit;
} else {
  # No, merging not required
  # Either merging is complete and building is continued,
  # OR merging not even performed, build is based on e.g. trunk
}
CONTINUE:
  
&message(" Changing VERSION");
# go to $BRANCH directory
chdir("$WORKDIR/$BRANCH");
# fix links as VERSION changes
&execute(
  "sed s/`cat build/VERSION | cut -f2 -d'='`/$VERSION/ ".
  "index.html >/tmp/index.html"
);
&execute("diff index.html /tmp/index.html");
&execute("cp /tmp/index.html index.html");
# increment VERSION
&execute("echo \"version=$VERSION\" >build/VERSION");

&message(" Commit changes ");
# commit changes
&execute("svn ci -m \"Building $VERSION release.\"");

&message(" Executing ant ");
# execute build script, takes 5-40 minutes depending on hw
chdir("$WORKDIR/$BRANCH/build");
&execute("ant");

&message(" Copying branch $BRANCH under tags branch");
# copy branch $BRANCH into tags directory (some may interpret this as tagging)
&execute(
  "svn copy $SVN_ROOT/branches/$BRANCH $SVN_ROOT/tags/$VERSION ".
  "-m \"Copying $VERSION release into tags.\""
);

&message(" Committing release package zip file to builds dir ");
# commit release package zip to SVN
&execute("cp result/itmill-toolkit-$VERSION.zip $WORKDIR/builds/$TARGET");
chdir("$WORKDIR/builds/$TARGET");
&execute("svn add itmill-toolkit-$VERSION.zip");
&execute(
  "svn ci itmill-toolkit-$VERSION.zip ".
  "-m \"Added $VERSION release package.\""
);
&message(" Done ");

# store log to SVN
close(LOG);
`svn add $WORKDIR/builds/$TARGET/itmill-toolkit-$VERSION.make.log`;
`svn ci $WORKDIR/builds/$TARGET/itmill-toolkit-$VERSION.make.log -m \"Release $VERSION build completed. See toolkit-release-make log file.\"`;

exit;

sub message() {
  my $msg = shift;
  $msg = "\n***".$msg."***\n";
  print $msg;
  print LOG $msg;
}

sub execute() {
    my $cmd = shift;   
    print "  $cmd\n";
    print LOG "  $cmd\n";
    my $result = `$cmd 2>/dev/stdout`;
    print $result."\n";
    print LOG $result."\n";
}

sub failure() {
    my $msg = shift;
    print $msg."\n";
    exit;
}