Skip to content
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

fix: use correct icon url path in metadata publish #38247

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def log_metadata_upload_info(metadata_upload_info: MetadataUploadInfo):
for file in metadata_upload_info.uploaded_files:
if file.uploaded:
click.secho(
f"The {file.description} file for {metadata_upload_info.metadata_file_path} was uploaded to {file.blob_id}.", color="green"
f"The {file.description} file for {metadata_upload_info.metadata_file_path} was uploaded to {file.blob_id}.", fg="green"
)
else:
click.secho(
f"The {file.description} file for {metadata_upload_info.metadata_file_path} was not uploaded. Reason: {file.blob_id}",
fg="yellow",
)


Expand Down Expand Up @@ -53,10 +58,9 @@ def upload(metadata_file_path: pathlib.Path, docs_path: pathlib.Path, bucket_nam
upload_info = upload_metadata_to_gcs(bucket_name, metadata_file_path, validator_opts)
log_metadata_upload_info(upload_info)
except (ValidationError, FileNotFoundError) as e:
click.secho(f"The metadata file could not be uploaded: {str(e)}", color="red")
click.secho(f"The metadata file could not be uploaded: {str(e)}", fg="red")
exit(1)
if upload_info.metadata_uploaded:
exit(0)
else:
click.secho(f"The metadata file {metadata_file_path} was not uploaded.", color="yellow")
exit(5)
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ def _version_upload(metadata: ConnectorMetadataDefinitionV0, bucket: storage.buc
return upload_file_if_changed(metadata_file_path, bucket, version_path, disable_cache=True)


def _icon_upload(metadata: ConnectorMetadataDefinitionV0, bucket: storage.bucket.Bucket, metadata_file_path: Path) -> Tuple[bool, str]:
local_icon_path = metadata_file_path.parent / ICON_FILE_NAME
def _icon_upload(metadata: ConnectorMetadataDefinitionV0, bucket: storage.bucket.Bucket, icon_file_path: Path) -> Tuple[bool, str]:
latest_icon_path = get_icon_remote_file_path(metadata.data.dockerRepository, "latest")
if not local_icon_path.exists():
return False, f"No Icon found at {local_icon_path}"
return upload_file_if_changed(local_icon_path, bucket, latest_icon_path)
if not icon_file_path.exists():
return False, f"No Icon found at {icon_file_path}"
return upload_file_if_changed(icon_file_path, bucket, latest_icon_path)


def _doc_upload(
Expand Down Expand Up @@ -282,7 +281,7 @@ def upload_metadata_to_gcs(bucket_name: str, metadata_file_path: Path, validator
Returns:
Tuple[bool, str]: Whether the metadata file was uploaded and its blob id.
"""

icon_file_path = metadata_file_path.parent / ICON_FILE_NAME
metadata_file_path = _apply_modifications_to_metadata_file(metadata_file_path, validator_opts)

metadata, error = validate_and_load(metadata_file_path, POST_UPLOAD_VALIDATORS, validator_opts)
Expand All @@ -299,7 +298,7 @@ def upload_metadata_to_gcs(bucket_name: str, metadata_file_path: Path, validator
bucket = storage_client.bucket(bucket_name)
docs_path = Path(validator_opts.docs_path)

icon_uploaded, icon_blob_id = _icon_upload(metadata, bucket, metadata_file_path)
icon_uploaded, icon_blob_id = _icon_upload(metadata, bucket, icon_file_path)

version_uploaded, version_blob_id = _version_upload(metadata, bucket, metadata_file_path)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metadata-service"
version = "0.7.0"
version = "0.7.1"
description = ""
authors = ["Ben Church <ben@airbyte.io>"]
readme = "README.md"
Expand Down
49 changes: 36 additions & 13 deletions airbyte-ci/connectors/metadata_service/lib/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,47 +160,70 @@ def test_upload(

if latest_uploaded:
commands.click.secho.assert_has_calls(
[mocker.call(f"The latest metadata file for {metadata_file_path} was uploaded to latest_blob_id.", color="green")]
[mocker.call(f"The latest metadata file for {metadata_file_path} was uploaded to latest_blob_id.", fg="green")]
)
assert result.exit_code == 0
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The latest metadata file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if version_uploaded:
commands.click.secho.assert_has_calls(
[mocker.call(f"The versioned metadata file for {metadata_file_path} was uploaded to version_blob_id.", color="green")]
[mocker.call(f"The versioned metadata file for {metadata_file_path} was uploaded to version_blob_id.", fg="green")]
)
assert result.exit_code == 0
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The versioned metadata file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if icon_uploaded:
commands.click.secho.assert_has_calls(
[mocker.call(f"The icon file for {metadata_file_path} was uploaded to icon_blob_id.", color="green")]
[mocker.call(f"The icon file for {metadata_file_path} was uploaded to icon_blob_id.", fg="green")]
)
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The icon file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if doc_version_uploaded:
commands.click.secho.assert_has_calls(
[mocker.call(f"The versioned doc file for {metadata_file_path} was uploaded to doc_version_blob_id.", color="green")]
[mocker.call(f"The versioned doc file for {metadata_file_path} was uploaded to doc_version_blob_id.", fg="green")]
)
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The versioned doc file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if doc_inapp_version_uploaded:
commands.click.secho.assert_has_calls(
[
mocker.call(
f"The versioned inapp doc file for {metadata_file_path} was uploaded to doc_inapp_version_blob_id.", color="green"
)
]
[mocker.call(f"The versioned inapp doc file for {metadata_file_path} was uploaded to doc_inapp_version_blob_id.", fg="green")]
)
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The versioned inapp doc file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if doc_latest_uploaded:
commands.click.secho.assert_has_calls(
[mocker.call(f"The latest doc file for {metadata_file_path} was uploaded to doc_latest_blob_id.", color="green")]
[mocker.call(f"The latest doc file for {metadata_file_path} was uploaded to doc_latest_blob_id.", fg="green")]
)
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The latest doc file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if doc_inapp_latest_uploaded:
commands.click.secho.assert_has_calls(
[mocker.call(f"The latest inapp doc file for {metadata_file_path} was uploaded to doc_inapp_latest_blob_id.", color="green")]
[mocker.call(f"The latest inapp doc file for {metadata_file_path} was uploaded to doc_inapp_latest_blob_id.", fg="green")]
)
else:
commands.click.secho.assert_has_calls(
[mocker.call(f"The latest inapp doc file for {metadata_file_path} was not uploaded. Reason: None", fg="yellow")]
)

if not (latest_uploaded or version_uploaded):
commands.click.secho.assert_has_calls([mocker.call(f"The metadata file {metadata_file_path} was not uploaded.", color="yellow")])
# We exit with 5 status code to share with the CI pipeline that the upload was skipped.
assert result.exit_code == 5

Expand Down Expand Up @@ -243,4 +266,4 @@ def test_upload_with_errors(mocker, valid_metadata_yaml_files, tmp_path, error,
) # Using valid_metadata_yaml_files[0] as SA because it exists...
assert result.exit_code == 1
if handled:
commands.click.secho.assert_called_with(f"The metadata file could not be uploaded: {str(error)}", color="red")
commands.click.secho.assert_called_with(f"The metadata file could not be uploaded: {str(error)}", fg="red")
Loading