-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Extract and send tooling versions to Sentry (EME-606) #464
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
runningcode
wants to merge
10
commits into
main
Choose a base branch
from
no/eme-606-extract-and-send-tooling-versions
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
f12c060
feat: Extract and send tooling versions to Sentry (EME-606)
runningcode 47a4a6a
refactor: Move metadata extraction to analyzers (EME-606)
runningcode 5998900
refactor: Remove redundant comments (EME-606)
runningcode 4b10d48
refactor: Rename fastlane_version to fastlane_plugin_version (EME-606)
runningcode 0cfd711
refactor: Update metadata keys to use -version suffix (EME-606)
runningcode 8bb5f86
refactor: Remove duplicate tooling metadata extraction (EME-606)
runningcode 0a59a68
refactor: Only look for metadata file in zip root (EME-606)
runningcode acb6caa
refactor: Remove redundant docstrings from metadata_extractor (EME-606)
runningcode 3b2c2d5
fix: Apply ruff formatting to metadata_extractor (EME-606)
runningcode 76cdd8e
Move tooling versions out of UpdateData and to respective Android/App…
runningcode 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -442,12 +442,16 @@ def _get_artifact_type(artifact: Artifact) -> ArtifactType: | |
| certificate_expiration_date=app_info.certificate_expiration_date, | ||
| missing_dsym_binaries=app_info.missing_dsym_binaries, | ||
| build_date=app_info.build_date, | ||
| cli_version=app_info.cli_version, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| fastlane_plugin_version=app_info.fastlane_plugin_version, | ||
| ) | ||
|
|
||
| android_app_info = None | ||
| if isinstance(app_info, AndroidAppInfo): | ||
| android_app_info = AndroidAppInfoModel( | ||
| has_proguard_mapping=app_info.has_proguard_mapping, | ||
| cli_version=app_info.cli_version, | ||
| gradle_plugin_version=app_info.gradle_plugin_version, | ||
| ) | ||
|
|
||
| update_data = UpdateData( | ||
|
|
||
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
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,67 @@ | ||
| import zipfile | ||
|
|
||
| from pathlib import Path | ||
| from typing import Dict, Optional | ||
|
|
||
| from launchpad.utils.logging import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
| METADATA_FILENAME = ".sentry-cli-metadata.txt" | ||
|
|
||
|
|
||
| class ToolingMetadata: | ||
| def __init__( | ||
| self, | ||
| cli_version: Optional[str] = None, | ||
| fastlane_plugin_version: Optional[str] = None, | ||
| gradle_plugin_version: Optional[str] = None, | ||
| ): | ||
| self.cli_version = cli_version | ||
| self.fastlane_plugin_version = fastlane_plugin_version | ||
| self.gradle_plugin_version = gradle_plugin_version | ||
|
|
||
|
|
||
| def extract_metadata_from_zip(zip_path: Path) -> ToolingMetadata: | ||
| try: | ||
| with zipfile.ZipFile(zip_path, "r") as zf: | ||
| # Only look for .sentry-cli-metadata.txt in the root of the zip | ||
| if METADATA_FILENAME not in zf.namelist(): | ||
| logger.debug(f"No {METADATA_FILENAME} found in root of {zip_path}") | ||
| return ToolingMetadata() | ||
|
|
||
| logger.debug(f"Found metadata file: {METADATA_FILENAME}") | ||
|
|
||
| with zf.open(METADATA_FILENAME) as f: | ||
| content = f.read().decode("utf-8") | ||
| return _parse_metadata_content(content) | ||
|
|
||
| except Exception as e: | ||
| logger.warning(f"Failed to extract metadata from {zip_path}: {e}") | ||
| return ToolingMetadata() | ||
|
|
||
|
|
||
| def _parse_metadata_content(content: str) -> ToolingMetadata: | ||
| """Expected format: | ||
| sentry-cli-version: 2.58.2 | ||
| sentry-fastlane-plugin: 1.2.3 | ||
| sentry-gradle-plugin: 4.12.0 | ||
| """ | ||
| metadata: Dict[str, str] = {} | ||
|
|
||
| for line in content.strip().split("\n"): | ||
| line = line.strip() | ||
| if not line or ":" not in line: | ||
| continue | ||
|
|
||
| key, value = line.split(":", 1) | ||
| key = key.strip() | ||
| value = value.strip() | ||
|
|
||
| metadata[key] = value | ||
|
|
||
| return ToolingMetadata( | ||
| cli_version=metadata.get("sentry-cli-version"), | ||
| fastlane_plugin_version=metadata.get("sentry-fastlane-plugin"), | ||
| gradle_plugin_version=metadata.get("sentry-gradle-plugin"), | ||
| ) |
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,69 @@ | ||
| import tempfile | ||
| import zipfile | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from launchpad.utils.metadata_extractor import ( | ||
| ToolingMetadata, | ||
| _parse_metadata_content, | ||
| extract_metadata_from_zip, | ||
| ) | ||
|
|
||
|
|
||
| class TestParseMetadataContent: | ||
| def test_parse_all_fields(self): | ||
| content = """sentry-cli-version: 2.58.2 | ||
| sentry-fastlane-plugin: 1.2.3 | ||
| sentry-gradle-plugin: 4.12.0""" | ||
| metadata = _parse_metadata_content(content) | ||
| assert metadata.cli_version == "2.58.2" | ||
| assert metadata.fastlane_plugin_version == "1.2.3" | ||
| assert metadata.gradle_plugin_version == "4.12.0" | ||
|
|
||
| def test_parse_empty_content(self): | ||
| content = "" | ||
| metadata = _parse_metadata_content(content) | ||
| assert metadata.cli_version is None | ||
| assert metadata.fastlane_plugin_version is None | ||
| assert metadata.gradle_plugin_version is None | ||
|
|
||
|
|
||
| class TestExtractMetadataFromZip: | ||
| def test_extract_from_zip_root(self): | ||
| with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as tf: | ||
| try: | ||
| with zipfile.ZipFile(tf.name, "w") as zf: | ||
| zf.writestr( | ||
| ".sentry-cli-metadata.txt", | ||
| "sentry-cli-version: 2.58.2\nsentry-fastlane-plugin: 1.2.3\nsentry-gradle-plugin: 4.12.0", | ||
| ) | ||
| zf.writestr("some-file.txt", "content") | ||
|
|
||
| metadata = extract_metadata_from_zip(Path(tf.name)) | ||
| assert metadata.cli_version == "2.58.2" | ||
| assert metadata.fastlane_plugin_version == "1.2.3" | ||
| assert metadata.gradle_plugin_version == "4.12.0" | ||
| finally: | ||
| Path(tf.name).unlink() | ||
|
|
||
| def test_extract_when_missing(self): | ||
| with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as tf: | ||
| try: | ||
| with zipfile.ZipFile(tf.name, "w") as zf: | ||
| zf.writestr("some-file.txt", "content") | ||
| zf.writestr("other-file.txt", "content") | ||
|
|
||
| metadata = extract_metadata_from_zip(Path(tf.name)) | ||
| assert metadata.cli_version is None | ||
| assert metadata.fastlane_plugin_version is None | ||
| assert metadata.gradle_plugin_version is None | ||
| finally: | ||
| Path(tf.name).unlink() | ||
|
|
||
|
|
||
| class TestToolingMetadata: | ||
| def test_create_with_defaults(self): | ||
| metadata = ToolingMetadata() | ||
| assert metadata.cli_version is None | ||
| assert metadata.fastlane_plugin_version is None | ||
| assert metadata.gradle_plugin_version is None |
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.
Added this base class to reduce duplication of the
cli_version. Can remove if it seems redundant.