Use supermin4 binary when compiling libguestfs <= 1.24.
[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_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_repo
54
55 (* Goal: Tarball added to repository and checked in. *)
56 and website_checked_in version =
57   let key = sprintf "libguestfs_website_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     git add %s
68     git add *.txt *.html
69     git commit -m \"Version %s\"
70   " libguestfs_website_repo
71     buildtmp version.tarball version.urlpath
72     version.urlpath
73     version.version
74
75 (* Goal: website (local copy) has been built. *)
76 and website_built version =
77   let index_file = sprintf "%s/index.html" libguestfs_website_repo in
78   target (file_contains_string index_file version.version);
79
80   require (tarball_created version);
81   require (tarball_tested version);
82
83   (* We should only update the website on development releases. *)
84   assert (not version.is_stable);
85
86   sh "
87     tar zxf %s/tarballs/%s
88     cd %s
89
90     echo %s > localconfigure
91     chmod +x localconfigure
92     echo %s > localenv
93
94     # Copy in the builder/website templates.
95     cp -a $HOME/d/libguestfs/builder/website/*.xz builder/website/
96
97     ./localconfigure
98     make
99     make website WEBSITEDIR=%s
100   " buildtmp version.tarball
101     version.package_version
102     (quote (libguestfs_localconfigure `Tarball))
103     (quote (libguestfs_localenv (supermin version)))
104     (quote libguestfs_website_repo)
105
106 (* Goal: the tarball has passed the required set of tests before
107  * a release is allowed.
108  *)
109 and tarball_tested version =
110   let key = sprintf "libguestfs_tarball_tested_%s" version.version in
111   target (memory_exists key);
112   onrun (fun () -> memory_set key "1");
113
114   require (tarball_created version);
115
116   sh "
117     tar zxf %s/tarballs/%s
118     cd %s
119
120     echo %s > localconfigure
121     chmod +x localconfigure
122     echo %s > localenv
123
124     ./localconfigure
125     make
126     make check-release
127   " buildtmp version.tarball
128     version.package_version
129     (quote (libguestfs_localconfigure `Tarball))
130     (quote (libguestfs_localenv (supermin version)))
131
132 (* Goal: the tarball has been created from git. *)
133 and tarball_created version =
134   let filename = sprintf "%s/tarballs/%s" buildtmp version.tarball in
135   target (file_exists filename);
136
137   require (repo_up_to_date version.branch);
138
139   let repodir = sprintf "%s/repos/%s-%s" buildtmp package version.branch in
140
141   sh "
142     cp -a %s libguestfs
143     cd libguestfs
144     git reset --hard %s
145
146     echo %s > localconfigure
147     chmod +x localconfigure
148     echo %s > localenv
149
150     ./localconfigure
151
152     # Ensure the po-docs are updated.  Grrr this is ugly ...
153     make ||:
154     rm po-docs/podfiles
155     make -C po-docs update-po
156
157     make
158     make dist
159     mv %s %s/tarballs/%s
160   " repodir
161     version.version
162     (quote (libguestfs_localconfigure `Git))
163     (quote (libguestfs_localenv (supermin version)))
164     version.tarball buildtmp version.tarball
165
166 (* Goal: test a commit. *)
167 and commit_tested branch commit =
168   onfail (
169     fun _ ->
170       let subject = sprintf "goal: %s: FAILED" goalname in
171       mailto ~from ~subject (*~attach:[logfile]*) to_
172   );
173
174   let key = sprintf "libguestfs_commit_tested_%s" commit in
175   target (memory_exists key);
176   onrun (fun () -> memory_set key "1");
177
178   require (repo_up_to_date branch);
179
180   let repodir = sprintf "%s/repos/%s-%s" buildtmp package branch in
181
182   sh "
183     cp -a %s libguestfs
184     cd libguestfs
185     git reset --hard %s
186
187     echo %s > localconfigure
188     chmod +x localconfigure
189     echo %s > localenv
190
191     ./localconfigure
192     make
193     make check-release
194   " repodir
195     commit
196     (quote (libguestfs_localconfigure `Git))
197     (quote (libguestfs_localenv None))
198
199 and repo_up_to_date branch =
200   git_force branch
201
202 let () =
203   (* Add a periodic job to check for new git commits and test them. *)
204   every libguestfs_query_mins minutes ~name:"new libguestfs commit" (
205     fun () ->
206       require (repo_up_to_date "master");
207       let commit = git_latest_commit "master" in
208       require (commit_tested "master" commit);
209   );
210
211   (* Periodic job to build new tarballs. *)
212   every libguestfs_query_mins minutes ~name:"new libguestfs version" (
213     fun () ->
214       require (repo_up_to_date "master");
215       let version = git_latest_version "master" in
216       require (website_updated version)
217   )
218
219 (* Allow these jobs to run from the command line. *)
220 let () =
221   publish "commit" (
222     function
223     | [commit] -> require (commit_tested "master" commit)
224     | [branch; commit] -> require (commit_tested branch commit)
225     | _ ->
226       failwith "use './libguestfs_upstream commit [<branch>] <commit>'"
227   );
228   publish "release" (
229     function
230     | [version] -> require (website_updated (vernames version))
231     | _ ->
232       failwith "use './libguestfs_upstream release <version>'"
233   )