Skip to content

Commit 92dc6ee

Browse files
committed
release notes sections creation
1 parent c0a9c28 commit 92dc6ee

File tree

8 files changed

+84
-11
lines changed

8 files changed

+84
-11
lines changed

src/gardenlinux/apt/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"""
66

77
from .debsource import Debsrc, DebsrcFile
8+
from .package_repo_info import GardenLinuxRepo
89

9-
__all__ = ["Debsrc", "DebsrcFile"]
10+
__all__ = ["Debsrc", "DebsrcFile", "GardenLinuxRepo"]

src/gardenlinux/constants.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# -*- coding: utf-8 -*-
1+
import os
2+
from pathlib import Path
23

34
ARCHS = ["amd64", "arm64"]
45

@@ -149,3 +150,7 @@
149150
RELEASE_ID_FILE = ".github_release_id"
150151

151152
REQUESTS_TIMEOUTS = (5, 30) # connect, read
153+
154+
S3_DOWNLOADS_DIR = Path(os.path.dirname(__file__)) / ".." / "s3_downloads"
155+
156+
GLVD_BASE_URL = "https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com/v1"

src/gardenlinux/github/__main__.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import argparse
22

3-
from .release import upload_to_github_release_page
3+
from gardenlinux.logger import LoggerSetup
4+
5+
from .release import create_github_release, upload_to_github_release_page, write_to_release_id_file
6+
from .release_notes import create_github_release_notes
7+
8+
LOGGER = LoggerSetup.get_logger("gardenlinux.github", "INFO")
49

510

611
def main():
712
parser = argparse.ArgumentParser(description="GitHub Release Script")
813
subparsers = parser.add_subparsers(dest="command")
914

15+
create_parser = subparsers.add_parser("create")
16+
create_parser.add_argument("--owner", default="gardenlinux")
17+
create_parser.add_argument("--repo", default="gardenlinux")
18+
create_parser.add_argument("--tag", required=True)
19+
create_parser.add_argument("--commit", required=True)
20+
create_parser.add_argument('--latest', action='store_true', default=False)
21+
create_parser.add_argument("--dry-run", action="store_true", default=False)
22+
1023
upload_parser = subparsers.add_parser("upload")
1124
upload_parser.add_argument("--owner", default="gardenlinux")
1225
upload_parser.add_argument("--repo", default="gardenlinux")
@@ -16,7 +29,19 @@ def main():
1629

1730
args = parser.parse_args()
1831

19-
if args.command == "upload":
32+
if args.command == "create":
33+
body = create_github_release_notes(args.tag, args.commit)
34+
if args.dry_run:
35+
print("Dry Run ...")
36+
print("This release would be created:")
37+
print(body)
38+
else:
39+
release_id = create_github_release(
40+
args.owner, args.repo, args.tag, args.commit, args.latest, body
41+
)
42+
write_to_release_id_file(f"{release_id}")
43+
LOGGER.info(f"Release created with ID: {release_id}")
44+
elif args.command == "upload":
2045
upload_to_github_release_page(
2146
args.owner, args.repo, args.release_id, args.file_path, args.dry_run
2247
)

src/gardenlinux/github/release_notes/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def create_github_release_notes(gardenlinux_version, commitish):
1919
gardenlinux_version, package_list
2020
)
2121

22+
# TODO: image ids
23+
2224
output += "\n"
2325
output += "## Kernel Module Build Container (kmodbuild)"
2426
output += "\n"

src/gardenlinux/github/release_notes/sections.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import requests
55

6-
from gardenlinux.constants import REQUESTS_TIMEOUTS
6+
from gardenlinux.constants import GLVD_BASE_URL, REQUESTS_TIMEOUTS
77
from gardenlinux.logger import LoggerSetup
88

99
from .helpers import compare_apt_repo_versions
@@ -18,7 +18,7 @@ def release_notes_changes_section(gardenlinux_version):
1818
file issues in glvd for improvement suggestions https://github.com/gardenlinux/glvd/issues
1919
"""
2020
try:
21-
url = f"https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com/v1/patchReleaseNotes/{gardenlinux_version}"
21+
url = f"{GLVD_BASE_URL}/patchReleaseNotes/{gardenlinux_version}"
2222
response = requests.get(url, timeout=REQUESTS_TIMEOUTS)
2323
response.raise_for_status()
2424
data = response.json()
@@ -43,8 +43,11 @@ def release_notes_changes_section(gardenlinux_version):
4343

4444
return "\n".join(output) + "\n\n"
4545
except Exception as exn:
46-
# There are expected error cases, for example with versions not supported by glvd (1443.x) or when the api is not available
47-
# Fail gracefully by adding the placeholder we previously used, so that the release note generation does not fail.
46+
# There are expected error cases,
47+
# for example with versions not supported by glvd (1443.x)
48+
# or when the api is not available
49+
# Fail gracefully by adding the placeholder we previously used,
50+
# so that the release note generation does not fail.
4851
LOGGER.error(f"Failed to process GLVD API output: {exn}")
4952
return textwrap.dedent(
5053
"""

tests/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,4 @@
2727
TEST_GARDENLINUX_RELEASE = "1877.3"
2828
TEST_GARDENLINUX_COMMIT = "75df9f401a842914563f312899ec3ce34b24515c"
2929

30-
RELEASE_ID_FILE = ".github_release_id"
31-
3230
S3_DOWNLOADS_DIR = Path(os.path.dirname(__file__)) / ".." / "s3_downloads"

tests/github/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from ..constants import RELEASE_ID_FILE, S3_DOWNLOADS_DIR
7+
from gardenlinux.constants import RELEASE_ID_FILE, S3_DOWNLOADS_DIR
88

99

1010
@pytest.fixture
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import requests_mock
2+
3+
from gardenlinux.constants import GLVD_BASE_URL
4+
from gardenlinux.github.release_notes import (
5+
release_notes_changes_section,
6+
release_notes_compare_package_versions_section,
7+
)
8+
9+
from ..constants import TEST_GARDENLINUX_RELEASE
10+
11+
12+
def test_release_notes_changes_section_empty_packagelist():
13+
with requests_mock.Mocker() as m:
14+
m.get(
15+
f"{GLVD_BASE_URL}/patchReleaseNotes/{TEST_GARDENLINUX_RELEASE}",
16+
text='{"packageList": []}',
17+
status_code=200
18+
)
19+
assert release_notes_changes_section(TEST_GARDENLINUX_RELEASE) == "", \
20+
"Expected an empty result if GLVD returns an empty package list"
21+
22+
23+
def test_release_notes_changes_section_broken_glvd_response():
24+
with requests_mock.Mocker() as m:
25+
m.get(
26+
f"{GLVD_BASE_URL}/patchReleaseNotes/{TEST_GARDENLINUX_RELEASE}",
27+
text="<html><body><h1>Personal Home Page</h1></body></html>",
28+
status_code=200
29+
)
30+
assert "fill this in" in release_notes_changes_section(TEST_GARDENLINUX_RELEASE), \
31+
"Expected a placeholder message to be generated if GVLD response is not valid"
32+
33+
34+
def test_release_notes_compare_package_versions_section_semver_is_not_recognized():
35+
assert release_notes_compare_package_versions_section("1.2.0", []) == "", "Semver is not supported"
36+
37+
38+
def test_release_notes_compare_package_versions_section_unrecognizable_version():
39+
assert release_notes_compare_package_versions_section("garden.linux", []) == ""

0 commit comments

Comments
 (0)