Skip to content

Commit

Permalink
replace line endings when parsing frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Mar 11, 2024
1 parent 1a4afb5 commit 2ba7556
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 8 deletions.
6 changes: 6 additions & 0 deletions PackageStagingArea.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "AVPRIndex", "src\AVPRIndex\
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "StagingAreaTests", "StagingAreaTests\StagingAreaTests.fsproj", "{510A5F69-72CD-4CBB-95BF-04E716585488}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "IndexTests", "tests\IndexTests\IndexTests.fsproj", "{FA7524A5-3A92-4E33-8E28-726BA2E615D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{510A5F69-72CD-4CBB-95BF-04E716585488}.Debug|Any CPU.Build.0 = Debug|Any CPU
{510A5F69-72CD-4CBB-95BF-04E716585488}.Release|Any CPU.ActiveCfg = Release|Any CPU
{510A5F69-72CD-4CBB-95BF-04E716585488}.Release|Any CPU.Build.0 = Release|Any CPU
{FA7524A5-3A92-4E33-8E28-726BA2E615D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA7524A5-3A92-4E33-8E28-726BA2E615D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA7524A5-3A92-4E33-8E28-726BA2E615D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA7524A5-3A92-4E33-8E28-726BA2E615D2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions StagingAreaTests/StagingAreaTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="playground.fsx" />
<Content Include="..\src\PackageRegistryService\StagingArea\**" CopyToOutputDirectory="Always" LinkBase="StagingArea" />
<Compile Include="Utils.fs" />
<Compile Include="ReferenceObjects.fs" />
Expand All @@ -18,6 +19,8 @@
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
6 changes: 3 additions & 3 deletions StagingAreaTests/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type Assert with
//test wether all required fields are present
Assert.NotNull(m)
Assert.NotNull(m.Name)
Assert.NotEmpty(m.Name)
Assert.NotEqual<string>(m.Name, "")
Assert.NotNull(m.Summary)
Assert.NotEmpty(m.Summary)
Assert.NotEqual<string>(m.Summary, "")
Assert.NotNull(m.Description)
Assert.NotEmpty(m.Description)
Assert.NotEqual<string>(m.Description, "")
Assert.NotNull(m.MajorVersion)
Assert.True(m.MajorVersion >= 0)
Assert.NotNull(m.MinorVersion)
Expand Down
34 changes: 34 additions & 0 deletions StagingAreaTests/playground.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#r "nuget: YamlDotNet, 15.1.2"
#r "../src/AVPRIndex/bin/Debug/net8.0/AVPRIndex.dll"

open AVPRIndex
open AVPRIndex.Domain
open AVPRIndex.Frontmatter
open YamlDotNet.Serialization

open System
open System.IO
open System.Text

let yamlDeserializer =
DeserializerBuilder()
.WithNamingConvention(NamingConventions.PascalCaseNamingConvention.Instance)
.Build()

let p = @"C:\Users\schne\source\repos\nfdi4plants\arc-validate-package-registry\src\PackageRegistryService\StagingArea\pride\[email protected]"

ValidationPackageMetadata.extractFromScript(p)

let f = File.ReadAllText(p).ReplaceLineEndings()

f.ReplaceLineEndings().StartsWith(Frontmatter.frontMatterStart)

f.ReplaceLineEndings().Contains(Frontmatter.frontMatterEnd)

let fm =
f.Substring(
frontMatterStart.Length,
(f.IndexOf(Frontmatter.frontMatterEnd, StringComparison.Ordinal) - frontMatterEnd.Length)
)

yamlDeserializer.Deserialize<ValidationPackageMetadata>(fm)
2 changes: 1 addition & 1 deletion src/AVPRIndex/AVPRIndex.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md"))</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>0.0.3</PackageVersion>
<PackageVersion>0.0.4</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/AVPRIndex/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ module Domain =
member val Name = "" with get,set
member val Summary = "" with get,set
member val Description = "" with get,set
member val MajorVersion = 0 with get,set
member val MinorVersion = 0 with get,set
member val PatchVersion = 0 with get,set
member val MajorVersion = -1 with get,set
member val MinorVersion = -1 with get,set
member val PatchVersion = -1 with get,set
// optional fields
member val Publish = false with get,set
member val Authors: Author [] = Array.empty<Author> with get,set
Expand Down
3 changes: 2 additions & 1 deletion src/AVPRIndex/Frontmatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Frontmatter =
type ValidationPackageMetadata with

static member extractFromScript (scriptPath: string) =
let script = File.ReadAllText(scriptPath)
let script = File.ReadAllText(scriptPath).ReplaceLineEndings()
if script.StartsWith(frontMatterStart, StringComparison.Ordinal) && script.Contains(frontMatterEnd) then
let frontmatter =
script.Substring(
Expand All @@ -32,6 +32,7 @@ module Frontmatter =
result
with e as exn ->
printfn $"error parsing package metadata at {scriptPath}. Make sure that all required metadata tags are included."
printfn $"Error msg: {e.Message}."
ValidationPackageMetadata()
else
printfn $"script at {scriptPath} has no correctly formatted frontmatter."
Expand Down
4 changes: 4 additions & 0 deletions src/AVPRIndex/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.0.4

- Replace line endings when parsing frontmatter

## v0.0.3

- Add create function to Author and OntologyAnnotation (https://github.com/nfdi4plants/arc-validate-package-registry/pull/27)
Expand Down

0 comments on commit 2ba7556

Please sign in to comment.