Skip to content

Commit

Permalink
Add scripts to generate Release note (#484)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruinong Tian <[email protected]>
  • Loading branch information
TRNWWZ and Ruinong Tian authored Oct 3, 2024
1 parent 981276a commit 9932945
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
get_semver,
is_exists_dir_for_version,
)
from version_release_note_generator import generate_new_version_release_note

_docker_client = docker.from_env()

Expand Down Expand Up @@ -442,6 +443,21 @@ def get_arg_parser():
required=True,
help="Specify the target patch version for which the package dependency report needs to be generated.",
)
package_release_parser = subparsers.add_parser(
"generate-version-release-note",
help="Generates release for each new image version.",
)
package_release_parser.set_defaults(func=generate_new_version_release_note)
package_release_parser.add_argument(
"--target-patch-version",
required=True,
help="Specify the target patch version for which the release needs to be generated.",
)
package_release_parser.add_argument(
"--image-type",
required=True,
help="Specify the image type for which the release needs to be generated.",
)
return parser


Expand Down
23 changes: 23 additions & 0 deletions src/version_release_note_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from semver import Version

from utils import get_semver


def generate_new_version_release_note(args):
image_version: Version = get_semver(args.target_patch_version)
image_type = args.image_type

print(f"### Public ECR Gallery URL")
print(f"https://gallery.ecr.aws/sagemaker/sagemaker-distribution")
print(f"### Public ECR Image URL")
print("```")
print(f"public.ecr.aws/sagemaker/sagemaker-distribution:{image_version}-{image_type}")
print("```")

print("## Change Logs")
print(
f"Change log: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v{image_version.major}/v{image_version.major}.{image_version.minor}/v{image_version.major}.{image_version.minor}.{image_version.patch}/CHANGELOG-{image_type}.md"
)
print(
f"Release note: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v{image_version.major}/v{image_version.major}.{image_version.minor}/v{image_version.major}.{image_version.minor}.{image_version.patch}/RELEASE.md"
)
75 changes: 75 additions & 0 deletions test/test_version_release_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import unittest
from unittest.mock import patch

from version_release_note_generator import generate_new_version_release_note


class TestVersionReleaseGenerator(unittest.TestCase):
def test_generate_new_version_release_v0(self):
args = lambda: None
args.target_patch_version = "0.13.0"
args.image_type = "cpu"

# Act
with patch("builtins.print") as mock_print:
generate_new_version_release_note(args)

# Assert
expected_output = [
"### Public ECR Gallery URL",
"https://gallery.ecr.aws/sagemaker/sagemaker-distribution",
"### Public ECR Image URL",
"```",
"public.ecr.aws/sagemaker/sagemaker-distribution:0.13.0-cpu",
"```",
"## Change Logs",
"Change log: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v0/v0.13/v0.13.0/CHANGELOG-cpu.md",
"Release note: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v0/v0.13/v0.13.0/RELEASE.md",
]
mock_print.assert_has_calls([unittest.mock.call(line) for line in expected_output])

def test_generate_new_version_release_v1(self):
args = lambda: None
args.target_patch_version = "1.2.3"
args.image_type = "cpu"

# Act
with patch("builtins.print") as mock_print:
generate_new_version_release_note(args)

# Assert
expected_output = [
"### Public ECR Gallery URL",
"https://gallery.ecr.aws/sagemaker/sagemaker-distribution",
"### Public ECR Image URL",
"```",
"public.ecr.aws/sagemaker/sagemaker-distribution:1.2.3-cpu",
"```",
"## Change Logs",
"Change log: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v1/v1.2/v1.2.3/CHANGELOG-cpu.md",
"Release note: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v1/v1.2/v1.2.3/RELEASE.md",
]
mock_print.assert_has_calls([unittest.mock.call(line) for line in expected_output])

def test_generate_new_version_release_v2(self):
args = lambda: None
args.target_patch_version = "2.0.0"
args.image_type = "gpu"

# Act
with patch("builtins.print") as mock_print:
generate_new_version_release_note(args)

# Assert
expected_output = [
"### Public ECR Gallery URL",
"https://gallery.ecr.aws/sagemaker/sagemaker-distribution",
"### Public ECR Image URL",
"```",
"public.ecr.aws/sagemaker/sagemaker-distribution:2.0.0-gpu",
"```",
"## Change Logs",
"Change log: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v2/v2.0/v2.0.0/CHANGELOG-gpu.md",
"Release note: https://github.com/aws/sagemaker-distribution/blob/main/build_artifacts/v2/v2.0/v2.0.0/RELEASE.md",
]
mock_print.assert_has_calls([unittest.mock.call(line) for line in expected_output])

0 comments on commit 9932945

Please sign in to comment.