forked from kernelci/kernelci-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·92 lines (76 loc) · 3.44 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
#
# Copyright (C) 2021 Collabora Limited
# Author: Guillaume Tucker <[email protected]>
#
# This module is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import argparse
import os
import sys
import kernelci
from kernelci import print_color, shell_cmd, ssh_agent
def do_rebase(path, origin='origin', origin_branch='main'):
shell_cmd("""\
cd {path}
git pull --rebase {origin} {origin_branch}
git push 'origin' HEAD:{origin_branch} --force
""".format(path=path, origin=origin, origin_branch=origin_branch))
def do_push(path, ssh_key, tag, branch):
diff = kernelci.origin_diff(path, branch)
if not diff:
print_color('yellow', "No changes, not pushing.")
return True
print(diff)
kernelci.create_tag(path, tag)
print("\nPushing tag ({}) and branch ({})".format(tag, branch))
kernelci.push_tag_and_branch(path, ssh_key, branch, tag)
def main(args):
repo_name = '/'.join([args.namespace, args.project])
repo = kernelci.GITHUB.get_repo(repo_name)
path = os.path.join('checkout', args.project)
kernelci.checkout_repository(path, repo, branch=args.branch)
do_rebase(path, args.origin, args.origin_branch)
if args.push:
ssh_key = kernelci.default_ssh_key(args.ssh_key, args.branch)
if not ssh_key:
print_color('red', "No SSH key provided, cannot push.")
return False
tag = args.tag or kernelci.date_tag(path, args.tag_prefix)
do_push(path, ssh_key, tag, args.branch)
return True
if __name__ == '__main__':
parser = argparse.ArgumentParser("\
Update kernelci.org branch with latest changes")
parser.add_argument("project",
help="Name of the Github project")
parser.add_argument("--tag",
help="Tag to create, default is to use current date")
parser.add_argument("--tag-prefix", default="kernelci-",
help="Prefix to create date with current date")
parser.add_argument("--branch", default='kernelci.org',
help="Name of the branch to force-push to")
parser.add_argument("--origin", default='origin',
help="Name of the origin to rebase onto")
parser.add_argument("--origin-branch", default='main',
help="Name of the branch in the origin to rebase onto")
parser.add_argument("--namespace", default='kernelci',
help="Github project namespace, default is kernelci")
parser.add_argument("--ssh-key",
help="Path to SSH key to push branches and tags")
parser.add_argument("--push", action="store_true",
help="Push the resulting branch and tag")
args = parser.parse_args(sys.argv[1:])
ret = main(args)
sys.exit(0 if ret is True else 1)