-
Notifications
You must be signed in to change notification settings - Fork 24
ci: add gate, preflight and verification to testing image release #718
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
nvasiu
wants to merge
2
commits into
main
Choose a base branch
from
gate-ecr-release
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
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: 2025-present Amazon.com, Inc. or its affiliates. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
|
|
||
| from packaging.version import InvalidVersion, Version | ||
|
|
||
|
|
||
| def is_newest(candidate: str, existing_tags: list[str]) -> bool: | ||
| """True if candidate is >= every v<semver> tag in existing_tags. | ||
|
|
||
| Non-version tags (latest, malformed) are ignored. With no existing | ||
| version tags the candidate is newest by default. | ||
| """ | ||
| candidate_version = Version(candidate) | ||
| highest = candidate_version | ||
| for tag in existing_tags: | ||
| if not tag.startswith("v"): | ||
| continue | ||
| try: | ||
| version = Version(tag[1:]) | ||
| except InvalidVersion: | ||
| continue | ||
| if version > highest: | ||
| highest = version | ||
| return candidate_version >= highest | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser( | ||
| description="Decide whether a release version is the newest published." | ||
| ) | ||
| parser.add_argument("--candidate", required=True) | ||
| parser.add_argument( | ||
| "tags", nargs="*", help="Existing image tags, e.g. v1.2.1 v2.0.0 latest" | ||
| ) | ||
| args = parser.parse_args(argv) | ||
|
|
||
| print("true" if is_newest(args.candidate, args.tags) else "false") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
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,46 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: 2025-present Amazon.com, Inc. or its affiliates. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
|
|
||
| from packaging.version import InvalidVersion, Version | ||
|
|
||
|
|
||
| def latest_version(existing_tags: list[str]) -> str: | ||
| """Return the highest v<semver> tag, or empty if there are none. | ||
|
|
||
| Non-version tags (latest, malformed) are ignored. | ||
| """ | ||
| highest: Version | None = None | ||
| highest_tag = "" | ||
| for tag in existing_tags: | ||
| if not tag.startswith("v"): | ||
| continue | ||
| try: | ||
| version = Version(tag[1:]) | ||
| except InvalidVersion: | ||
| continue | ||
| if highest is None or version > highest: | ||
| highest = version | ||
| highest_tag = tag | ||
| return highest_tag | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser( | ||
| description="Print the highest published testing version tag." | ||
| ) | ||
| parser.add_argument( | ||
| "tags", nargs="*", help="Existing image tags, e.g. v1.2.1 v2.0.0 latest" | ||
| ) | ||
| args = parser.parse_args(argv) | ||
|
|
||
| print(latest_version(args.tags)) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
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,38 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: 2025-present Amazon.com, Inc. or its affiliates. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import re | ||
|
|
||
| # A release-tag component naming the testing package: testing-v<x.y.z> with an | ||
| # optional pre-release suffix. Anchored and matched against a single comma-split | ||
| # component so prefixes like "mytesting-v1.2.1" are rejected. | ||
| _COMPONENT = re.compile(r"testing-v([0-9]+\.[0-9]+\.[0-9]+[0-9A-Za-z.-]*)\Z") | ||
|
|
||
|
|
||
| def parse_testing_version(release_tag: str) -> str: | ||
| """Return the testing version named by the release tag, or empty if none.""" | ||
| for part in release_tag.split(","): | ||
| match = _COMPONENT.fullmatch(part.strip()) | ||
| if match: | ||
| return match.group(1) | ||
| return "" | ||
|
|
||
|
|
||
| def main(): | ||
| release_tag = os.environ.get("RELEASE_TAG", "") | ||
| tag_version = parse_testing_version(release_tag) | ||
|
|
||
| github_output = os.environ.get("GITHUB_OUTPUT") | ||
| if github_output: | ||
| with open(github_output, "a", encoding="utf-8") as f: | ||
| f.write(f"tag_version={tag_version}\n") | ||
|
|
||
| print(tag_version) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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,42 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: 2025-present Amazon.com, Inc. or its affiliates. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
|
|
||
| from is_newest_testing_version import is_newest | ||
|
|
||
|
|
||
| def test_is_newest(): | ||
| test_cases = [ | ||
| # Newest so far | ||
| ("2.0.0", ["v1.2.1", "v1.1.3", "latest"], True), | ||
| # First ever release | ||
| ("1.0.0", [], True), | ||
| ("1.0.0", ["latest"], True), | ||
| # Equal to the highest counts as newest (idempotent re-publish) | ||
| ("2.0.0", ["v2.0.0", "latest"], True), | ||
| # Backport below the highest is NOT newest | ||
| ("1.1.3", ["v1.2.1", "v2.0.0", "latest"], False), | ||
| ("1.9.9", ["v2.0.0"], False), | ||
| # Malformed and non-version tags are ignored | ||
| ("2.0.1", ["v2.0.0", "notaversion", "latest", "v"], True), | ||
| # Pre-release ordering | ||
| ("2.0.0", ["v2.0.0rc1"], True), | ||
| ("2.0.0rc1", ["v2.0.0"], False), | ||
| ] | ||
|
|
||
| for candidate, tags, expected in test_cases: | ||
| result = is_newest(candidate, tags) | ||
| # Assert is expected in test functions | ||
| assert result == expected, ( # noqa: S101 | ||
| f"Expected {expected} but got {result} for {candidate} against {tags}" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_is_newest() | ||
| sys.exit(0) |
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,44 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: 2025-present Amazon.com, Inc. or its affiliates. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
|
|
||
| from latest_testing_version import latest_version | ||
|
|
||
|
|
||
| def test_latest_version(): | ||
| test_cases = [ | ||
| # Highest of several | ||
| (["v1.2.1", "v2.0.0", "v1.1.3", "latest"], "v2.0.0"), | ||
| # Single version | ||
| (["v1.0.0"], "v1.0.0"), | ||
| # Order does not matter | ||
| (["v2.0.0", "v1.0.0"], "v2.0.0"), | ||
| # Non-version and malformed tags ignored | ||
| (["v2.0.0", "latest", "notaversion", "v"], "v2.0.0"), | ||
| # No version tags | ||
| ([], ""), | ||
| (["latest"], ""), | ||
| # Pre-release orders below its release | ||
| (["v2.0.0rc1", "v2.0.0"], "v2.0.0"), | ||
| (["v2.0.0rc1"], "v2.0.0rc1"), | ||
| # Original tag text is preserved, not normalized | ||
| (["v2.0.0-beta"], "v2.0.0-beta"), | ||
| (["v1.0.0", "v2.0.0-beta"], "v2.0.0-beta"), | ||
| ] | ||
|
|
||
| for tags, expected in test_cases: | ||
| result = latest_version(tags) | ||
| # Assert is expected in test functions | ||
| assert result == expected, ( # noqa: S101 | ||
| f"Expected '{expected}' but got '{result}' for {tags}" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_latest_version() | ||
| sys.exit(0) |
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,48 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
|
|
||
| from parse_testing_version import parse_testing_version | ||
|
|
||
|
|
||
| def test_parse_testing_version(): | ||
| test_cases = [ | ||
| # Testing-only tag enables the job | ||
| ("testing-v2.0.0", "2.0.0"), | ||
| ("testing-v1.2.1", "1.2.1"), | ||
| # Combined comma-separated tags resolve to the testing version | ||
| ("sdk-v2.0.0,testing-v2.0.0", "2.0.0"), | ||
| ("testing-v2.0.0,sdk-v2.1.0", "2.0.0"), | ||
| ("otel-v1.0.0,testing-v1.2.1,sdk-v2.0.0", "1.2.1"), | ||
| # SDK-only or OTel-only tags do not enable the job | ||
| ("sdk-v2.1.0", ""), | ||
| ("otel-v1.0.0", ""), | ||
| ("sdk-v2.0.0,otel-v1.0.0", ""), | ||
| # Malformed or unrelated prefixes must not match | ||
| ("not-testing-v1.2.1", ""), | ||
| ("sdk-v2.0.0,mytesting-v1.2.1", ""), | ||
| ("testing-v1.2", ""), | ||
| ("testing-version-1.2.1", ""), | ||
| # No release tag | ||
| ("", ""), | ||
| ("v2.0.0", ""), | ||
| ("random-text", ""), | ||
| # Pre-release suffix is kept | ||
| ("testing-v2.0.0rc1", "2.0.0rc1"), | ||
| ("testing-v2.0.0-beta,sdk-v1.0.0", "2.0.0-beta"), | ||
| ] | ||
|
|
||
| for input_text, expected in test_cases: | ||
| result = parse_testing_version(input_text) | ||
| # Assert is expected in test functions | ||
| assert result == expected, ( # noqa: S101 | ||
| f"Expected '{expected}' but got '{result}' for input: {input_text}" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_parse_testing_version() | ||
| sys.exit(0) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex AI review · Finding
arf_v1_bn7u2dvrf6j45ju4qaataf7xkx[P2]
Version()accepts abbreviated PEP 440 values such as1and1.2, although this workflow only publishes versions with anX.Y.Zprefix. A stray registry tag such asv999is therefore selected as newest, causing attempts to use nonexistentv999-x86_64andv999-arm64images and blocking releases. Full-match the supported tag grammar before parsing, and add regression cases forv1andv1.2.