Override XDG_CONFIG_DIRS to make virt-builder use global configuration.
[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.33-development", "master";    (* Rawhide follows development. *)
26   "1.33-development", "f24";       (* F24 follows development, for now. *)
27   "1.32-stable", "f23";            (* F23 follows 1.32. *)
28   "1.30-stable", "f22";            (* F22 follows 1.30. *)
29 ]
30
31 (* Goal: Latest website version has been built in every branch. *)
32 let rec goal all () =
33   List.iter (
34     fun (wbranch, fbranch) ->
35       match website_latest_version wbranch with
36       | None -> ()
37       | Some version ->
38         require (fedora_built version fbranch)
39   ) branches
40
41 (* Goal: Fedora has a successful build of 'version' on 'branch'. *)
42 and fedora_built version branch =
43   let specfile = fedora_specfile package branch in
44
45   target (file_contains_string specfile version.version &&
46             match koji_build_state (fedora_verrel package branch) with
47             | `Complete | `Building -> true
48             | _ -> false);
49
50   require (sources_uploaded version branch);
51   require (specfile_pushed version branch);
52
53   koji_build ~wait:true package branch
54
55 and sources_uploaded version branch =
56   let repodir = fedora_repo package branch in
57   let sources = repodir // "sources" in
58   let key = sprintf "libguestfs_fedora_sources_uploaded_%s" version.version in
59
60   target (file_contains_string sources version.version &&
61             memory_exists key);
62   onrun (fun () -> memory_set key "1");
63
64   require (repodir_up_to_date repodir);
65
66   sh "
67     cd %s
68     fedpkg new-sources %s/%s
69   " repodir libguestfs_website_repo version.urlpath
70
71 and specfile_updated version branch =
72   let repodir = fedora_repo package branch in
73   let specfile = fedora_specfile package branch in
74
75   target (file_contains_string specfile version.version);
76
77   require (repodir_up_to_date repodir);
78
79   (* Hairy specfile editing. *)
80   sh "
81     cd %s
82     email=\"Richard W.M. Jones <rjones@redhat.com>\"
83     date=`date +\"%%a %%b %%d %%Y\"`
84     cp libguestfs.spec libguestfs.spec.old
85     sed < libguestfs.spec.old \\
86     -e \"s/^Version:.*/Version:       %s/\" \\
87     -e \"s/^Release:.*/Release:       1%%{?dist}/\" \\
88     -e \"/^%%changelog/a \\
89 * $date $email - 1:%s-1\\\\n\\
90 - New upstream version %s.\\\\n\\
91 \" > libguestfs.spec
92     rm libguestfs.spec.old
93   " repodir version.version version.version version.version
94
95 and specfile_committed version branch =
96   let repodir = fedora_repo package branch in
97   let key = sprintf "libguestfs_fedora_specfile_committed_%s_%s"
98     branch version.version in
99
100   target (memory_exists key);
101   onrun (fun () -> memory_set key "1");
102
103   require (specfile_updated version branch);
104
105   sh "
106     cd %s
107     fedpkg commit -c
108   " repodir
109
110 and specfile_pushed version branch =
111   let repodir = fedora_repo package branch in
112   let key =
113     sprintf "libguestfs_fedora_specfile_pushed_%s_%s" branch version.version in
114
115   target (memory_exists key);
116   onrun (fun () -> memory_set key "1");
117
118   require (repodir_up_to_date repodir);
119   require (specfile_committed version branch);
120
121   sh "
122     cd %s
123     fedpkg push
124   " repodir
125
126 and repodir_up_to_date repodir =
127   sh "
128     cd %s
129     git fetch
130   " repodir;
131   if not (git_has_local_changes repodir) then
132     sh "
133       cd %s
134       git pull --rebase
135     " repodir