-
Notifications
You must be signed in to change notification settings - Fork 14.4k
/
build_changelog_annotations.py
executable file
·108 lines (91 loc) · 3.45 KB
/
build_changelog_annotations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Take normal chart CHANGELOG entries and build ArtifactHub changelog annotations.
Only outputs the annotations for the latest release in the CHANGELOG.
e.g from:
New Features
------------
- Add resources for `cleanup` and `createuser` jobs (#19263)
to:
- kind: added
description: Add resources for `cleanup` and `createuser` jobs
links:
- name: "#19263"
url: https://github.com/apache/airflow/pull/19263
"""
from __future__ import annotations
import re
import yaml
TYPE_MAPPING = {
# CHANGELOG: (ArtifactHub kind, prefix for description)
# ArtifactHub kind must be one of: added, changed, deprecated, removed, fixed or security
"New Features": ("added", None),
"Improvements": ("changed", None),
"Bug Fixes": ("fixed", None),
"Doc only changes": ("changed", "Docs"),
"Misc": ("changed", "Misc"),
}
PREFIXES_TO_STRIP = [
# case insensitive
"Chart:",
"Chart Docs:",
]
def parse_line(line: str) -> tuple[str | None, int | None]:
match = re.search(r"^- (.*?)(?:\(#(\d+)\)){0,1}$", line)
if not match:
return None, None
desc, pr_number = match.groups()
return desc.strip(), int(pr_number)
def print_entry(section: str, description: str, pr_number: int | None):
for unwanted_prefix in PREFIXES_TO_STRIP:
if description.lower().startswith(unwanted_prefix.lower()):
description = description[len(unwanted_prefix) :].strip()
kind, prefix = TYPE_MAPPING[section]
if prefix:
description = f"{prefix}: {description}"
entry: dict[str, str | list] = {"kind": kind, "description": description}
if pr_number:
entry["links"] = [
{"name": f"#{pr_number}", "url": f"https://github.com/apache/airflow/pull/{pr_number}"}
]
print(yaml.dump([entry]))
in_first_release = False
past_significant_changes = False
section = ""
with open("chart/RELEASE_NOTES.rst") as f:
for line in f:
line = line.strip()
if not line or line.startswith(('"""', "----", "^^^^")):
pass
elif line.startswith("Airflow Helm Chart"):
# We only want to get annotations for the "latest" release
if in_first_release:
break
in_first_release = True
# Make sure we get past "significant features" before we actually start keeping track
elif not past_significant_changes:
if line == "New Features":
section = line
past_significant_changes = True
elif not line.startswith("- "):
section = line
else:
description, pr = parse_line(line)
if description:
print_entry(section, description, pr)