a3d558fc1c92a43d4ee9682db3e7f06534cacf13
[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 open Libguestfs
15
16 (* Enable debugging. *)
17 let () =
18   Unix.putenv "LIBGUESTFS_DEBUG" "1";
19   Unix.putenv "LIBGUESTFS_TRACE" "1"
20
21 (* Log program output. *)
22 let from = "rjones@redhat.com"
23 let to_ = "rjones@redhat.com"
24 (*
25 let logfile = log_program_output ()
26 let () = eprintf "logging to %s\n%!" logfile
27 *)
28
29 let package = "libguestfs"
30
31 (* Goal: the website has been updated to 'version'. *)
32 let rec goal website_updated version =
33   target (url_exists version.url);
34
35   require (tarball_created version);
36   require (tarball_tested version);
37
38   (* We only update the website for the development releases. *)
39   if not version.is_stable then
40     require (website_built version);
41
42   require (website_cvs_checked_in version);
43   require (website_rsync_done version)
44
45 (* Goal: website has been rsync'd. *)
46 and website_rsync_done version =
47   target (url_contains_string "http://libguestfs.org" version.version &&
48           url_exists version.url);
49
50   sh "
51     cd %s
52     ./.rsync
53   " libguestfs_website_cvs
54
55 (* Goal: Tarball added to CVS and CVS checked in. *)
56 and website_cvs_checked_in version =
57   let key = sprintf "libguestfs_website_cvs_checked_in_%s" version.version in
58   target (memory_exists key);
59   onrun (fun () -> memory_set key "1");
60
61   require (tarball_created version);
62   require (tarball_tested version);
63
64   sh "
65     cd %s
66     cp %s/tarballs/%s %s
67     cvs add -kb %s
68     cvs ci -m \"Version %s\"
69   " libguestfs_website_cvs
70     buildtmp version.tarball version.urlpath
71     version.urlpath
72     version.version
73
74 (* Goal: website (local copy) has been built. *)
75 and website_built version =
76   let index_file = sprintf "%s/index.html" libguestfs_website_cvs in
77   target (file_contains_string index_file version.version);
78
79   require (tarball_created version);
80   require (tarball_tested version);
81
82   (* We should only update the website on development releases. *)
83   assert (not version.is_stable);
84
85   sh "
86     tar zxf %s/tarballs/%s
87     cd %s
88
89     echo %s > localconfigure
90     chmod +x localconfigure
91     echo %s > localenv
92
93     ./localconfigure
94     make
95     make website
96   " buildtmp version.tarball
97     version.package_version
98     (quote (libguestfs_localconfigure `Tarball))
99     (quote libguestfs_localenv)
100
101 (* Goal: the tarball has passed the required set of tests before
102  * a release is allowed.
103  *)
104 and tarball_tested version =
105   let key = sprintf "libguestfs_tarball_tested_%s" version.version in
106   target (memory_exists key);
107   onrun (fun () -> memory_set key "1");
108
109   require (tarball_created version);
110
111   sh "
112     tar zxf %s/tarballs/%s
113     cd %s
114
115     echo %s > localconfigure
116     chmod +x localconfigure
117     echo %s > localenv
118
119     ./localconfigure
120     make
121     make check-release
122   " buildtmp version.tarball
123     version.package_version
124     (quote (libguestfs_localconfigure `Tarball))
125     (quote libguestfs_localenv)
126
127 (* Goal: the tarball has been created from git. *)
128 and tarball_created version =
129   let filename = sprintf "%s/tarballs/%s" buildtmp version.tarball in
130   target (file_exists filename);
131
132   let repodir = sprintf "%s/repos/%s-%s" buildtmp package version.branch in
133   require (directory_exists repodir);
134
135   sh "
136     cp -a %s libguestfs
137     cd libguestfs
138     git reset --hard %s
139
140     echo %s > localconfigure
141     chmod +x localconfigure
142     echo %s > localenv
143
144     ./localconfigure
145     make
146     make dist
147     mv %s %s/tarballs/%s
148   " repodir
149     version.version
150     (quote (libguestfs_localconfigure `Git))
151     (quote libguestfs_localenv)
152     version.tarball buildtmp version.tarball
153
154 (* Goal: test a commit. *)
155 and commit_tested branch commit =
156   onfail (
157     fun _ ->
158       let subject = sprintf "goal: %s: FAILED" goalname in
159       mailto ~from ~subject (*~attach:[logfile]*) to_
160   );
161
162   let key = sprintf "libguestfs_commit_tested_%s" commit in
163   target (memory_exists key);
164   onrun (fun () -> memory_set key "1");
165
166   let repodir = sprintf "%s/repos/%s-%s" buildtmp package branch in
167   require (directory_exists repodir);
168
169   sh "
170     cp -a %s libguestfs
171     cd libguestfs
172     git reset --hard %s
173
174     echo %s > localconfigure
175     chmod +x localconfigure
176     echo %s > localenv
177
178     ./localconfigure
179     make
180     make check-release
181   " repodir
182     commit
183     (quote (libguestfs_localconfigure `Git))
184     (quote libguestfs_localenv)
185
186 let () =
187   (* Add a periodic job to check for new git commits and test them. *)
188   every libguestfs_query_mins minutes ~name:"new libguestfs commit" (
189     fun () ->
190       git_force "master";
191       let commit = git_latest_commit "master" in
192       require (commit_tested "master" commit);
193   );
194
195   (* Periodic job to build new tarballs. *)
196   every libguestfs_query_mins minutes ~name:"new libguestfs version" (
197     fun () ->
198       git_force "master";
199       let version = git_latest_version "master" in
200       require (website_updated version)
201   )
202
203 (* Allow these jobs to run from the command line. *)
204 let () =
205   publish "commit" (
206     function
207     | [commit] -> require (commit_tested "master" commit)
208     | [branch; commit] -> require (commit_tested branch commit)
209     | _ ->
210       failwith "use './libguestfs_upstream commit [<branch>] <commit>'"
211   );
212   publish "release" (
213     function
214     | [version] -> require (website_updated (vernames version))
215     | _ ->
216       failwith "use './libguestfs_upstream release <version>'"
217   )