From 3de5a8727495dfe183e4cda1731d476d599118cd Mon Sep 17 00:00:00 2001 From: Leonardo Chaia Date: Tue, 26 Nov 2024 22:15:03 -0300 Subject: [PATCH 1/2] chore: adds CA2007 warning Signed-off-by: Leonardo Chaia --- .editorconfig | 5 ++++- src/OrasProject.Oras/Packer.cs | 18 +++++++++--------- .../Registry/Remote/BlobStore.cs | 5 +++-- .../OrasProject.Oras.Tests.csproj | 3 +++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.editorconfig b/.editorconfig index b4cda3b..8f63d53 100644 --- a/.editorconfig +++ b/.editorconfig @@ -50,4 +50,7 @@ dotnet_naming_symbols.public_members.applicable_kinds = property, field, method dotnet_naming_symbols.public_members.applicable_accessibilities = public dotnet_naming_symbols.public_members.required_modifiers = -dotnet_naming_style.public_uppercase_style.capitalization = pascal_case \ No newline at end of file +dotnet_naming_style.public_uppercase_style.capitalization = pascal_case + +# CA2007: Consider calling ConfigureAwait on the awaited task +dotnet_diagnostic.CA2007.severity = warning \ No newline at end of file diff --git a/src/OrasProject.Oras/Packer.cs b/src/OrasProject.Oras/Packer.cs index f4816c2..7b9e08a 100644 --- a/src/OrasProject.Oras/Packer.cs +++ b/src/OrasProject.Oras/Packer.cs @@ -108,9 +108,9 @@ public static async Task PackManifestAsync( switch (version) { case ManifestVersion.Version1_0: - return await PackManifestV1_0Async(pusher, artifactType, options, cancellationToken); + return await PackManifestV1_0Async(pusher, artifactType, options, cancellationToken).ConfigureAwait(false); case ManifestVersion.Version1_1: - return await PackManifestV1_1Async(pusher, artifactType, options, cancellationToken); + return await PackManifestV1_1Async(pusher, artifactType, options, cancellationToken).ConfigureAwait(false); default: throw new NotSupportedException($"ManifestVersion({version}) is not supported"); } @@ -146,7 +146,7 @@ private static async Task PackManifestV1_0Async(IPushable pusher, st artifactType = MediaTypeUnknownConfig; } ValidateMediaType(artifactType); - configDescriptor = await PushCustomEmptyConfigAsync(pusher, artifactType, options.ConfigAnnotations, cancellationToken); + configDescriptor = await PushCustomEmptyConfigAsync(pusher, artifactType, options.ConfigAnnotations, cancellationToken).ConfigureAwait(false); } var annotations = EnsureAnnotationCreated(options.ManifestAnnotations, "org.opencontainers.image.created"); @@ -159,7 +159,7 @@ private static async Task PackManifestV1_0Async(IPushable pusher, st Annotations = annotations }; - return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.Config.MediaType, manifest.Annotations, cancellationToken); + return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.Config.MediaType, manifest.Annotations, cancellationToken).ConfigureAwait(false); } /// @@ -192,7 +192,7 @@ private static async Task PackManifestV1_1Async(IPushable pusher, st configDescriptor = Descriptor.Empty; options.Config = configDescriptor; var configBytes = new byte[] { 0x7B, 0x7D }; - await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken); + await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken).ConfigureAwait(false); } if (options.Layers == null || options.Layers.Count == 0) @@ -215,7 +215,7 @@ private static async Task PackManifestV1_1Async(IPushable pusher, st Annotations = annotations }; - return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.ArtifactType, manifest.Annotations, cancellationToken); + return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.ArtifactType, manifest.Annotations, cancellationToken).ConfigureAwait(false); } /// @@ -235,7 +235,7 @@ private static async Task PushManifestAsync(IPushable pusher, object manifestDesc.ArtifactType = artifactType; manifestDesc.Annotations = annotations; - await pusher.PushAsync(manifestDesc, new MemoryStream(manifestJson), cancellationToken); + await pusher.PushAsync(manifestDesc, new MemoryStream(manifestJson), cancellationToken).ConfigureAwait(false); return manifestDesc; } @@ -266,7 +266,7 @@ private static async Task PushCustomEmptyConfigAsync(IPushable pushe var configDescriptor = Descriptor.Create(configBytes, mediaType); configDescriptor.Annotations = annotations; - await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken); + await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken).ConfigureAwait(false); return configDescriptor; } @@ -280,7 +280,7 @@ private static async Task PushCustomEmptyConfigAsync(IPushable pushe /// private static async Task PushIfNotExistAsync(IPushable pusher, Descriptor descriptor, byte[] data, CancellationToken cancellationToken = default) { - await pusher.PushAsync(descriptor, new MemoryStream(data), cancellationToken); + await pusher.PushAsync(descriptor, new MemoryStream(data), cancellationToken).ConfigureAwait(false); } /// diff --git a/src/OrasProject.Oras/Registry/Remote/BlobStore.cs b/src/OrasProject.Oras/Registry/Remote/BlobStore.cs index d5bba1b..389830a 100644 --- a/src/OrasProject.Oras/Registry/Remote/BlobStore.cs +++ b/src/OrasProject.Oras/Registry/Remote/BlobStore.cs @@ -148,7 +148,7 @@ public async Task PushAsync(Descriptor expected, Stream content, CancellationTok url = location.IsAbsoluteUri ? location : new Uri(url, location); } - await CompletePushAsync(url, expected, content, cancellationToken); + await CompletePushAsync(url, expected, content, cancellationToken).ConfigureAwait(false); } /// @@ -255,7 +255,8 @@ async Task GetContentStream() return stream; } - await using (var contents = await GetContentStream()) + var contents = await GetContentStream().ConfigureAwait(false); + await using (contents.ConfigureAwait(false)) { await CompletePushAsync(url, descriptor, contents, cancellationToken).ConfigureAwait(false); } diff --git a/tests/OrasProject.Oras.Tests/OrasProject.Oras.Tests.csproj b/tests/OrasProject.Oras.Tests/OrasProject.Oras.Tests.csproj index f71d4cd..d64eb09 100644 --- a/tests/OrasProject.Oras.Tests/OrasProject.Oras.Tests.csproj +++ b/tests/OrasProject.Oras.Tests/OrasProject.Oras.Tests.csproj @@ -6,6 +6,9 @@ enable false + + + CA2007 From 3cfffcae856380168a53a234ed5a36b7ff51da98 Mon Sep 17 00:00:00 2001 From: Leonardo Chaia Date: Wed, 27 Nov 2024 07:14:13 -0300 Subject: [PATCH 2/2] fix: adds newline Signed-off-by: Leonardo Chaia --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 8f63d53..cb3572c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -53,4 +53,4 @@ dotnet_naming_symbols.public_members.required_modifiers = dotnet_naming_style.public_uppercase_style.capitalization = pascal_case # CA2007: Consider calling ConfigureAwait on the awaited task -dotnet_diagnostic.CA2007.severity = warning \ No newline at end of file +dotnet_diagnostic.CA2007.severity = warning