extend dump plugin to support resolving revisions

This patch adds a flag --resolve-refs to the dump plugin.
Once enabled, all relative refspecs (e.g. branch or tag names) are
resolved and replaced by their exact revision (before patches are
applied).
When re-running kas on the flattened and expanded config file, the build
is executed against exactly the versions of the dependencies that where
used when dumping the configuration. This helps to keep track of build
versions for future use (e.g. reproducible builds) or for
version-tracking tools like renovate.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer 2022-12-11 08:30:31 +01:00 committed by Jan Kiszka
parent 23dcf955a2
commit ffabaa19f3

View File

@ -64,7 +64,10 @@ class Dump(Checkout):
"""
name = 'dump'
helpmsg = 'Expand and dump the final config.'
helpmsg = (
'Expand and dump the final config to stdout. When resolving refspecs, '
'these are resolved before patches are applied.'
)
class KasYamlDumper(yaml.Dumper):
"""
@ -99,6 +102,9 @@ class Dump(Checkout):
type=int,
default=4,
help='Line indent (# of spaces, default: 4)')
parser.add_argument('--resolve-refs',
action='store_true',
help='Replace floating refs with exact SHAs')
def run(self, args):
args.skip += [
@ -116,6 +122,12 @@ class Dump(Checkout):
if 'includes' in config_expanded['header']:
del config_expanded['header']['includes']
if args.resolve_refs:
repos = ctx.config.get_repos()
for r in repos:
if r.refspec:
config_expanded['repos'][r.name]['refspec'] = r.revision
if args.format == 'json':
json.dump(config_expanded, sys.stdout, indent=args.indent)
sys.stdout.write('\n')