From ffabaa19f339026682fdcb68acbc7e31b1a7739f Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sun, 11 Dec 2022 08:30:31 +0100 Subject: [PATCH] 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 Signed-off-by: Jan Kiszka --- kas/plugins/dump.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kas/plugins/dump.py b/kas/plugins/dump.py index 77621b5..61ca3c1 100644 --- a/kas/plugins/dump.py +++ b/kas/plugins/dump.py @@ -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')