Skip to content

Commit

Permalink
#37: Add support for semver in AVPRClient
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jun 21, 2024
1 parent 744d729 commit a74a26e
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 29 deletions.
36 changes: 36 additions & 0 deletions src/AVPRClient/AVPRClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// SemVer prerelease version of the validationpackage.
/// </summary>
[Newtonsoft.Json.JsonProperty("PreReleaseVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string PreReleaseVersionSuffix { get; set; }

/// <summary>
/// SemVer buildmetadata of the validationpackage.
/// </summary>
[Newtonsoft.Json.JsonProperty("BuildMetadataVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string BuildMetadataVersionSuffix { get; set; }

/// <summary>
/// base64 encoded binary content of the validation package.
/// </summary>
Expand Down Expand Up @@ -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; }

/// <summary>
/// SemVer prerelease version of the validationpackage.
/// </summary>
[Newtonsoft.Json.JsonProperty("PackagePreReleaseVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string PackagePreReleaseVersionSuffix { get; set; }

/// <summary>
/// SemVer buildmetadata of the validationpackage.
/// </summary>
[Newtonsoft.Json.JsonProperty("PackageBuildMetadataVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string PackageBuildMetadataVersionSuffix { get; set; }

/// <summary>
/// MD5 hash hex string of the package content.
/// </summary>
Expand Down Expand Up @@ -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; }

/// <summary>
/// SemVer prerelease version of the validationpackage.
/// </summary>
[Newtonsoft.Json.JsonProperty("PackagePreReleaseVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string PackagePreReleaseVersionSuffix { get; set; }

/// <summary>
/// SemVer buildmetadata of the validationpackage.
/// </summary>
[Newtonsoft.Json.JsonProperty("PackageBuildMetadataVersionSuffix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string PackageBuildMetadataVersionSuffix { get; set; }

/// <summary>
/// Number of downloads for the package.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/AVPRClient/AVPRClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md"))</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>0.0.9</PackageVersion>
<PackageVersion>0.1.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<None Include="README.md" Pack="true" PackagePath="\" />
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" PackageVersion="[0.1.3, 1.0.0)" />
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" PackageVersion="[0.2.0, 1.0.0)" />
</ItemGroup>

<Target Name="UseExplicitPackageVersions" BeforeTargets="GenerateNuspec">
Expand Down
14 changes: 10 additions & 4 deletions src/AVPRClient/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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
};
}
}
Expand Down Expand Up @@ -149,8 +155,8 @@ this AVPRClient.ValidationPackage validationPackage
majorVersion: validationPackage.MajorVersion,
minorVersion: validationPackage.MinorVersion,
patchVersion: validationPackage.PatchVersion,
PreReleaseVersionSuffix: Microsoft.FSharp.Core.FSharpOption<string>.None,
BuildMetadataVersionSuffix: Microsoft.FSharp.Core.FSharpOption<string>.None,
PreReleaseVersionSuffix: validationPackage.PreReleaseVersionSuffix,
BuildMetadataVersionSuffix: validationPackage.BuildMetadataVersionSuffix,
Publish: Microsoft.FSharp.Core.FSharpOption<bool>.None,
Authors: validationPackage.Authors.AsIndexType(),
Tags: validationPackage.Tags.AsIndexType(),
Expand Down
3 changes: 3 additions & 0 deletions src/AVPRClient/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
95 changes: 86 additions & 9 deletions tests/ClientTests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module ValidationPackageMetadata =
PatchVersion = 0
)

let allFields = ValidationPackageMetadata(
let allFields_cqcHookAddition = ValidationPackageMetadata(
Name = "name",
Summary = "summary" ,
Description = "description" ,
Expand All @@ -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
Expand All @@ -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: [email protected]
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|],
Expand Down
49 changes: 35 additions & 14 deletions tests/ClientTests/TypeExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

[<Fact>]
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)

[<Fact>]
let ``CQCHook Addition - toPackageContentHash without direct file hash`` () =
let actual = allFields_cqcHookAddition.toPackageContentHash()
Assert.Equivalent(ReferenceObjects.Hash.allFields_cqcHookAddition, actual)

[<Fact>]
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
)

[<Fact>]
let ``SemVer Addition - toValidationPackage with release date`` () =
let actual = allFields_semVerAddition.toValidationPackage(ReferenceObjects.date)
Assert.Equivalent(actual, ReferenceObjects.ValidationPackage.allFields_semVerAddition)

[<Fact>]
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)

[<Fact>]
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 =

Expand Down
26 changes: 26 additions & 0 deletions tests/ClientTests/fixtures/allFields_semVerAddition.fsx
Original file line number Diff line number Diff line change
@@ -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: [email protected]
Affiliation: testaffiliation
AffiliationLink: test.com
Tags:
- Name: test
TermSourceREF: REF
TermAccessionNumber: TAN
ReleaseNotes: releasenotes
CQCHookEndpoint: hookendpoint
---
*)

printfn "yes"

0 comments on commit a74a26e

Please sign in to comment.