Fix creation of localenv in all goals.
[goaljobs-goals.git] / libguestfs_upstream.ml
1 (* This goal script is responsible for:
2  *  - testing each new commit to the libguestfs source repo
3  *  - checking for new upstream releases of libguestfs
4  *  - testing new upstream releases
5  *  - packaging them as a source tarball
6  *  - testing the source tarball on a variety of systems
7  *  - if all the above works, uploading the external website
8  * Note this doesn't build the Fedora releases.  See 'libguestfs_fedora.ml'.
9  *)
10
11 open Goaljobs
12 open Printf
13 open Config
14
15 (* Enable debugging. *)
16 let () =
17   Unix.putenv "LIBGUESTFS_DEBUG" "1";
18   Unix.putenv "LIBGUESTFS_TRACE" "1"
19
20 (* Log program output. *)
21 let from = "rjones@redhat.com"
22 let to_ = "rjones@redhat.com"
23 let logfile = log_program_output ()
24 let () = eprintf "logging to %s\n%!" logfile
25
26 let package = "libguestfs"
27
28 (* Helper object which stores everything about a version. *)
29 type info = {
30   version : string;              (* The version as a normal string. *)
31   major : int;                   (* Broken-out version fields. *)
32   minor : int;
33   release: int;
34   is_stable : bool;              (* is a stable version of libguestfs? *)
35   branch : string;               (* 'master' or 'stable-1.xx' *)
36   package_version : string;      (* package-version *)
37   tarball : string;              (* package-version.tar.gz *)
38   urlpath : string;              (* download/1.X-(stable|development)/tarball *)
39   url : string;                  (* full download URL of tarball *)
40 }
41
42 (* Helper: Fetch latest gnulib into $buildtmp/repos/gnulib
43  * XXX Move to Gnulib module.
44  *)
45 let get_gnulib () =
46   sh "
47     cd %s/repos
48     if [ ! -d gnulib ]; then git clone git://git.sv.gnu.org/gnulib.git; fi
49     cd gnulib
50     git checkout --force master
51     git pull
52   " buildtmp
53
54 (* Goal: the website has been updated to 'version'. *)
55 let rec goal website_updated version =
56   target (url_exists version.url);
57
58   require (tarball_created version);
59   require (tarball_tested version);
60
61   (* We only update the website for the development releases. *)
62   if not version.is_stable then
63     require (website_built version);
64
65   require (website_cvs_checked_in version);
66   require (website_rsync_done version)
67
68 (* Goal: website has been rsync'd. *)
69 and website_rsync_done version =
70   let key = sprintf "libguestfs_website_rsync_done_%s" version.version in
71   target (memory_exists key);
72
73   sh "
74     cd %s
75     echo NOT RUNNING: . .rsync
76   " libguestfs_website_cvs;
77   memory_set key "1"
78
79 (* Goal: Tarball added to CVS and CVS checked in. *)
80 and website_cvs_checked_in version =
81   let key = sprintf "libguestfs_website_cvs_checked_in_%s" version.version in
82   target (memory_exists key);
83
84   require (tarball_created version);
85   require (tarball_tested version);
86
87   sh "
88     cd %s
89     cp %s/tarballs/%s %s
90     echo NOT RUNNING: cvs add -kb %s
91     echo NOT RUNNING: cvs ci -m \"Version %s\"
92   " libguestfs_website_cvs
93     buildtmp version.tarball version.urlpath
94     version.urlpath
95     version.version
96
97 (* Goal: website (local copy) has been built. *)
98 and website_built version =
99   let index_file = sprintf "%s/index.html" libguestfs_website_cvs in
100   target (file_contains_string index_file version.version);
101
102   require (tarball_created version);
103   require (tarball_tested version);
104
105   (* We should only update the website on development releases. *)
106   assert (not version.is_stable);
107
108   sh "
109     tar zxf %s/tarballs/%s
110     cd %s
111
112     echo %s > localconfigure
113     chmod +x localconfigure
114     echo %s > localenv
115
116     ./localconfigure
117     make
118     make website
119   " buildtmp version.tarball
120     version.package_version
121     (quote (libguestfs_localconfigure `Tarball))
122     (quote libguestfs_localenv)
123
124 (* Goal: the tarball has passed the required set of tests before
125  * a release is allowed.
126  *)
127 and tarball_tested version =
128   let key = sprintf "libguestfs_tarball_tested_%s" version.version in
129   target (memory_exists key);
130
131   require (tarball_created version);
132
133   sh "
134     tar zxf %s/tarballs/%s
135     cd %s
136
137     echo %s > localconfigure
138     chmod +x localconfigure
139     echo %s > localenv
140
141     ./localconfigure
142     make
143     make check-release
144   " buildtmp version.tarball
145     version.package_version
146     (quote (libguestfs_localconfigure `Tarball))
147     (quote libguestfs_localenv)
148
149 (* Goal: the tarball has been created from git. *)
150 and tarball_created version =
151   let filename = sprintf "%s/tarballs/%s" buildtmp version.tarball in
152   target (file_exists filename);
153
154   let repodir = sprintf "%s/repos/%s-%s" buildtmp package version.branch in
155   require (directory_exists repodir);
156
157   sh "
158     cp -a %s libguestfs
159     cd libguestfs
160     git reset --hard %s
161
162     echo %s > localconfigure
163     chmod +x localconfigure
164     echo %s > localenv
165
166     ./localconfigure
167     make
168     make dist
169     mv %s %s/tarballs/%s
170   " repodir
171     version.version
172     (quote (libguestfs_localconfigure `Git))
173     (quote libguestfs_localenv)
174     version.tarball buildtmp version.tarball
175
176 (* Goal: test a commit. *)
177 and commit_tested branch commit =
178   onfail (
179     fun _ ->
180       let subject = sprintf "goal: %s: FAILED" goalname in
181       mailto ~from ~subject ~attach:[logfile] to_
182   );
183
184   let key = sprintf "libguestfs_commit_tested_%s" commit in
185   target (memory_exists key);
186
187   let repodir = sprintf "%s/repos/%s-%s" buildtmp package branch in
188   require (directory_exists repodir);
189
190   sh "
191     cp -a %s libguestfs
192     cd libguestfs
193     git reset --hard %s
194
195     echo %s > localconfigure
196     chmod +x localconfigure
197     echo %s > localenv
198
199     ./localconfigure
200     make
201     make check-release
202   " repodir
203     commit
204     (quote (libguestfs_localconfigure `Git))
205     (quote libguestfs_localenv);
206
207   memory_set key "1"
208
209 (* Helper function to make a full 'info' object from a version
210  * number.
211  *)
212 let vernames version =
213   Scanf.sscanf version "%d.%d.%d" (
214     fun major minor release ->
215       let is_stable = minor mod 2 = 0 in
216       let branch =
217         if is_stable then
218           sprintf "stable-%d.%d" major minor
219         else
220           sprintf "master" in
221       let package_version = sprintf "%s-%d.%d.%d" package major minor release in
222       let tarball = sprintf "%s.tar.gz" package_version in
223       let urlpath =
224         if is_stable then
225           sprintf "download/%d.%d-stable/%s" major minor tarball
226         else
227           sprintf "download/%d.%d-development/%s" major minor tarball in
228       let url = "http://libguestfs.org/" ^ urlpath in
229       { version = version;
230         major = major; minor = minor; release = release;
231         is_stable = is_stable;
232         branch = branch;
233         package_version = package_version;
234         tarball = tarball;
235         urlpath = urlpath;
236         url = url }
237   )
238
239 (* Helper function to read the latest version in a repo and return
240  * the version.
241  *)
242 let git_latest_version branch =
243   let v = shout "
244     cd %s/repos/%s-%s
245     git describe --tags --abbrev=0
246   " buildtmp package (quote branch) in
247   vernames v
248
249 (* Get the latest commit. *)
250 let git_latest_commit branch =
251   shout "
252     cd %s/repos/%s-%s
253     git rev-parse HEAD
254   " buildtmp package (quote branch)
255
256 (* Clone or update a repo to the latest version on a branch, by force.
257  * It is cached in name = $buildtmp/repos/<package>-<branch>
258  *)
259 let git_force url branch =
260   sh "
261     cd %s/repos
262     if [ ! -d %s-%s ]; then git clone %s %s-%s; fi
263     cd %s-%s
264     git checkout --force %s
265     git pull
266     # Copy or update gnulib
267     git submodule init
268     git submodule update
269   " buildtmp
270     package (quote branch) (quote url) package (quote branch)
271     package (quote branch)
272     (quote branch)
273
274 let () =
275   (* Add a periodic job to check for new git commits and test them. *)
276   every libguestfs_query_mins minutes ~name:"new libguestfs commit" (
277     fun () ->
278       git_force "https://github.com/libguestfs/libguestfs.git" "master";
279
280       let commit = git_latest_commit "master" in
281       require (commit_tested "master" commit);
282   );
283
284   (* Periodic job to build new tarballs. *)
285   every libguestfs_query_mins minutes ~name:"new libguestfs version" (
286     fun () ->
287       git_force "https://github.com/libguestfs/libguestfs.git" "master";
288
289       let version = git_latest_version "master" in
290       require (website_updated version)
291   )