3 # Helper script for committing data to git and pushing upstream
5 # Copyright (c) 2017, Intel Corporation.
7 # SPDX-License-Identifier: GPL-2.0-only
16 # Import oe and bitbake libs
17 scripts_path
= os
.path
.dirname(os
.path
.realpath(__file__
))
18 sys
.path
.append(os
.path
.join(scripts_path
, 'lib'))
20 scriptpath
.add_bitbake_lib_path()
21 scriptpath
.add_oe_lib_path()
23 from oeqa
.utils
.git
import GitRepo
, GitError
24 from oeqa
.utils
.metadata
import metadata_from_bb
25 import oeqa
.utils
.gitarchive
as gitarchive
28 logging
.basicConfig(level
=logging
.INFO
, format
="%(levelname)s: %(message)s")
29 log
= logging
.getLogger()
33 """Parse command line arguments"""
34 parser
= argparse
.ArgumentParser(
35 description
="Commit data to git and push upstream",
36 formatter_class
=argparse
.ArgumentDefaultsHelpFormatter
)
38 parser
.add_argument('--debug', '-D', action
='store_true',
39 help="Verbose logging")
40 parser
.add_argument('--git-dir', '-g', required
=True,
41 help="Local git directory to use")
42 parser
.add_argument('--no-create', action
='store_true',
43 help="If GIT_DIR is not a valid Git repository, do not "
45 parser
.add_argument('--bare', action
='store_true',
46 help="Initialize a bare repository when creating a "
48 parser
.add_argument('--push', '-p', nargs
='?', default
=False, const
=True,
49 help="Push to remote")
50 parser
.add_argument('--branch-name', '-b',
51 default
='{hostname}/{branch}/{machine}',
52 help="Git branch name (pattern) to use")
53 parser
.add_argument('--no-tag', action
='store_true',
54 help="Do not create Git tag")
55 parser
.add_argument('--tag-name', '-t',
56 default
='{hostname}/{branch}/{machine}/{commit_count}-g{commit}/{tag_number}',
57 help="Tag name (pattern) to use")
58 parser
.add_argument('--commit-msg-subject',
59 default
='Results of {branch}:{commit} on {hostname}',
60 help="Subject line (pattern) to use in the commit message")
61 parser
.add_argument('--commit-msg-body',
62 default
='branch: {branch}\ncommit: {commit}\nhostname: {hostname}',
63 help="Commit message body (pattern)")
64 parser
.add_argument('--tag-msg-subject',
65 default
='Test run #{tag_number} of {branch}:{commit} on {hostname}',
66 help="Subject line (pattern) of the tag message")
67 parser
.add_argument('--tag-msg-body',
69 help="Tag message body (pattern)")
70 parser
.add_argument('--exclude', action
='append', default
=[],
71 help="Glob to exclude files from the commit. Relative "
72 "to DATA_DIR. May be specified multiple times")
73 parser
.add_argument('--notes', nargs
=2, action
='append', default
=[],
74 metavar
=('GIT_REF', 'FILE'),
75 help="Add a file as a note under refs/notes/GIT_REF. "
76 "{branch_name} in GIT_REF will be expanded to the "
77 "actual target branch name (specified by "
78 "--branch-name). This option may be specified "
80 parser
.add_argument('data_dir', metavar
='DATA_DIR',
81 help="Data to commit")
82 return parser
.parse_args(argv
)
84 def get_nested(d
, list_of_keys
):
86 for k
in list_of_keys
:
93 args
= parse_args(argv
)
95 log
.setLevel(logging
.DEBUG
)
98 # Get keywords to be used in tag and branch names and messages
99 metadata
= metadata_from_bb()
100 keywords
= {'hostname': get_nested(metadata
, ['hostname']),
101 'branch': get_nested(metadata
, ['layers', 'meta', 'branch']),
102 'commit': get_nested(metadata
, ['layers', 'meta', 'commit']),
103 'commit_count': get_nested(metadata
, ['layers', 'meta', 'commit_count']),
104 'machine': get_nested(metadata
, ['config', 'MACHINE'])}
106 gitarchive
.gitarchive(args
.data_dir
, args
.git_dir
, args
.no_create
, args
.bare
,
107 args
.commit_msg_subject
.strip(), args
.commit_msg_body
, args
.branch_name
,
108 args
.no_tag
, args
.tag_name
, args
.tag_msg_subject
, args
.tag_msg_body
,
109 args
.exclude
, args
.notes
, args
.push
, keywords
, log
)
111 except gitarchive
.ArchiveError
as err
:
117 if __name__
== "__main__":