|
| 1 | +import yaml, sys |
| 2 | +from os import path |
| 3 | + |
| 4 | + |
| 5 | +def main(template, package, build_no, commit): |
| 6 | + |
| 7 | + # read template file |
| 8 | + with open(template) as input_file: |
| 9 | + template_doc = yaml.safe_load(input_file) |
| 10 | + |
| 11 | + |
| 12 | + print(template_doc) |
| 13 | + |
| 14 | + # read package file |
| 15 | + with open(package) as package_file: |
| 16 | + package_doc = yaml.safe_load(package_file) |
| 17 | + |
| 18 | + commit_short = commit[:6] |
| 19 | + sem_ver = ("%s+%s.%s" % (package_doc["version"], build_no, commit_short)) |
| 20 | + |
| 21 | + template_doc["Metadata"] = { |
| 22 | + "AWS::ServerlessRepo::Application": { |
| 23 | + "Name": package_doc["name"], |
| 24 | + "Description": package_doc["description"], |
| 25 | + "Author": package_doc["author"]["name"], |
| 26 | + "SpdxLicenseId": package_doc["license"], |
| 27 | + "HomePageUrl": package_doc["homepage"], |
| 28 | + "SourceCodeUrl": ("%s/tree/%s" % (package_doc["homepage"], commit_short)), |
| 29 | + "SemanticVersion": sem_ver |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + with open(path.join(path.dirname(input_file.name), 'packaged-versioned.yaml'), 'w') as output_file: |
| 34 | + yaml.dump(template_doc, output_file, sort_keys=False) |
| 35 | + |
| 36 | +if __name__ == "__main__": |
| 37 | + template = sys.argv[1] |
| 38 | + package = sys.argv[2] |
| 39 | + build_no = sys.argv[3] |
| 40 | + commit = sys.argv[4] |
| 41 | + main(template, package, build_no, commit) |
0 commit comments