6f65a9cd0d5de1a9348b02c9831490c778a435f6
[goaljobs-goals.git] / libguestfs_fedora.ml
1 (* Handle Fedora builds of libguestfs. *)
2
3 open Goaljobs
4
5 open Printf
6
7 open Config
8 open Fedora
9 open Git
10 open Libguestfs
11
12 (* Enable debugging. *)
13 let () =
14   Unix.putenv "LIBGUESTFS_DEBUG" "1";
15   Unix.putenv "LIBGUESTFS_TRACE" "1"
16
17 (* Log program output. *)
18 let from = "rjones@redhat.com"
19 let to_ = "rjones@redhat.com"
20
21 let package = "libguestfs"
22
23 (* How branches in libguestfs upstream map to branches in Fedora. *)
24 let branches = [
25   "1.37-development", "master";    (* Rawhide follows development. *)
26   (*"1.36-stable", "f26";            (* F26 follows 1.36. *)*)
27   "1.36-stable", "f25";            (* F25 follows 1.36. *)
28   "1.34-stable", "f24";            (* F24 follows 1.34. *)
29   "1.32-stable", "f23";            (* F23 follows 1.32. *)
30   "1.30-stable", "f22";            (* F22 follows 1.30. *)
31 ]
32
33 (* Goal: Latest website version has been built in every branch. *)
34 let rec goal all () =
35   List.iter (
36     fun (wbranch, fbranch) ->
37       match website_latest_version wbranch with
38       | None -> ()
39       | Some version ->
40         require (fedora_built version fbranch)
41   ) branches
42
43 (* Goal: Fedora has a successful build of 'version' on 'branch'. *)
44 and fedora_built version branch =
45   let specfile = fedora_specfile package branch in
46
47   target (file_contains_string specfile version.version &&
48             match koji_build_state (fedora_verrel package branch) with
49             | `Complete | `Building -> true
50             | _ -> false);
51
52   require (sources_uploaded version branch);
53   require (specfile_pushed version branch);
54
55   koji_build ~wait:true package branch
56
57 and sources_uploaded version branch =
58   let repodir = fedora_repo package branch in
59   let sources = repodir // "sources" in
60   let key = sprintf "libguestfs_fedora_sources_uploaded_%s" version.version in
61
62   target (file_contains_string sources version.version &&
63             memory_exists key);
64   onrun (fun () -> memory_set key "1");
65
66   require (repodir_up_to_date repodir);
67
68   sh "
69     cd %s
70     fedpkg new-sources %s/%s
71   " repodir libguestfs_website_repo version.urlpath
72
73 and specfile_updated version branch =
74   let repodir = fedora_repo package branch in
75   let specfile = fedora_specfile package branch in
76
77   target (file_contains_string specfile version.version);
78
79   require (repodir_up_to_date repodir);
80
81   (* Hairy specfile editing. *)
82   sh "
83     cd %s
84     email=\"Richard W.M. Jones <rjones@redhat.com>\"
85     date=`date +\"%%a %%b %%d %%Y\"`
86     cp libguestfs.spec libguestfs.spec.old
87     sed < libguestfs.spec.old \\
88     -e \"s/^Version:.*/Version:       %s/\" \\
89     -e \"s/^Release:.*/Release:       1%%{?dist}/\" \\
90     -e \"/^%%changelog/a \\
91 * $date $email - 1:%s-1\\\\n\\
92 - New upstream version %s.\\\\n\\
93 \" > libguestfs.spec
94     rm libguestfs.spec.old
95   " repodir version.version version.version version.version
96
97 and specfile_committed version branch =
98   let repodir = fedora_repo package branch in
99   let key = sprintf "libguestfs_fedora_specfile_committed_%s_%s"
100     branch version.version in
101
102   target (memory_exists key);
103   onrun (fun () -> memory_set key "1");
104
105   require (specfile_updated version branch);
106
107   sh "
108     cd %s
109     fedpkg commit -c
110   " repodir
111
112 and specfile_pushed version branch =
113   let repodir = fedora_repo package branch in
114   let key =
115     sprintf "libguestfs_fedora_specfile_pushed_%s_%s" branch version.version in
116
117   target (memory_exists key);
118   onrun (fun () -> memory_set key "1");
119
120   require (repodir_up_to_date repodir);
121   require (specfile_committed version branch);
122
123   sh "
124     cd %s
125     fedpkg push
126   " repodir
127
128 and repodir_up_to_date repodir =
129   sh "
130     cd %s
131     git fetch
132   " repodir;
133   if not (git_has_local_changes repodir) then
134     sh "
135       cd %s
136       git pull --rebase
137     " repodir