Skip to content

Commit

Permalink
Implement full semantic version support for the consuming libraries a…
Browse files Browse the repository at this point in the history
…nd CLI tool

- `ARCValidationPackages`:
  - fix various bugs using incorrect filenames without any semver part
  - add various tests
  - PackageCache now only returns stable packages for `latest`

- `ARCExpect`
  - include semver in default badge label
  - use full semver `2.0.0-draft` for existing specification validation package

- `arc-validate`:
  - added a diagnostic print including package source and full version string on install
  - added tests for multiple test packages
  • Loading branch information
kMutagene committed Jun 25, 2024
1 parent 9d19617 commit 92e54fe
Show file tree
Hide file tree
Showing 28 changed files with 1,393 additions and 204 deletions.
23 changes: 0 additions & 23 deletions .arc-validate-results/arc_specification@2.0.0/badge.svg

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/ARCExpect/ARCExpect.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
<PackageReference Include="OBO.NET" Version="[0.4.2]" />
<PackageReference Include="AnyBadge.NET" Version="[2.0.0]" />
<PackageReference Include="FSharp.SystemTextJson" Version="[1.3.13]" />
<PackageReference Include="AVPRIndex" Version="[0.1.3]" />
<PackageReference Include="AVPRIndex" Version="[0.2.1]" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/ARCExpect/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 4.0.0 - (Released 2024-06-21)

- Support full semantic versions for ValidationPackageMetadata in the `ARCExpect` API.

- Use SemVer prerelease suffix for `arc_specification @2.0.0-draft_`

### 3.0.1 - (Released 2024-04-30)

Update pinned dependencies
Expand Down
3 changes: 2 additions & 1 deletion src/ARCExpect/SpecificationValidation/V2_0_0_Draft.fs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ module V2_0_0_Draft =
description = "Validate whether an ARC conforms to Specification V2.0.0-draft. See the relevant spec at https://github.com/nfdi4plants/ARC-specification/blob/v2.0.0/ARC%20specification.md",
majorVersion = 2,
minorVersion = 0,
patchVersion = 0
patchVersion = 0,
PreReleaseVersionSuffix = "draft"
),
CriticalValidationCasesList = cases
)
2 changes: 1 addition & 1 deletion src/ARCExpect/TopLevelAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Execute =
) =
fun (arcValidationPackage: ARCValidationPackage) ->

let labelText = defaultArg BadgeLabelText arcValidationPackage.Metadata.Name
let labelText = defaultArg BadgeLabelText $"{arcValidationPackage.Metadata.Name}@{ValidationPackageMetadata.getSemanticVersionString arcValidationPackage.Metadata}"

let foldername = $"{arcValidationPackage.Metadata.Name}@{ValidationPackageMetadata.getSemanticVersionString arcValidationPackage.Metadata}"

Expand Down
4 changes: 2 additions & 2 deletions src/ARCValidationPackages/ARCValidationPackages.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<ItemGroup>
<PackageReference Include="Fake.DotNet.Cli" Version="[6.0.0]" />
<PackageReference Include="FsHttp" Version="[14.5.0]" />
<PackageReference Include="AVPRIndex" Version="[0.1.3]" />
<PackageReference Include="AVPRClient" Version="[0.0.9]" />
<PackageReference Include="AVPRIndex" Version="[0.2.1]" />
<PackageReference Include="AVPRClient" Version="[0.1.2]" />
</ItemGroup>

</Project>
31 changes: 5 additions & 26 deletions src/ARCValidationPackages/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ open System.Text.Json.Serialization
open AVPRIndex.Domain
open System.Runtime.CompilerServices


module ValidationPackageMetadata =
let getSemanticVersionString(m: ValidationPackageMetadata) = $"{m.MajorVersion}.{m.MinorVersion}.{m.PatchVersion}"

module ValidationPackageIndex =
let getSemanticVersionString(i: ValidationPackageIndex) = $"{i.Metadata.MajorVersion}.{i.Metadata.MinorVersion}.{i.Metadata.PatchVersion}"

/// <summary>
/// represents the locally installed version of a validation package, e.g. the path to the local file and the date it was cached.
/// </summary>
Expand Down Expand Up @@ -50,32 +43,18 @@ type CachedValidationPackage =
metadata = packageIndex.Metadata
)

/// <summary>
/// Creates a new ARCValidationPackage from a package name only, with the CacheDate set to the current or optionally a custom date, and the LocalPath set to the default preview cache folder or custom folder.
/// </summary>
/// <param name="packageName"></param>
/// <param name="Date"></param>
/// <param name="Path"></param>
static member ofPackageName (packageName: string, ?Date: System.DateTimeOffset, ?Path: string) =
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FOLDER_PREVIEW())
CachedValidationPackage.create(
fileName = packageName,
cacheDate = (defaultArg Date System.DateTimeOffset.Now),
localPath = (System.IO.Path.Combine(path, $"{packageName}.fsx").Replace("\\","/")),
metadata = ValidationPackageMetadata()
)

/// <summary>
/// Creates a new ARCValidationPackage from a ValidationPackageMetadata, with the CacheDate set to the current or optionally a custom date, and the LocalPath set to the default release cache folder or custom folder.
/// </summary>
/// <param name="packageIndex">The input package index entry</param>
/// <param name="Date">Optional. The date to set the CacheDate to. Defaults to the current date.</param>
static member ofPackageMetadata (packageMetadata: ValidationPackageMetadata, ?Date: System.DateTimeOffset, ?CacheFolder: string) =
let path = defaultArg CacheFolder (Defaults.PACKAGE_CACHE_FOLDER_RELEASE())
let filename = $"{packageMetadata.Name}@{ValidationPackageMetadata.getSemanticVersionString packageMetadata}.fsx"
CachedValidationPackage.create(
fileName = packageMetadata.Name,
fileName = filename,
cacheDate = (defaultArg Date System.DateTimeOffset.Now),
localPath = (System.IO.Path.Combine(path, $"{packageMetadata.Name}@{packageMetadata.MajorVersion}.{packageMetadata.MinorVersion}.{packageMetadata.PatchVersion}.fsx").Replace("\\","/")),
localPath = (System.IO.Path.Combine(path, filename).Replace("\\","/")),
metadata = packageMetadata
)

Expand All @@ -87,7 +66,7 @@ type CachedValidationPackage =
static member updateCacheDate (date: System.DateTimeOffset) (package: CachedValidationPackage) =
{package with CacheDate = date}

static member getSemanticVersionString(vp: CachedValidationPackage) = $"{vp.Metadata.MajorVersion}.{vp.Metadata.MinorVersion}.{vp.Metadata.PatchVersion}";
static member getSemanticVersionString(vp: CachedValidationPackage) = ValidationPackageMetadata.getSemanticVersionString vp.Metadata

member this.PrettyPrint() =
$" {this.Metadata.Name} @ version {this.Metadata.MajorVersion}.{this.Metadata.MinorVersion}.{this.Metadata.PatchVersion}{System.Environment.NewLine}{this.Metadata.Description}{System.Environment.NewLine}CacheDate: {this.CacheDate}{System.Environment.NewLine}Installed at: {this.LocalPath}{System.Environment.NewLine}"
$" {this.Metadata.Name} @ version {ValidationPackageMetadata.getSemanticVersionString this.Metadata}{System.Environment.NewLine}{this.Metadata.Description}{System.Environment.NewLine}CacheDate: {this.CacheDate}{System.Environment.NewLine}Installed at: {this.LocalPath}{System.Environment.NewLine}"
13 changes: 12 additions & 1 deletion src/ARCValidationPackages/PackageCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ type PackageCache =

static member getLatestPackage (name: string) (cache: PackageCache) =
cache[name]
|> Seq.maxBy (fun (kv:KeyValuePair<string,CachedValidationPackage>) -> kv.Key)
// only get stable versions when suffixes are not supplied explicitly
|> Seq.filter (fun (kv:KeyValuePair<string,CachedValidationPackage>) ->
let semver = SemVer.tryParse kv.Key
if semver.IsSome then
semver.Value.PreRelease = ""
&& semver.Value.BuildMetadata = ""
else false
)
|> Seq.maxBy (fun (kv:KeyValuePair<string,CachedValidationPackage>) ->
let semver = SemVer.tryParse kv.Key |> Option.get
semver.Major, semver.Minor, semver.Patch
)
|> fun x -> x.Value

static member getPackages (name: string) (cache: PackageCache) =
Expand Down
6 changes: 5 additions & 1 deletion src/ARCValidationPackages/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
### 4.0.1 - (Released 2024-04-30)
### 5.0.0 - (Released 2024-06-21)

Support full semantic versions with suffixes

### 4.0.1 - (Released 2024-04-30)

Update pinned dependencies

Expand Down
2 changes: 1 addition & 1 deletion src/ARCValidationPackages/TopLevelAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type Preview =
|> PackageCache.addPackage package
|> PackageCache.write(cacheFolder)

Ok ($"installed preview package {package.FileName}@{ValidationPackageMetadata.getSemanticVersionString package.Metadata} at {package.LocalPath}")
Ok ($"installed preview package {package.FileName} at {package.LocalPath}")

with e ->
match e with
Expand Down
7 changes: 7 additions & 0 deletions src/arc-validate/APIs/PackageAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ type PackageAPI =

let packageName = args.TryGetResult(PackageInstallArgs.Package).Value
let version = args.TryGetResult(PackageInstallArgs.Version)

if Verbose.IsSome then
if Verbose.Value then
if version.IsSome then
printfn $"""Installing package {packageName} {version.Value} from source {if isRelease then "'avpr.nfdi4plants.org'" else "'preview-index on GitHub'"} """
else
printfn $"""Installing package latest version of {packageName} from source {if isRelease then "'avpr.nfdi4plants.org'" else "'preview-index on GitHub'"} """
if isRelease then
match (AVPR.InstallPackage(avprCache, packageName, ?SemVer = version, ?Verbose = Verbose)) with
| Ok msg ->
Expand Down
4 changes: 2 additions & 2 deletions src/arc-validate/arc-validate.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<PackageReference Include="Spectre.Console.CLI" Version="[0.49.1]" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ARCExpect\ARCExpect.fsproj" PackageVersion="[3.0.0, 4.0.0)" />
<ProjectReference Include="..\ARCValidationPackages\ARCValidationPackages.fsproj" PackageVersion="[4.0.0, 5.0.0)" />
<ProjectReference Include="..\ARCExpect\ARCExpect.fsproj" PackageVersion="[4.0.0, 5.0.0)" />
<ProjectReference Include="..\ARCValidationPackages\ARCValidationPackages.fsproj" PackageVersion="[5.0.0, 6.0.0)" />
</ItemGroup>
<Target Name="UseExplicitPackageVersions" BeforeTargets="GenerateNuspec">
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ let tests =
test "updateCacheDate" {
Expect.equal
(
testValidationPackage1
CachedValidationPackage.Preview.testValidationPackage1
|> CachedValidationPackage.updateCacheDate testDate2
)
testValidationPackage2
CachedValidationPackage.Preview.testValidationPackage2
"ARCValidationPackage cache date was not updated correctly."
}
test "ofPackageIndex" {
Expand All @@ -26,7 +26,7 @@ let tests =
Date = testDate2
)
)
testValidationPackage2
CachedValidationPackage.Preview.testValidationPackage2
"ARCValidationPackage was not created correctly."
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Compile Include="TestUtils.fs" />
<Compile Include="ReferenceObjects.fs" />
<Compile Include="DefaultsTests.fs" />
<Compile Include="DomainTests.fs" />
<Compile Include="GitHubAPITests.fs" />
<Compile Include="AVPRAPITests.fs" />
<Compile Include="ARCValidationPackageTests.fs" />
Expand Down
50 changes: 34 additions & 16 deletions tests/ARCValidationPackages.Tests/AVPRAPITests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,45 @@ let ``AVPRAPI tests`` =
}
test "test_5_0_0 - CQCHookEndpoint addition" {
let vp = AVPR.api.GetPackageByNameAndVersion "test" "5.0.0"
let script =
vp.PackageContent
|> Encoding.UTF8.GetString
Expect.equal
(script.ReplaceLineEndings("\n"))
ReferenceObjects.testScriptContentAVPR_test_5_0_0
$"repository content was not correct{System.Environment.NewLine}{script}"
Expect.AVPRClient.validationPackageEqual vp ReferenceObjects.AVPRClientDomain.ValidationPackage.testPackage_5_0_0
}
test "test_5_0_0-use+suffixes - SemVer addition" {
let vp = AVPR.api.GetPackageByNameAndVersion "test" "5.0.0-use+suffixes"
Expect.AVPRClient.validationPackageEqual vp ReferenceObjects.AVPRClientDomain.ValidationPackage.``testPackage_5_0_0-use+suffixes``
}

]
test "GetAllPackages contains a test package" {
let indexedPackages = AVPR.api.GetAllPackages()
Expect.isTrue (indexedPackages |> Array.exists (fun package -> package.Name = "test")) "package index did not contain test script"
}
test "downloadPackageScript test_3_0_0" {
Expect.equal
(
AVPR.api.downloadPackageScript( "test", "3.0.0")
|> fun content -> content.ReplaceLineEndings("\n")
)
ReferenceObjects.testScriptContentAVPR_test_3_0_0
"script content was not correct"
}
testList "downloadPackageScript" [
test "test_3_0_0" {
Expect.equal
(
AVPR.api.downloadPackageScript( "test", "3.0.0")
|> fun content -> content.ReplaceLineEndings("\n")
)
ReferenceObjects.testScriptContentAVPR_test_3_0_0
"script content was not correct"
}
test "test_5_0_0 - CQCHookEndpoint addition" {
Expect.equal
(
AVPR.api.downloadPackageScript( "test", "5.0.0")
|> fun content -> content.ReplaceLineEndings("\n")
)
ReferenceObjects.testScriptContentAVPR_test_5_0_0
"script content was not correct"
}
test "test_5_0_0-use+suffixes - SemVer addition" {
Expect.equal
(
AVPR.api.downloadPackageScript( "test", "5.0.0-use+suffixes")
|> fun content -> content.ReplaceLineEndings("\n")
)
ReferenceObjects.``testScriptContentAVPR_test_5_0_0-use+suffixes``
"script content was not correct"
}
]
]
Loading

0 comments on commit 92e54fe

Please sign in to comment.