From a74a26ed410c78b9bf01253cb314df3580f51836 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 21 Jun 2024 13:54:42 +0200 Subject: [PATCH] #37: Add support for semver in AVPRClient --- src/AVPRClient/AVPRClient.cs | 36 +++++++ src/AVPRClient/AVPRClient.csproj | 4 +- src/AVPRClient/Extensions.cs | 14 ++- src/AVPRClient/RELEASE_NOTES.md | 3 + tests/ClientTests/ReferenceObjects.fs | 95 +++++++++++++++++-- tests/ClientTests/TypeExtensionsTests.fs | 49 +++++++--- ...elds.fsx => allFields_cqcHookAddition.fsx} | 0 .../fixtures/allFields_semVerAddition.fsx | 26 +++++ 8 files changed, 198 insertions(+), 29 deletions(-) rename tests/ClientTests/fixtures/{test_validation_package_all_fields.fsx => allFields_cqcHookAddition.fsx} (100%) create mode 100644 tests/ClientTests/fixtures/allFields_semVerAddition.fsx diff --git a/src/AVPRClient/AVPRClient.cs b/src/AVPRClient/AVPRClient.cs index 554ab91..aa2c7bf 100644 --- a/src/AVPRClient/AVPRClient.cs +++ b/src/AVPRClient/AVPRClient.cs @@ -1070,6 +1070,18 @@ public partial class ValidationPackage [Newtonsoft.Json.JsonProperty("PatchVersion", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public int PatchVersion { get; set; } + /// + /// SemVer prerelease version of the validationpackage. + /// + [Newtonsoft.Json.JsonProperty("PreReleaseVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PreReleaseVersionSuffix { get; set; } + + /// + /// SemVer buildmetadata of the validationpackage. + /// + [Newtonsoft.Json.JsonProperty("BuildMetadataVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string BuildMetadataVersionSuffix { get; set; } + /// /// base64 encoded binary content of the validation package. /// @@ -1155,6 +1167,18 @@ public partial class PackageContentHash [Newtonsoft.Json.JsonProperty("PackagePatchVersion", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public int PackagePatchVersion { get; set; } + /// + /// SemVer prerelease version of the validationpackage. + /// + [Newtonsoft.Json.JsonProperty("PackagePreReleaseVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PackagePreReleaseVersionSuffix { get; set; } + + /// + /// SemVer buildmetadata of the validationpackage. + /// + [Newtonsoft.Json.JsonProperty("PackageBuildMetadataVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PackageBuildMetadataVersionSuffix { get; set; } + /// /// MD5 hash hex string of the package content. /// @@ -1190,6 +1214,18 @@ public partial class PackageDownloads [Newtonsoft.Json.JsonProperty("PackagePatchVersion", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public int PackagePatchVersion { get; set; } + /// + /// SemVer prerelease version of the validationpackage. + /// + [Newtonsoft.Json.JsonProperty("PackagePreReleaseVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PackagePreReleaseVersionSuffix { get; set; } + + /// + /// SemVer buildmetadata of the validationpackage. + /// + [Newtonsoft.Json.JsonProperty("PackageBuildMetadataVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PackageBuildMetadataVersionSuffix { get; set; } + /// /// Number of downloads for the package. /// diff --git a/src/AVPRClient/AVPRClient.csproj b/src/AVPRClient/AVPRClient.csproj index 872ad7a..5d09d2d 100644 --- a/src/AVPRClient/AVPRClient.csproj +++ b/src/AVPRClient/AVPRClient.csproj @@ -22,13 +22,13 @@ git $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md")) README.md - 0.0.9 + 0.1.0 - + diff --git a/src/AVPRClient/Extensions.cs b/src/AVPRClient/Extensions.cs index 8bffa8e..e8a1b03 100644 --- a/src/AVPRClient/Extensions.cs +++ b/src/AVPRClient/Extensions.cs @@ -26,6 +26,8 @@ DateTimeOffset releaseDate MajorVersion = indexedPackage.Metadata.MajorVersion, MinorVersion = indexedPackage.Metadata.MinorVersion, PatchVersion = indexedPackage.Metadata.PatchVersion, + PreReleaseVersionSuffix = indexedPackage.Metadata.PreReleaseVersionSuffix, + BuildMetadataVersionSuffix = indexedPackage.Metadata.BuildMetadataVersionSuffix, PackageContent = BinaryContent.fromFile(indexedPackage.RepoPath), ReleaseDate = releaseDate, Tags = @@ -78,7 +80,9 @@ public static AVPRClient.PackageContentHash toPackageContentHash( Hash = Hash.hashFile(indexedPackage.RepoPath), PackageMajorVersion = indexedPackage.Metadata.MajorVersion, PackageMinorVersion = indexedPackage.Metadata.MinorVersion, - PackagePatchVersion = indexedPackage.Metadata.PatchVersion + PackagePatchVersion = indexedPackage.Metadata.PatchVersion, + PackagePreReleaseVersionSuffix = indexedPackage.Metadata.PreReleaseVersionSuffix, + PackageBuildMetadataVersionSuffix = indexedPackage.Metadata.BuildMetadataVersionSuffix }; } else @@ -89,7 +93,9 @@ public static AVPRClient.PackageContentHash toPackageContentHash( Hash = indexedPackage.ContentHash, PackageMajorVersion = indexedPackage.Metadata.MajorVersion, PackageMinorVersion = indexedPackage.Metadata.MinorVersion, - PackagePatchVersion = indexedPackage.Metadata.PatchVersion + PackagePatchVersion = indexedPackage.Metadata.PatchVersion, + PackagePreReleaseVersionSuffix = indexedPackage.Metadata.PreReleaseVersionSuffix, + PackageBuildMetadataVersionSuffix = indexedPackage.Metadata.BuildMetadataVersionSuffix }; } } @@ -149,8 +155,8 @@ this AVPRClient.ValidationPackage validationPackage majorVersion: validationPackage.MajorVersion, minorVersion: validationPackage.MinorVersion, patchVersion: validationPackage.PatchVersion, - PreReleaseVersionSuffix: Microsoft.FSharp.Core.FSharpOption.None, - BuildMetadataVersionSuffix: Microsoft.FSharp.Core.FSharpOption.None, + PreReleaseVersionSuffix: validationPackage.PreReleaseVersionSuffix, + BuildMetadataVersionSuffix: validationPackage.BuildMetadataVersionSuffix, Publish: Microsoft.FSharp.Core.FSharpOption.None, Authors: validationPackage.Authors.AsIndexType(), Tags: validationPackage.Tags.AsIndexType(), diff --git a/src/AVPRClient/RELEASE_NOTES.md b/src/AVPRClient/RELEASE_NOTES.md index 7ea560a..19ceb23 100644 --- a/src/AVPRClient/RELEASE_NOTES.md +++ b/src/AVPRClient/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +## v0.1.0 +- Regen client for full semVer support (AVPRIndex >= 0.2.0) + ## v0.0.9 - Use AVPRIndex for all package binary content extractions diff --git a/tests/ClientTests/ReferenceObjects.fs b/tests/ClientTests/ReferenceObjects.fs index 1277dc4..9c2ea2e 100644 --- a/tests/ClientTests/ReferenceObjects.fs +++ b/tests/ClientTests/ReferenceObjects.fs @@ -59,7 +59,7 @@ module ValidationPackageMetadata = PatchVersion = 0 ) - let allFields = ValidationPackageMetadata( + let allFields_cqcHookAddition = ValidationPackageMetadata( Name = "name", Summary = "summary" , Description = "description" , @@ -73,23 +73,53 @@ module ValidationPackageMetadata = CQCHookEndpoint = "hookendpoint" ) + let allFields_semVerAddition = ValidationPackageMetadata( + Name = "name", + Summary = "summary" , + Description = "description" , + MajorVersion = 1, + MinorVersion = 0, + PatchVersion = 0, + PreReleaseVersionSuffix = "use", + BuildMetadataVersionSuffix = "suffixes", + Publish = true, + Authors = [|Author.allFieldsIndex|], + Tags = [|OntologyAnnotation.allFieldsIndex|], + ReleaseNotes = "releasenotes", + CQCHookEndpoint = "hookendpoint" + ) + module Hash = - let expected_hash = "C5BD4262301D27CF667106D9024BD721" + let expected_hash_cqcHookAddition = "C5BD4262301D27CF667106D9024BD721" + + let allFields_cqcHookAddition = AVPRClient.PackageContentHash( + PackageName = "name", + PackageMajorVersion = 1, + PackageMinorVersion = 0, + PackagePatchVersion = 0, + PackagePreReleaseVersionSuffix = "", + PackageBuildMetadataVersionSuffix = "", + Hash = expected_hash_cqcHookAddition + ) + + let expected_hash_semVerAddition = "2A546201341641AAB21FB49DADD06676" - let allFields = AVPRClient.PackageContentHash( + let allFields_semVerAddition = AVPRClient.PackageContentHash( PackageName = "name", PackageMajorVersion = 1, PackageMinorVersion = 0, PackagePatchVersion = 0, - Hash = expected_hash + PackagePreReleaseVersionSuffix = "use", + PackageBuildMetadataVersionSuffix = "suffixes", + Hash = expected_hash_semVerAddition ) module BinaryContent = open System.IO - let expected_content = "(* + let expected_content_cqcHookAddition = "(* --- Name: name Summary: summary @@ -112,23 +142,70 @@ CQCHookEndpoint: hookendpoint --- *) -printfn \"yes\"" .ReplaceLineEndings("\n") +printfn \"yes\"" .ReplaceLineEndings("\n") + + let expected_binary_content_cqcHookAddition = expected_content_cqcHookAddition |> System.Text.Encoding.UTF8.GetBytes + + let expected_content_semVerAddition = "(* +--- +Name: name +Summary: summary +Description = description +MajorVersion: 1 +MinorVersion: 0 +PatchVersion: 0 +PreRelease: use +BuildMetadata: suffixes +Publish: true +Authors: + - FullName: test + Email: test@test.test + Affiliation: testaffiliation + AffiliationLink: test.com +Tags: + - Name: test + TermSourceREF: REF + TermAccessionNumber: TAN +ReleaseNotes: releasenotes +CQCHookEndpoint: hookendpoint +--- +*) - let expected_binary_content = expected_content |> System.Text.Encoding.UTF8.GetBytes +printfn \"yes\"" .ReplaceLineEndings("\n") + let expected_binary_content_semVerAddition = expected_content_semVerAddition |> System.Text.Encoding.UTF8.GetBytes module ValidationPackage = open System.IO - let allFields = AVPRClient.ValidationPackage( + let allFields_cqcHookAddition = AVPRClient.ValidationPackage( + Name = "name", + Summary = "summary" , + Description = "description" , + MajorVersion = 1, + MinorVersion = 0, + PatchVersion = 0, + PreReleaseVersionSuffix = "", + BuildMetadataVersionSuffix = "", + PackageContent = BinaryContent.expected_binary_content_cqcHookAddition, + ReleaseDate = date, + Authors = [|Author.allFieldsClient|], + Tags = [|OntologyAnnotation.allFieldsClient|], + ReleaseNotes = "releasenotes", + CQCHookEndpoint = "hookendpoint" + ) + + let allFields_semVerAddition = AVPRClient.ValidationPackage( Name = "name", Summary = "summary" , Description = "description" , MajorVersion = 1, MinorVersion = 0, PatchVersion = 0, - PackageContent = BinaryContent.expected_binary_content, + PreReleaseVersionSuffix = "use", + BuildMetadataVersionSuffix = "suffixes", + PackageContent = BinaryContent.expected_binary_content_semVerAddition, ReleaseDate = date, Authors = [|Author.allFieldsClient|], Tags = [|OntologyAnnotation.allFieldsClient|], diff --git a/tests/ClientTests/TypeExtensionsTests.fs b/tests/ClientTests/TypeExtensionsTests.fs index af1ee52..7f1bd44 100644 --- a/tests/ClientTests/TypeExtensionsTests.fs +++ b/tests/ClientTests/TypeExtensionsTests.fs @@ -10,30 +10,51 @@ open System.Security.Cryptography module ValidationPackageIndex = - let test_validation_package_all_fields = AVPRIndex.Domain.ValidationPackageIndex.create( - repoPath = "fixtures/test_validation_package_all_fields.fsx", - fileName = "test_validation_package_all_fields.fsx", + let allFields_cqcHookAddition = AVPRIndex.Domain.ValidationPackageIndex.create( + repoPath = "fixtures/allFields_cqcHookAddition.fsx", + fileName = "allFields_cqcHookAddition.fsx", lastUpdated = ReferenceObjects.date, - contentHash = ReferenceObjects.Hash.expected_hash, - metadata = ReferenceObjects.ValidationPackageMetadata.allFields + contentHash = ReferenceObjects.Hash.expected_hash_cqcHookAddition, + metadata = ReferenceObjects.ValidationPackageMetadata.allFields_cqcHookAddition ) [] - let ``toValidationPackage with release date`` () = - let actual = test_validation_package_all_fields.toValidationPackage(ReferenceObjects.date) - Assert.Equivalent(actual, ReferenceObjects.ValidationPackage.allFields) + let ``CQCHook Addition - toValidationPackage with release date`` () = + let actual = allFields_cqcHookAddition.toValidationPackage(ReferenceObjects.date) + Assert.Equivalent(actual, ReferenceObjects.ValidationPackage.allFields_cqcHookAddition) + [] + let ``CQCHook Addition - toPackageContentHash without direct file hash`` () = + let actual = allFields_cqcHookAddition.toPackageContentHash() + Assert.Equivalent(ReferenceObjects.Hash.allFields_cqcHookAddition, actual) + + [] + let ``CQCHook Addition - toPackageContentHash with direct file hash`` () = + let actual = allFields_cqcHookAddition.toPackageContentHash(HashFileDirectly = true) + Assert.Equivalent(ReferenceObjects.Hash.allFields_cqcHookAddition, actual) + let allFields_semVerAddition = AVPRIndex.Domain.ValidationPackageIndex.create( + repoPath = "fixtures/allFields_semVerAddition.fsx", + fileName = "allFields_semVerAddition.fsx", + lastUpdated = ReferenceObjects.date, + contentHash = ReferenceObjects.Hash.expected_hash_semVerAddition, + metadata = ReferenceObjects.ValidationPackageMetadata.allFields_semVerAddition + ) + + [] + let ``SemVer Addition - toValidationPackage with release date`` () = + let actual = allFields_semVerAddition.toValidationPackage(ReferenceObjects.date) + Assert.Equivalent(actual, ReferenceObjects.ValidationPackage.allFields_semVerAddition) [] - let ``toPackageContentHash without direct file hash`` () = - let actual = test_validation_package_all_fields.toPackageContentHash() - Assert.Equivalent(ReferenceObjects.Hash.allFields, actual) + let ``SemVer Addition - toPackageContentHash without direct file hash`` () = + let actual = allFields_semVerAddition.toPackageContentHash() + Assert.Equivalent(ReferenceObjects.Hash.allFields_semVerAddition, actual) [] - let ``toPackageContentHash with direct file hash`` () = - let actual = test_validation_package_all_fields.toPackageContentHash(HashFileDirectly = true) - Assert.Equivalent(ReferenceObjects.Hash.allFields, actual) + let ``SemVer Addition - toPackageContentHash with direct file hash`` () = + let actual = allFields_semVerAddition.toPackageContentHash(HashFileDirectly = true) + Assert.Equivalent(ReferenceObjects.Hash.allFields_semVerAddition, actual) module Author = diff --git a/tests/ClientTests/fixtures/test_validation_package_all_fields.fsx b/tests/ClientTests/fixtures/allFields_cqcHookAddition.fsx similarity index 100% rename from tests/ClientTests/fixtures/test_validation_package_all_fields.fsx rename to tests/ClientTests/fixtures/allFields_cqcHookAddition.fsx diff --git a/tests/ClientTests/fixtures/allFields_semVerAddition.fsx b/tests/ClientTests/fixtures/allFields_semVerAddition.fsx new file mode 100644 index 0000000..f2c73ca --- /dev/null +++ b/tests/ClientTests/fixtures/allFields_semVerAddition.fsx @@ -0,0 +1,26 @@ +(* +--- +Name: name +Summary: summary +Description = description +MajorVersion: 1 +MinorVersion: 0 +PatchVersion: 0 +PreRelease: use +BuildMetadata: suffixes +Publish: true +Authors: + - FullName: test + Email: test@test.test + Affiliation: testaffiliation + AffiliationLink: test.com +Tags: + - Name: test + TermSourceREF: REF + TermAccessionNumber: TAN +ReleaseNotes: releasenotes +CQCHookEndpoint: hookendpoint +--- +*) + +printfn "yes" \ No newline at end of file