Skip to content

Commit c225b55

Browse files
authored
Merge branch 'main' into deps/version-bump-nginx-1.29.0
2 parents 16c42bf + 5744fbc commit c225b55

21 files changed

+1510
-726
lines changed

.github/data/version.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
IC_VERSION=5.1.0
2-
HELM_CHART_VERSION=2.2.0
1+
IC_VERSION=5.2.0
2+
HELM_CHART_VERSION=2.3.0

.github/dependabot.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ updates:
4545
- "patch"
4646

4747
- package-ecosystem: pip
48-
directory: /tests
48+
directory: /
4949
schedule:
5050
interval: weekly
5151
groups:
@@ -54,8 +54,3 @@ updates:
5454
- "major"
5555
- "minor"
5656
- "patch"
57-
58-
- package-ecosystem: gomod
59-
directory: /site
60-
schedule:
61-
interval: weekly
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -o pipefail
4+
5+
usage() {
6+
echo "Usage: $0 <docs_folder> <new_ic_version> <new_helm_chart_version> <new_operator_version>"
7+
exit 1
8+
}
9+
10+
docs_folder=$1
11+
new_ic_version=$2
12+
new_helm_chart_version=$3
13+
new_operator_version=$4
14+
15+
if [ -z "${docs_folder}" ]; then
16+
usage
17+
fi
18+
19+
if [ -z "${new_ic_version}" ]; then
20+
usage
21+
fi
22+
23+
if [ -z "${new_helm_chart_version}" ]; then
24+
usage
25+
fi
26+
27+
if [ -z "${new_operator_version}" ]; then
28+
usage
29+
fi
30+
31+
32+
# update docs with new versions
33+
echo -n "${new_ic_version}" > ${docs_folder}/layouts/shortcodes/nic-version.html
34+
echo -n "${new_helm_chart_version}" > ${docs_folder}/layouts/shortcodes/nic-helm-version.html
35+
echo -n "${new_operator_version}" > ${docs_folder}/layouts/shortcodes/nic-operator-version.html

.github/scripts/exclude_ci_files.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
.github/ISSUE_TEMPLATE/*
1111
.github/scripts/create-release-tarballs.sh
1212
.github/scripts/docker-updater.sh
13-
.github/scripts/release-notes-update.sh
13+
.github/scripts/docs-shortcode-update.sh
14+
.github/scripts/pull-release-notes.py
15+
.github/scripts/release-docs.sh
16+
.github/scripts/release-notes.j2
1417
.github/scripts/release-version-update.sh
18+
.github/scripts/requirements.txt
1519
.github/workflows/build-base-images.yml
1620
.github/workflows/build-ot-dependency.yml
1721
.github/workflows/build-test-image.yml

.github/scripts/pull-release-notes.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import os
5+
import re
6+
import sys
7+
8+
from github import Auth, Github
9+
from jinja2 import Environment, FileSystemLoader, select_autoescape
10+
11+
# parse args
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument("nic_version", help="NGINX Ingress Controller version")
14+
parser.add_argument("helm_chart_version", help="NGINX Ingress Controller Helm chart version")
15+
parser.add_argument("k8s_versions", help="Kubernetes versions")
16+
parser.add_argument("release_date", help="Release date")
17+
args = parser.parse_args()
18+
NIC_VERSION = args.nic_version
19+
HELM_CHART_VERSION = args.helm_chart_version
20+
K8S_VERSIONS = args.k8s_versions
21+
RELEASE_DATE = args.release_date
22+
23+
# Set up Jinja2 environment
24+
template_dir = os.path.dirname(os.path.abspath(__file__))
25+
env = Environment(loader=FileSystemLoader(template_dir), autoescape=select_autoescape(["j2"]))
26+
template = env.get_template("release-notes.j2")
27+
28+
# Setup required variables
29+
github_org = os.getenv("GITHUB_ORG", "nginx")
30+
github_repo = os.getenv("GITHUB_REPO", "kubernetes-ingress")
31+
token = os.environ.get("GITHUB_TOKEN")
32+
docker_pr_strings = ["Docker image update", "docker group", "docker-images group", "in /build"]
33+
golang_pr_strings = ["go group", "go_modules group"]
34+
35+
# Setup regex's
36+
# Matches:
37+
# My new change by @gihubhandle in https://github.com/<org>/<repo>/pull/<number>
38+
# Captures change title and PR URL
39+
change_regex = r"^(.*) by @.* in (.*)$"
40+
# Matches:
41+
# https://github.com/<org>/<repo>/pull/<number>
42+
# Captures PR number
43+
pull_request_regex = r"^.*pull/(\d+)$"
44+
45+
46+
def parse_sections(markdown: str):
47+
sections = {}
48+
section_name = None
49+
for line in markdown.splitlines():
50+
# Check if the line starts with a section header
51+
# Section headers start with "### "
52+
# We will use the section header as the key in the sections dictionary
53+
# and the lines below it as the values (until the next section header)
54+
line = line.strip()
55+
if not line:
56+
continue # skip empty lines
57+
if line.startswith("### "):
58+
section_name = line[3:].strip()
59+
sections[section_name] = []
60+
# If the line starts with "* " and contains "made their first contribution",
61+
# we will skip it as it is not a change but a contributor note
62+
elif section_name and line.startswith("* ") and "made their first contribution" in line:
63+
continue
64+
# Check if the line starts with "* " or "- "
65+
# If it does, we will add the line to the current section
66+
# We will also strip the "* " or "- " from the beginning of the line
67+
elif section_name and line.strip().startswith("* "):
68+
sections[section_name].append(line.strip()[2:].strip())
69+
return sections
70+
71+
72+
def format_pr_groups(prs, title):
73+
# join the PR's into a comma, space separated string
74+
comma_sep_prs = "".join([f"{dep['details']}, " for dep in prs])
75+
76+
# strip the last comma and space, and add the first PR title
77+
trimmed_comma_sep_prs = f"{comma_sep_prs.rstrip(', ')} {title}"
78+
79+
# split the string by the last comma and join with an ampersand
80+
split_result = trimmed_comma_sep_prs.rsplit(",", 1)
81+
return " &".join(split_result)
82+
83+
84+
# Get release text
85+
def get_github_release(version, github_org, github_repo, token):
86+
if token == "":
87+
print("ERROR: GITHUB token variable cannot be empty")
88+
return None
89+
auth = Auth.Token(token)
90+
g = Github(auth=auth)
91+
repo = g.get_organization(github_org).get_repo(github_repo)
92+
release = None
93+
releases = repo.get_releases()
94+
for rel in releases:
95+
if rel.tag_name == f"v{version}":
96+
release = rel
97+
break
98+
g.close()
99+
if release is not None:
100+
return release.body
101+
print(f"ERROR: Release v{NIC_VERSION} not found in {github_org}/{github_repo}.")
102+
return None
103+
104+
105+
## Main section of script
106+
107+
release_body = get_github_release(NIC_VERSION, github_org, github_repo, token)
108+
if release_body is None:
109+
print("ERROR: Cannot get release from Github. Exiting...")
110+
sys.exit(1)
111+
112+
# Parse the release body to extract sections
113+
sections = parse_sections(release_body or "")
114+
115+
# Prepare the data for rendering
116+
# We will create a dictionary with the categories and their changes
117+
# Also, we will handle dependencies separately for Go and Docker images
118+
# and format them accordingly
119+
catagories = {}
120+
dependencies_title = ""
121+
for title, changes in sections.items():
122+
if any(x in title for x in ["Other Changes", "Documentation", "Maintenance", "Tests"]):
123+
# These sections do not show up in the docs release notes
124+
continue
125+
parsed_changes = []
126+
go_dependencies = []
127+
docker_dependencies = []
128+
for line in changes:
129+
change = re.search(change_regex, line)
130+
change_title = change.group(1)
131+
pr_link = change.group(2)
132+
pr_number = re.search(pull_request_regex, pr_link).group(1)
133+
pr = {"details": f"[{pr_number}]({pr_link})", "title": change_title.capitalize()}
134+
if "Dependencies" in title:
135+
# save section title for later use as lookup key to categories dict
136+
dependencies_title = title
137+
138+
# Append Golang changes in to the go_dependencies list for later processing
139+
if any(str in change_title for str in golang_pr_strings):
140+
go_dependencies.append(pr)
141+
# Append Docker changes in to the docker_dependencies list for later processing
142+
elif any(str in change_title for str in docker_pr_strings):
143+
docker_dependencies.append(pr)
144+
# Treat this change like any other ungrouped change
145+
else:
146+
parsed_changes.append(f"{pr['details']} {pr['title']}")
147+
else:
148+
parsed_changes.append(f"{pr['details']} {pr['title']}")
149+
150+
catagories[title] = parsed_changes
151+
152+
# Add grouped dependencies to the Dependencies category
153+
catagories[dependencies_title].append(format_pr_groups(docker_dependencies, "Bump Docker dependencies"))
154+
catagories[dependencies_title].append(format_pr_groups(go_dependencies, "Bump Go dependencies"))
155+
catagories[dependencies_title].reverse()
156+
157+
# Populates the data needed for rendering the template
158+
# The data will be passed to the Jinja2 template for rendering
159+
data = {
160+
"version": NIC_VERSION,
161+
"release_date": RELEASE_DATE,
162+
"sections": catagories,
163+
"HELM_CHART_VERSION": HELM_CHART_VERSION,
164+
"K8S_VERSIONS": K8S_VERSIONS,
165+
}
166+
167+
# Render with Jinja2
168+
print(template.render(**data))

0 commit comments

Comments
 (0)