|
7 | 7 | # containing each product name and associated last version. |
8 | 8 | # Used in CI when a new is release is creted to comment it. |
9 | 9 | def listVersions(source_path): |
| 10 | + print("Extracting products name and version from Spack recipes") |
10 | 11 | recipes = glob.glob(source_path + '/**/package.py', recursive=True) |
| 12 | + products = {} |
| 13 | + for recipe in recipes: |
| 14 | + with open(recipe) as f: |
| 15 | + product_name = os.path.basename(os.path.dirname(recipe)) |
| 16 | + line = ' '.join(f.readlines()) |
| 17 | + version = re.search("version\([\'\"]([0-9]+(\.[0-9]+)*)[\'\"]", line) |
| 18 | + version_name = 'undefined' if version is None else version.group(1) |
| 19 | + recipes[product_name] = version_name |
| 20 | + print(products) |
| 21 | + |
11 | 22 | file_name = source_path + '/recipes.md' |
| 23 | + print("Creating markdown file:", file_name) |
12 | 24 | with open(file_name, 'w') as md: |
13 | 25 | md.write('**Below the last version of products contained in Spack recipes for this release.**\n') |
14 | 26 | md.write('| Product | Version |\n') |
15 | 27 | md.write('| ------- | ------- |\n') |
16 | | - for recipe in recipes: |
17 | | - with open(recipe) as f: |
18 | | - product_name = os.path.basename(os.path.dirname(recipe)) |
19 | | - line = ' '.join(f.readlines()) |
20 | | - version = re.search("version\([\'\"]([0-9]+(\.[0-9]+)*)[\'\"]", line) |
21 | | - version_name = 'undefined' if version is None else version.group(1) |
22 | | - md.write('| ' + product_name + ' | ' + version_name + ' |\n') |
| 28 | + for product in products: |
| 29 | + product_name = product[0] |
| 30 | + version = product[1] |
| 31 | + md.write('| ' + product_name + ' | ' + version + ' |\n') |
23 | 32 | print("File created:", file_name) |
24 | 33 |
|
| 34 | + file_name = source_path + '/recipes.sh' |
| 35 | + print("Creating bash file:", file_name) |
| 36 | + with open(file_name, 'w') as md: |
| 37 | + md.write('#!/bin/bash\n\n') |
| 38 | + md.write('declare -A products\n') |
| 39 | + for product in products: |
| 40 | + product_name = product[0] |
| 41 | + version = product[1] |
| 42 | + md.write('products[' + product_name + ']=' + version + '\n') |
| 43 | + print("File created:", file_name) |
| 44 | + |
25 | 45 | if __name__ == "__main__": |
26 | 46 | project_path = sys.argv[1] |
27 | 47 | listVersions(project_path) |
0 commit comments