libguestfs_upload: Copy builder templates in when making website.
[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     # Copy in the builder/website templates.
94     cp $HOME/d/libguestfs/builder/website/*.xz builder/website/
95
96     ./localconfigure
97     make
98     make website
99   " buildtmp version.tarball
100     version.package_version
101     (quote (libguestfs_localconfigure `Tarball))
102     (quote libguestfs_localenv)
103
104 (* Goal: the tarball has passed the required set of tests before
105  * a release is allowed.
106  *)
107 and tarball_tested version =
108   let key = sprintf "libguestfs_tarball_tested_%s" version.version in
109   target (memory_exists key);
110   onrun (fun () -> memory_set key "1");
111
112   require (tarball_created version);
113
114   sh "
115     tar zxf %s/tarballs/%s
116     cd %s
117
118     echo %s > localconfigure
119     chmod +x localconfigure
120     echo %s > localenv
121
122     ./localconfigure
123     make
124     make check-release
125   " buildtmp version.tarball
126     version.package_version
127     (quote (libguestfs_localconfigure `Tarball))
128     (quote libguestfs_localenv)
129
130 (* Goal: the tarball has been created from git. *)
131 and tarball_created version =
132   let filename = sprintf "%s/tarballs/%s" buildtmp version.tarball in
133   target (file_exists filename);
134
135   let repodir = sprintf "%s/repos/%s-%s" buildtmp package version.branch in
136   require (directory_exists repodir);
137
138   sh "
139     cp -a %s libguestfs
140     cd libguestfs
141     git reset --hard %s
142
143     echo %s > localconfigure
144     chmod +x localconfigure
145     echo %s > localenv
146
147     ./localconfigure
148     make
149     make dist
150     mv %s %s/tarballs/%s
151   " repodir
152     version.version
153     (quote (libguestfs_localconfigure `Git))
154     (quote libguestfs_localenv)
155     version.tarball buildtmp version.tarball
156
157 (* Goal: test a commit. *)
158 and commit_tested branch commit =
159   onfail (
160     fun _ ->
161       let subject = sprintf "goal: %s: FAILED" goalname in
162       mailto ~from ~subject (*~attach:[logfile]*) to_
163   );
164
165   let key = sprintf "libguestfs_commit_tested_%s" commit in
166   target (memory_exists key);
167   onrun (fun () -> memory_set key "1");
168
169   let repodir = sprintf "%s/repos/%s-%s" buildtmp package branch in
170   require (directory_exists repodir);
171
172   sh "
173     cp -a %s libguestfs
174     cd libguestfs
175     git reset --hard %s
176
177     echo %s > localconfigure
178     chmod +x localconfigure
179     echo %s > localenv
180
181     ./localconfigure
182     make
183     make check-release
184   " repodir
185     commit
186     (quote (libguestfs_localconfigure `Git))
187     (quote libguestfs_localenv)
188
189 let () =
190   (* Add a periodic job to check for new git commits and test them. *)
191   every libguestfs_query_mins minutes ~name:"new libguestfs commit" (
192     fun () ->
193       git_force "master";
194       let commit = git_latest_commit "master" in
195       require (commit_tested "master" commit);
196   );
197
198   (* Periodic job to build new tarballs. *)
199   every libguestfs_query_mins minutes ~name:"new libguestfs version" (
200     fun () ->
201       git_force "master";
202       let version = git_latest_version "master" in
203       require (website_updated version)
204   )
205
206 (* Allow these jobs to run from the command line. *)
207 let () =
208   publish "commit" (
209     function
210     | [commit] -> require (commit_tested "master" commit)
211     | [branch; commit] -> require (commit_tested branch commit)
212     | _ ->
213       failwith "use './libguestfs_upstream commit [<branch>] <commit>'"
214   );
215   publish "release" (
216     function
217     | [version] -> require (website_updated (vernames version))
218     | _ ->
219       failwith "use './libguestfs_upstream release <version>'"
220   )