Show all missing deps when publishing-bot has no listed dependencies

Before this, it only showed one dependency in the error message.

Also, replace godeps.json with go.mod in the error message.
This commit is contained in:
Nikhita Raghunath 2019-04-05 12:02:40 +05:30
parent e9ca60bf0d
commit d474631e38

View File

@ -23,7 +23,7 @@ import json
import yaml import yaml
def get_godeps_dependencies(rootdir, components): def get_gomod_dependencies(rootdir, components):
all_dependencies = {} all_dependencies = {}
for component in components: for component in components:
with open(os.path.join(rootdir, component, "go.mod")) as f: with open(os.path.join(rootdir, component, "go.mod")) as f:
@ -58,8 +58,9 @@ def main():
components.append(component) components.append(component)
components.sort() components.sort()
godep_dependencies = get_godeps_dependencies(rootdir + '/staging/src/k8s.io/', components) rules_file = "/staging/publishing/rules.yaml"
rules_dependencies = get_rules_dependencies(rootdir + "/staging/publishing/rules.yaml") gomod_dependencies = get_gomod_dependencies(rootdir + '/staging/src/k8s.io/', components)
rules_dependencies = get_rules_dependencies(rootdir + rules_file)
processed_repos = [] processed_repos = []
for rule in rules_dependencies["rules"]: for rule in rules_dependencies["rules"]:
@ -70,10 +71,10 @@ def main():
raise Exception("cannot find master source branch for destination %s" % rule["destination"]) raise Exception("cannot find master source branch for destination %s" % rule["destination"])
print("processing : %s" % rule["destination"]) print("processing : %s" % rule["destination"])
if rule["destination"] not in godep_dependencies: if rule["destination"] not in gomod_dependencies:
raise Exception("missing Godeps.json for %s" % rule["destination"]) raise Exception("missing go.mod for %s" % rule["destination"])
processed_repos.append(rule["destination"]) processed_repos.append(rule["destination"])
for dep in set(godep_dependencies[rule["destination"]]): for dep in set(gomod_dependencies[rule["destination"]]):
found = False found = False
if "dependencies" in branch: if "dependencies" in branch:
for dep2 in branch["dependencies"]: for dep2 in branch["dependencies"]:
@ -84,12 +85,12 @@ def main():
found = True found = True
else: else:
raise Exception( raise Exception(
"destination %s does not have any dependencies (looking for %s)" % (rule["destination"], dep)) "Please add %s as dependencies under destination %s in %s" % (gomod_dependencies[rule["destination"]], rule["destination"], rules_file))
if not found: if not found:
raise Exception("destination %s does not have dependency %s" % (rule["destination"], dep)) raise Exception("Please add %s as a dependency under destination %s in %s" % (dep, rule["destination"], rules_file))
else: else:
print(" found dependency %s" % dep) print(" found dependency %s" % dep)
items = set(godep_dependencies.keys()) - set(processed_repos) items = set(gomod_dependencies.keys()) - set(processed_repos)
if len(items) > 0: if len(items) > 0:
raise Exception("missing rules for %s" % ','.join(str(s) for s in items)) raise Exception("missing rules for %s" % ','.join(str(s) for s in items))
print("Done.") print("Done.")