| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""generate_release.py. |
| 6 |
|
| 7 |
This script is used to generate the release.yml file as per |
| 8 |
https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes |
| 9 |
""" |
| 10 |
|
| 11 |
from itertools import permutations |
| 12 |
from pathlib import Path |
| 13 |
|
| 14 |
import yaml |
| 15 |
|
| 16 |
BASE_SCOPES = [ |
| 17 |
"anta", |
| 18 |
"anta.tests", |
| 19 |
"anta.cli", |
| 20 |
] |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
SCOPES = [ |
| 25 |
*BASE_SCOPES, |
| 26 |
*["|".join(scopes) for scope_count in range(2, len(BASE_SCOPES) + 1) for scopes in permutations(BASE_SCOPES, scope_count)], |
| 27 |
] |
| 28 |
|
| 29 |
|
| 30 |
CATEGORIES = { |
| 31 |
"feat": "Features", |
| 32 |
"fix": "Bug Fixes", |
| 33 |
"cut": "Cut", |
| 34 |
"doc": "Documentation", |
| 35 |
"bump": "Bump", |
| 36 |
"revert": "Revert", |
| 37 |
"refactor": "Refactoring", |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
class SafeDumper(yaml.SafeDumper): |
| 42 |
"""Make yamllint happy. |
| 43 |
|
| 44 |
https://github.com/yaml/pyyaml/issues/234#issuecomment-765894586. |
| 45 |
""" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
def increase_indent(self, flow: bool = False, *_args: object, **_kwargs: object) -> None: |
| 50 |
"""Increase indentation for nested lists.""" |
| 51 |
return super().increase_indent(flow=flow, indentless=False) |
| 52 |
|
| 53 |
|
| 54 |
if __name__ == "__main__": |
| 55 |
exclude_list = [] |
| 56 |
categories_list = [] |
| 57 |
|
| 58 |
|
| 59 |
for scope in SCOPES: |
| 60 |
exclude_list.append(f"rn: test({scope})") |
| 61 |
exclude_list.append(f"rn: ci({scope})") |
| 62 |
exclude_list.extend(["rn: test", "rn: ci"]) |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
breaking_label_categories = ["feat", "fix", "cut", "revert", "refactor", "bump"] |
| 67 |
breaking_labels = [f"rn: {cc_type}({scope})!" for cc_type in breaking_label_categories for scope in SCOPES] |
| 68 |
breaking_labels.extend([f"rn: {cc_type}!" for cc_type in breaking_label_categories]) |
| 69 |
|
| 70 |
categories_list.append( |
| 71 |
{ |
| 72 |
"title": "Breaking Changes", |
| 73 |
"labels": breaking_labels, |
| 74 |
}, |
| 75 |
) |
| 76 |
|
| 77 |
|
| 78 |
feat_labels = [f"rn: feat({scope})" for scope in SCOPES] |
| 79 |
feat_labels.append("rn: feat") |
| 80 |
|
| 81 |
categories_list.append( |
| 82 |
{ |
| 83 |
"title": "New features and enhancements", |
| 84 |
"labels": feat_labels, |
| 85 |
}, |
| 86 |
) |
| 87 |
|
| 88 |
|
| 89 |
fixes_labels = [f"rn: fix({scope})" for scope in SCOPES] |
| 90 |
fixes_labels.append("rn: fix") |
| 91 |
|
| 92 |
categories_list.append( |
| 93 |
{ |
| 94 |
"title": "Fixed issues", |
| 95 |
"labels": fixes_labels, |
| 96 |
}, |
| 97 |
) |
| 98 |
|
| 99 |
|
| 100 |
doc_labels = [f"rn: doc({scope})" for scope in SCOPES] |
| 101 |
doc_labels.append("rn: doc") |
| 102 |
|
| 103 |
categories_list.append( |
| 104 |
{ |
| 105 |
"title": "Documentation", |
| 106 |
"labels": doc_labels, |
| 107 |
}, |
| 108 |
) |
| 109 |
|
| 110 |
|
| 111 |
categories_list.append( |
| 112 |
{ |
| 113 |
"title": "Other Changes", |
| 114 |
"labels": ["*"], |
| 115 |
}, |
| 116 |
) |
| 117 |
with Path(__file__).with_name("release.yml").open("w", encoding="utf-8") as release_file: |
| 118 |
yaml.dump( |
| 119 |
{ |
| 120 |
"changelog": { |
| 121 |
"exclude": {"labels": exclude_list}, |
| 122 |
"categories": categories_list, |
| 123 |
}, |
| 124 |
}, |
| 125 |
release_file, |
| 126 |
Dumper=SafeDumper, |
| 127 |
sort_keys=False, |
| 128 |
) |