| |
@@ -0,0 +1,107 @@
|
| |
+ #!/usr/bin/python3
|
| |
+
|
| |
+ import gi
|
| |
+ import git
|
| |
+ import os
|
| |
+ import sys
|
| |
+
|
| |
+ from gi.repository import GLib
|
| |
+ gi.require_version('Modulemd', '2.0')
|
| |
+ from gi.repository import Modulemd
|
| |
+
|
| |
+ def print_failure(failure):
|
| |
+ print("Error: %s" % failure.get_gerror())
|
| |
+ print("Offending YAML: \n%s" % failure.get_yaml())
|
| |
+
|
| |
+ def unusable_baseline():
|
| |
+ print("Baseline was unusable. Skipping test.")
|
| |
+ return os.EX_OK
|
| |
+
|
| |
+ def get_index_and_defaults (repo, filename, commit):
|
| |
+ try:
|
| |
+ yaml = repo.git.show('%s:%s' % (commit, filename))
|
| |
+ except git.exc.GitCommandError as e:
|
| |
+ # This file didn't exist in the baseline commit, so just return
|
| |
+ # success. If there's anything wrong with the new file, it will be
|
| |
+ # caught in common_tests.sh
|
| |
+ return 0
|
| |
+
|
| |
+ index = Modulemd.ModuleIndex.new()
|
| |
+ try:
|
| |
+ ret, failures = index.update_from_string(yaml, True)
|
| |
+ if ret != True:
|
| |
+ for failure in failures:
|
| |
+ print_failure (failure)
|
| |
+ raise IOError("Invalid modulemd-defaults document")
|
| |
+
|
| |
+ except gi.repository.GLib.Error as e:
|
| |
+ print ("Error: %s" % e)
|
| |
+ raise IOError("Invalid YAML document")
|
| |
+
|
| |
+ module_names = index.get_module_names()
|
| |
+ if len(module_names) > 1:
|
| |
+ raise IOError("YAML contained multiple modules")
|
| |
+ elif len(module_names) < 1:
|
| |
+ raise IOError("YAML contained no modules")
|
| |
+
|
| |
+ defaults = index.get_module(index.get_module_names()[0]).get_defaults()
|
| |
+ if not defaults:
|
| |
+ raise IOError("YAML contained no defaults")
|
| |
+
|
| |
+ return index, defaults
|
| |
+
|
| |
+ def main():
|
| |
+ os.putenv('G_MESSAGES_DEBUG', 'all')
|
| |
+ filename = sys.argv[1]
|
| |
+ baseline_commit = sys.argv[2]
|
| |
+
|
| |
+ script_dir = os.path.dirname(os.path.realpath(__file__))
|
| |
+
|
| |
+ repo = git.Repo(script_dir,
|
| |
+ search_parent_directories=True)
|
| |
+
|
| |
+ # First get the defaults from the baseline commit
|
| |
+ try:
|
| |
+ baseline_index, baseline_defaults = get_index_and_defaults (
|
| |
+ repo, filename, baseline_commit)
|
| |
+ except IOError as e:
|
| |
+ # This should never happen, since the original files presumably have
|
| |
+ # been validated previously (unless someone merged without checking
|
| |
+ # the CI results on a PR). If this occurs, the failures will be in the
|
| |
+ # logs and we'll assume that this PR is trying to fix it, which will
|
| |
+ # be mostly handled in common_tests.sh.
|
| |
+ print(e, file=sys.stderr)
|
| |
+ return unusable_baseline()
|
| |
+
|
| |
+ try:
|
| |
+ updated_commit = 'HEAD'
|
| |
+ updated_index, updated_defaults = get_index_and_defaults (
|
| |
+ repo, filename, updated_commit)
|
| |
+ except IOError as e:
|
| |
+ # If we hit this, the patch is broken.
|
| |
+ print(e, file=sys.stderr)
|
| |
+ return os.EX_DATAERR
|
| |
+
|
| |
+ if updated_defaults.get_modified() <= baseline_defaults.get_modified():
|
| |
+ print ("%s has changed but the 'modified' field has not increased." %
|
| |
+ filename)
|
| |
+ print ("Baseline modified: %d", baseline_defaults.get_modified())
|
| |
+ print ("Updated modified: %d", updated_defaults.get_modified())
|
| |
+ return os.EX_DATAERR
|
| |
+
|
| |
+ # Confirm that these two sets of defaults merge cleanly
|
| |
+ merger = Modulemd.ModuleIndexMerger.new()
|
| |
+ merger.associate_index(baseline_index, 0)
|
| |
+ merger.associate_index(baseline_index, 0)
|
| |
+
|
| |
+ try:
|
| |
+ merger.resolve()
|
| |
+ except gi.repository.GLib.Error as e:
|
| |
+ print ("Merge Error: %s" % e, file=sys.stderr)
|
| |
+ return os.EX_DATAERR
|
| |
+
|
| |
+ return os.EX_OK
|
| |
+
|
| |
+ if __name__ == "__main__":
|
| |
+ sys.exit(main())
|
| |
+
|
| |
Signed-off-by: Stephen Gallagher sgallagh@redhat.com