2 # Ship a local branch to a remote host (sn-104?) over ssh and run autobuild in it.
3 # Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GPL, v3 or later
11 samba_master
= os
.getenv('SAMBA_MASTER', 'git://git.samba.org/samba.git')
13 parser
= optparse
.OptionParser("autoland-remote [options] [trees...]")
14 parser
.add_option("--remote-repo", help="Location of remote repository (default: temporary repository)", type=str, default
=None)
15 parser
.add_option("--host", help="Host to land on (SSH connection string)", type=str, default
="sn-devel-104.sn.samba.org")
16 parser
.add_option("--foreground", help="Don't daemonize", action
="store_true", default
=False)
17 parser
.add_option("--email", help="Email address to send build/test output to", type=str, default
=None, metavar
="EMAIL")
18 parser
.add_option("--always-email", help="always send email, even on success", action
="store_true")
19 parser
.add_option("--rebase-master", help="rebase on master before testing", default
=False, action
='store_true')
20 parser
.add_option("--push-master", help="push to samba.org master on success",
21 default
=False, action
='store_true')
22 parser
.add_option("--pushto", help="push to a git url on success",
23 default
=None, type='str')
24 parser
.add_option("--rebase", help="rebase on the given tree before testing", default
=None, type='str')
25 parser
.add_option("--passcmd", help="command to run on success", default
=None)
26 parser
.add_option("--tail", help="show output while running", default
=False, action
="store_true")
27 parser
.add_option("--keeplogs", help="keep logs", default
=False, action
="store_true")
28 parser
.add_option("--nocleanup", help="don't remove test tree", default
=False, action
="store_true")
29 parser
.add_option("--revision", help="revision to compile if not HEAD", default
=None, type=str)
30 parser
.add_option("--fix-whitespace", help="fix whitespace on rebase",
31 default
=False, action
="store_true")
32 parser
.add_option("--fail-slowly", help="continue running tests even after one has already failed",
35 (opts
, extra_args
) = parser
.parse_args()
37 if opts
.email
is None and os
.getenv("EMAIL") is not None:
38 opts
.email
= os
.getenv("EMAIL")
40 if not opts
.foreground
and not opts
.email
:
41 print "Not running in foreground and --email not specified."
44 if not opts
.foreground
and opts
.push_master
:
45 print "Unable to push to master when not running in foreground."
48 if not opts
.remote_repo
:
49 print "%s$ mktemp -d" % opts
.host
50 f
= subprocess
.Popen(["ssh", opts
.host
, "mktemp", "-d"], stdout
=subprocess
.PIPE
)
51 (stdout
, stderr
) = f
.communicate()
54 remote_repo
= stdout
.rstrip()
55 print "Remote tempdir: %s" % remote_repo
56 # Bootstrap, git.samba.org is usually more easily accessible.
57 #remote_args = ["git", "clone", samba_master, remote_repo]
58 remote_args
= ["if [ -d /data/git/samba.git ]; then git clone --shared /data/git/samba.git %s; else git clone --shared %s %s; fi" % (remote_repo
, samba_master
, remote_repo
)]
59 #remote_args = ["git", "init", remote_repo]
60 print "%s$ %s" % (opts
.host
, " ".join(remote_args
))
61 subprocess
.check_call(["ssh", opts
.host
] + remote_args
)
63 remote_repo
= opts
.remote_repo
65 print "Pushing local branch"
67 if opts
.revision
is not None:
68 revision
= opts
.revision
71 args
= ["git", "push", "--force", "git+ssh://%s/%s" % (opts
.host
, remote_repo
), "%s:land" % revision
]
72 print "$ " + " ".join(args
)
73 subprocess
.check_call(args
)
74 remote_args
= ["cd", remote_repo
, ";", "git", "checkout", "land", ";", "python", "-u", "./script/land.py", "--repository=%s" % remote_repo
]
76 if (opts
.email
and not (opts
.foreground
or opts
.pushto
or opts
.push_master
)):
77 # Force always emailing if there's nothing else to do
78 opts
.always_email
= True
81 remote_args
.append("--email=%s" % opts
.email
)
83 remote_args
.append("--always-email")
84 if not opts
.foreground
:
85 remote_args
.append("--daemon")
87 remote_args
.append("--nocleanup")
88 if opts
.fix_whitespace
:
89 remote_args
.append("--fix-whitespace")
91 remote_args
.append("--tail")
93 remote_args
.append("--keeplogs")
94 if opts
.rebase_master
:
95 remote_args
.append("--rebase-master")
97 remote_args
.append("--rebase=%s" % opts
.rebase
)
99 remote_args
.append("--passcmd=%s" % opts
.passcmd
)
101 remote_args
.append("--pushto=%s" % opts
.pushto
)
103 remote_args
.append("--push-master")
105 remote_args
+= extra_args
106 print "%s$ %s" % (opts
.host
, " ".join(remote_args
))
107 args
= ["ssh", "-A", opts
.host
] + remote_args
108 sys
.exit(subprocess
.call(args
))