-
Notifications
You must be signed in to change notification settings - Fork 2k
Update release notes scripts #7962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pdabelf5
wants to merge
10
commits into
main
Choose a base branch
from
chore/update-release-notes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4594689
update release notes scripts
AlexFenlon 80f58a2
file no longer required
pdabelf5 cb204c8
add requirements.txt for running release notes generation script
pdabelf5 876f81f
test script in pipeline
pdabelf5 974712e
debugging
pdabelf5 110886c
fixup version
pdabelf5 c31814d
debugging
pdabelf5 d914c8b
remove debug
pdabelf5 e4cb754
address copilot feedback
pdabelf5 e54f5f3
Merge branch 'main' into chore/update-release-notes
pdabelf5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o pipefail | ||
|
||
usage() { | ||
echo "Usage: $0 <docs_folder> <new_ic_version> <new_helm_chart_version> <new_operator_version>" | ||
exit 1 | ||
} | ||
|
||
docs_folder=$1 | ||
new_ic_version=$2 | ||
new_helm_chart_version=$3 | ||
new_operator_version=$4 | ||
|
||
if [ -z "${docs_folder}" ]; then | ||
usage | ||
fi | ||
|
||
if [ -z "${new_ic_version}" ]; then | ||
usage | ||
fi | ||
|
||
if [ -z "${new_helm_chart_version}" ]; then | ||
usage | ||
fi | ||
|
||
if [ -z "${new_operator_version}" ]; then | ||
usage | ||
fi | ||
|
||
|
||
# update docs with new versions | ||
echo -n "${new_ic_version}" > ${docs_folder}/layouts/shortcodes/nic-version.html | ||
echo -n "${new_helm_chart_version}" > ${docs_folder}/layouts/shortcodes/nic-helm-version.html | ||
echo -n "${new_operator_version}" > ${docs_folder}/layouts/shortcodes/nic-operator-version.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import os | ||
import re | ||
import sys | ||
|
||
from github import Auth, Github | ||
from jinja2 import Environment, FileSystemLoader, select_autoescape | ||
|
||
# parse args | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("nic_version", help="NGINX Ingress Controller version") | ||
parser.add_argument("helm_chart_version", help="NGINX Ingress Controller Helm chart version") | ||
parser.add_argument("k8s_versions", help="Kubernetes versions") | ||
parser.add_argument("release_date", help="Release date") | ||
args = parser.parse_args() | ||
NIC_VERSION = args.nic_version | ||
HELM_CHART_VERSION = args.helm_chart_version | ||
K8S_VERSIONS = args.k8s_versions | ||
RELEASE_DATE = args.release_date | ||
|
||
# Set up Jinja2 environment | ||
template_dir = os.path.dirname(os.path.abspath(__file__)) | ||
env = Environment(loader=FileSystemLoader(template_dir), autoescape=select_autoescape(["j2"])) | ||
template = env.get_template("release-notes.j2") | ||
|
||
# Setup required variables | ||
github_org = os.getenv("GITHUB_ORG", "nginx") | ||
github_repo = os.getenv("GITHUB_REPO", "kubernetes-ingress") | ||
token = os.environ.get("GITHUB_TOKEN") | ||
docker_pr_strings = ["Docker image update", "docker group", "docker-images group", "in /build"] | ||
golang_pr_strings = ["go group", "go_modules group"] | ||
|
||
# Setup regex's | ||
# Matches: | ||
# My new change by @gihubhandle in https://github.com/<org>/<repo>/pull/<number> | ||
# Captures change title and PR URL | ||
change_regex = r"^(.*) by @.* in (.*)$" | ||
# Matches: | ||
# https://github.com/<org>/<repo>/pull/<number> | ||
# Captures PR number | ||
pull_request_regex = r"^.*pull/(\d+)$" | ||
|
||
|
||
def parse_sections(markdown: str): | ||
sections = {} | ||
section_name = None | ||
for line in markdown.splitlines(): | ||
# Check if the line starts with a section header | ||
# Section headers start with "### " | ||
# We will use the section header as the key in the sections dictionary | ||
# and the lines below it as the values (until the next section header) | ||
line = line.strip() | ||
if not line: | ||
continue # skip empty lines | ||
if line.startswith("### "): | ||
section_name = line[3:].strip() | ||
sections[section_name] = [] | ||
# If the line starts with "* " and contains "made their first contribution", | ||
# we will skip it as it is not a change but a contributor note | ||
elif section_name and line.startswith("* ") and "made their first contribution" in line: | ||
continue | ||
# Check if the line starts with "* " or "- " | ||
# If it does, we will add the line to the current section | ||
# We will also strip the "* " or "- " from the beginning of the line | ||
elif section_name and line.strip().startswith("* "): | ||
sections[section_name].append(line.strip()[2:].strip()) | ||
return sections | ||
|
||
|
||
def format_pr_groups(prs, title): | ||
# join the PR's into a comma, space separated string | ||
comma_sep_prs = "".join([f"{dep['details']}, " for dep in prs]) | ||
|
||
# strip the last comma and space, and add the first PR title | ||
trimmed_comma_sep_prs = f"{comma_sep_prs.rstrip(', ')} {title}" | ||
|
||
# split the string by the last comma and join with an ampersand | ||
split_result = trimmed_comma_sep_prs.rsplit(",", 1) | ||
return " &".join(split_result) | ||
|
||
|
||
# Get release text | ||
def get_github_release(version, github_org, github_repo, token): | ||
if token == "": | ||
print("ERROR: GITHUB token variable cannot be empty") | ||
return None | ||
auth = Auth.Token(token) | ||
g = Github(auth=auth) | ||
repo = g.get_organization(github_org).get_repo(github_repo) | ||
release = None | ||
releases = repo.get_releases() | ||
for rel in releases: | ||
if rel.tag_name == f"v{version}": | ||
release = rel | ||
break | ||
g.close() | ||
if release is not None: | ||
return release.body | ||
print(f"ERROR: Release v{NIC_VERSION} not found in {github_org}/{github_repo}.") | ||
return None | ||
|
||
|
||
## Main section of script | ||
|
||
release_body = get_github_release(NIC_VERSION, github_org, github_repo, token) | ||
if release_body is None: | ||
print("ERROR: Cannot get release from Github. Exiting...") | ||
sys.exit(1) | ||
|
||
# Parse the release body to extract sections | ||
sections = parse_sections(release_body or "") | ||
|
||
# Prepare the data for rendering | ||
# We will create a dictionary with the categories and their changes | ||
# Also, we will handle dependencies separately for Go and Docker images | ||
# and format them accordingly | ||
catagories = {} | ||
dependencies_title = "" | ||
for title, changes in sections.items(): | ||
if any(x in title for x in ["Other Changes", "Documentation", "Maintenance", "Tests"]): | ||
# These sections do not show up in the docs release notes | ||
continue | ||
parsed_changes = [] | ||
go_dependencies = [] | ||
docker_dependencies = [] | ||
for line in changes: | ||
change = re.search(change_regex, line) | ||
change_title = change.group(1) | ||
pr_link = change.group(2) | ||
pr_number = re.search(pull_request_regex, pr_link).group(1) | ||
pr = {"details": f"[{pr_number}]({pr_link})", "title": change_title.capitalize()} | ||
if "Dependencies" in title: | ||
# save section title for later use as lookup key to categories dict | ||
dependencies_title = title | ||
|
||
# Append Golang changes in to the go_dependencies list for later processing | ||
if any(str in change_title for str in golang_pr_strings): | ||
go_dependencies.append(pr) | ||
# Append Docker changes in to the docker_dependencies list for later processing | ||
elif any(str in change_title for str in docker_pr_strings): | ||
docker_dependencies.append(pr) | ||
# Treat this change like any other ungrouped change | ||
else: | ||
parsed_changes.append(f"{pr['details']} {pr['title']}") | ||
else: | ||
parsed_changes.append(f"{pr['details']} {pr['title']}") | ||
|
||
catagories[title] = parsed_changes | ||
|
||
# Add grouped dependencies to the Dependencies category | ||
catagories[dependencies_title].append(format_pr_groups(docker_dependencies, "Bump Docker dependencies")) | ||
catagories[dependencies_title].append(format_pr_groups(go_dependencies, "Bump Go dependencies")) | ||
catagories[dependencies_title].reverse() | ||
|
||
# Populates the data needed for rendering the template | ||
# The data will be passed to the Jinja2 template for rendering | ||
data = { | ||
"version": NIC_VERSION, | ||
"release_date": RELEASE_DATE, | ||
"sections": catagories, | ||
"HELM_CHART_VERSION": HELM_CHART_VERSION, | ||
"K8S_VERSIONS": K8S_VERSIONS, | ||
} | ||
|
||
# Render with Jinja2 | ||
print(template.render(**data)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.