-
Notifications
You must be signed in to change notification settings - Fork 2
Create GitHub release notes #202
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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,33 @@ | ||
from .helpers import get_package_list | ||
from .sections import ( | ||
release_notes_changes_section, | ||
release_notes_compare_package_versions_section, | ||
release_notes_software_components_section, | ||
) | ||
|
||
|
||
def create_github_release_notes(gardenlinux_version, commitish): | ||
package_list = get_package_list(gardenlinux_version) | ||
|
||
output = "" | ||
|
||
output += release_notes_changes_section(gardenlinux_version) | ||
|
||
output += release_notes_software_components_section(package_list) | ||
|
||
output += release_notes_compare_package_versions_section( | ||
gardenlinux_version, package_list | ||
) | ||
|
||
# TODO: image ids | ||
|
||
output += "\n" | ||
output += "## Kernel Module Build Container (kmodbuild)" | ||
output += "\n" | ||
output += "```" | ||
output += "\n" | ||
output += f"ghcr.io/gardenlinux/gardenlinux/kmodbuild:{gardenlinux_version}" | ||
output += "\n" | ||
output += "```" | ||
output += "\n" | ||
return output |
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 @@ | ||
import gzip | ||
import io | ||
|
||
import requests | ||
|
||
from gardenlinux.apt import DebsrcFile, GardenLinuxRepo | ||
from gardenlinux.apt.package_repo_info import compare_repo | ||
from gardenlinux.constants import GL_DEB_REPO_BASE_URL, REQUESTS_TIMEOUTS | ||
|
||
|
||
def get_package_list(gardenlinux_version): | ||
url = f"{GL_DEB_REPO_BASE_URL}/dists/{gardenlinux_version}/main/binary-amd64/Packages.gz" | ||
response = requests.get(url, timeout=REQUESTS_TIMEOUTS) | ||
response.raise_for_status() | ||
|
||
d = DebsrcFile() | ||
|
||
with io.BytesIO(response.content) as buf: | ||
with gzip.open(buf, "rt") as f: | ||
d.read(f) | ||
|
||
return d | ||
|
||
|
||
def compare_apt_repo_versions(previous_version, current_version): | ||
previous_repo = GardenLinuxRepo(previous_version) | ||
current_repo = GardenLinuxRepo(current_version) | ||
pkg_diffs = sorted(compare_repo(previous_repo, current_repo), key=lambda t: t[0]) | ||
|
||
output = f"| Package | {previous_version} | {current_version} |\n" | ||
output += "|---------|--------------------|-------------------|\n" | ||
|
||
for pkg in pkg_diffs: | ||
output += f"|{pkg[0]} | {pkg[1] if pkg[1] is not None else '-'} | {pkg[2] if pkg[2] is not None else '-'} |\n" | ||
return output |
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,112 @@ | ||
import re | ||
import textwrap | ||
|
||
import requests | ||
|
||
from gardenlinux.constants import GLVD_BASE_URL, REQUESTS_TIMEOUTS | ||
from gardenlinux.logger import LoggerSetup | ||
|
||
from .helpers import compare_apt_repo_versions | ||
|
||
LOGGER = LoggerSetup.get_logger("gardenlinux.github.release_notes", "INFO") | ||
|
||
|
||
def release_notes_changes_section(gardenlinux_version): | ||
""" | ||
Get list of fixed CVEs, grouped by upgraded package. | ||
Note: This result is not perfect, feel free to edit the generated release notes and | ||
file issues in glvd for improvement suggestions https://github.com/gardenlinux/glvd/issues | ||
""" | ||
try: | ||
url = f"{GLVD_BASE_URL}/patchReleaseNotes/{gardenlinux_version}" | ||
response = requests.get(url, timeout=REQUESTS_TIMEOUTS) | ||
response.raise_for_status() | ||
data = response.json() | ||
|
||
if len(data["packageList"]) == 0: | ||
return "" | ||
|
||
output = [ | ||
"## Changes", | ||
"The following packages have been upgraded, to address the mentioned CVEs:", | ||
] | ||
for package in data["packageList"]: | ||
upgrade_line = ( | ||
f"- upgrade '{package['sourcePackageName']}' from `{package['oldVersion']}` " | ||
f"to `{package['newVersion']}`" | ||
) | ||
output.append(upgrade_line) | ||
|
||
if package["fixedCves"]: | ||
for fixedCve in package["fixedCves"]: | ||
output.append(f" - {fixedCve}") | ||
|
||
return "\n".join(output) + "\n\n" | ||
except Exception as exn: | ||
# There are expected error cases, | ||
# for example with versions not supported by glvd (1443.x) | ||
# or when the api is not available | ||
# Fail gracefully by adding the placeholder we previously used, | ||
# so that the release note generation does not fail. | ||
LOGGER.error(f"Failed to process GLVD API output: {exn}") | ||
return textwrap.dedent( | ||
""" | ||
## Changes | ||
The following packages have been upgraded, to address the mentioned CVEs: | ||
**todo release facilitator: fill this in** | ||
""" | ||
) | ||
|
||
|
||
def release_notes_software_components_section(package_list): | ||
output = "## Software Component Versions\n" | ||
output += "```" | ||
output += "\n" | ||
packages_regex = re.compile( | ||
r"^linux-image-amd64$|^systemd$|^containerd$|^runc$|^curl$|^openssl$|^openssh-server$|^libc-bin$" | ||
) | ||
for entry in package_list.values(): | ||
if packages_regex.match(entry.deb_source): | ||
output += f"{entry!r}\n" | ||
output += "```" | ||
output += "\n\n" | ||
return output | ||
|
||
|
||
def release_notes_compare_package_versions_section(gardenlinux_version, package_list): | ||
output = "" | ||
version_components = gardenlinux_version.split(".") | ||
# Assumes we always have version numbers like 1443.2 | ||
if len(version_components) == 2: | ||
vivus-ignis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
major = int(version_components[0]) | ||
patch = int(version_components[1]) | ||
|
||
if patch > 0: | ||
previous_version = f"{major}.{patch - 1}" | ||
|
||
output += ( | ||
f"## Changes in Package Versions Compared to {previous_version}\n" | ||
) | ||
output += compare_apt_repo_versions( | ||
previous_version, gardenlinux_version | ||
) | ||
elif patch == 0: | ||
output += f"## Full List of Packages in Garden Linux version {major}\n" | ||
output += "<details><summary>Expand to see full list</summary>\n" | ||
output += "<pre>" | ||
output += "\n" | ||
for entry in package_list.values(): | ||
output += f"{entry!r}\n" | ||
output += "</pre>" | ||
output += "\n</details>\n\n" | ||
|
||
except ValueError: | ||
LOGGER.error( | ||
f"Could not parse {gardenlinux_version} as the Garden Linux version, skipping version compare section" | ||
) | ||
else: | ||
LOGGER.error( | ||
f"Unexpected version number format {gardenlinux_version}, expected format (major is int).(patch is int)" | ||
) | ||
return output |
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
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,39 @@ | ||
import requests_mock | ||
|
||
from gardenlinux.constants import GLVD_BASE_URL | ||
from gardenlinux.github.release_notes import ( | ||
release_notes_changes_section, | ||
release_notes_compare_package_versions_section, | ||
) | ||
|
||
from ..constants import TEST_GARDENLINUX_RELEASE | ||
|
||
|
||
def test_release_notes_changes_section_empty_packagelist(): | ||
with requests_mock.Mocker() as m: | ||
m.get( | ||
f"{GLVD_BASE_URL}/patchReleaseNotes/{TEST_GARDENLINUX_RELEASE}", | ||
text='{"packageList": []}', | ||
status_code=200 | ||
) | ||
assert release_notes_changes_section(TEST_GARDENLINUX_RELEASE) == "", \ | ||
"Expected an empty result if GLVD returns an empty package list" | ||
|
||
|
||
def test_release_notes_changes_section_broken_glvd_response(): | ||
with requests_mock.Mocker() as m: | ||
m.get( | ||
f"{GLVD_BASE_URL}/patchReleaseNotes/{TEST_GARDENLINUX_RELEASE}", | ||
text="<html><body><h1>Personal Home Page</h1></body></html>", | ||
status_code=200 | ||
) | ||
assert "fill this in" in release_notes_changes_section(TEST_GARDENLINUX_RELEASE), \ | ||
"Expected a placeholder message to be generated if GVLD response is not valid" | ||
|
||
|
||
def test_release_notes_compare_package_versions_section_semver_is_not_recognized(): | ||
assert release_notes_compare_package_versions_section("1.2.0", []) == "", "Semver is not supported" | ||
|
||
|
||
def test_release_notes_compare_package_versions_section_unrecognizable_version(): | ||
assert release_notes_compare_package_versions_section("garden.linux", []) == "" |
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.