diff --git a/scripts/eofConvention.fsx b/scripts/eofConvention.fsx index 3f2b712b..f2c37233 100755 --- a/scripts/eofConvention.fsx +++ b/scripts/eofConvention.fsx @@ -4,7 +4,7 @@ open System.IO open System #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Helpers.fs" #load "../src/FileConventions/Library.fs" diff --git a/scripts/executableConvention.fsx b/scripts/executableConvention.fsx index cecaf6b5..9789f7e9 100755 --- a/scripts/executableConvention.fsx +++ b/scripts/executableConvention.fsx @@ -4,6 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/inconsistentVersionsInFSharpScripts.fsx b/scripts/inconsistentVersionsInFSharpScripts.fsx index 93922496..b62c8a03 100755 --- a/scripts/inconsistentVersionsInFSharpScripts.fsx +++ b/scripts/inconsistentVersionsInFSharpScripts.fsx @@ -4,7 +4,7 @@ open System.IO open System.Linq #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/inconsistentVersionsInGitHubCI.fsx b/scripts/inconsistentVersionsInGitHubCI.fsx index f8041a45..17e06f88 100755 --- a/scripts/inconsistentVersionsInGitHubCI.fsx +++ b/scripts/inconsistentVersionsInGitHubCI.fsx @@ -3,7 +3,7 @@ open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/mixedLineEndings.fsx b/scripts/mixedLineEndings.fsx index 427826a6..777d627a 100755 --- a/scripts/mixedLineEndings.fsx +++ b/scripts/mixedLineEndings.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx index 54bd123d..41d9a17d 100755 --- a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx +++ b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/shebangConvention.fsx b/scripts/shebangConvention.fsx index 965a9aad..b3b5752f 100755 --- a/scripts/shebangConvention.fsx +++ b/scripts/shebangConvention.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedDotnetPackageVersions.fsx b/scripts/unpinnedDotnetPackageVersions.fsx index 56da33c0..b6f06507 100755 --- a/scripts/unpinnedDotnetPackageVersions.fsx +++ b/scripts/unpinnedDotnetPackageVersions.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedDotnetToolInstallVersions.fsx b/scripts/unpinnedDotnetToolInstallVersions.fsx index 92f35dcc..de6e3fad 100755 --- a/scripts/unpinnedDotnetToolInstallVersions.fsx +++ b/scripts/unpinnedDotnetToolInstallVersions.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedGitHubActionsImageVersions.fsx b/scripts/unpinnedGitHubActionsImageVersions.fsx index 07d31cc9..e3eabd47 100755 --- a/scripts/unpinnedGitHubActionsImageVersions.fsx +++ b/scripts/unpinnedGitHubActionsImageVersions.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedNugetPackageReferenceVersions.fsx b/scripts/unpinnedNugetPackageReferenceVersions.fsx index 72e0e74b..54d9766e 100755 --- a/scripts/unpinnedNugetPackageReferenceVersions.fsx +++ b/scripts/unpinnedNugetPackageReferenceVersions.fsx @@ -4,7 +4,7 @@ open System open System.IO #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" - +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/wrapLatestCommitMsg.fsx b/scripts/wrapLatestCommitMsg.fsx index 5b6592b0..709bf6ae 100755 --- a/scripts/wrapLatestCommitMsg.fsx +++ b/scripts/wrapLatestCommitMsg.fsx @@ -5,6 +5,7 @@ open System open System.Text.RegularExpressions #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" +#r "nuget: YamlDotNet, Version=13.0.2" #load "../src/FileConventions/Library.fs" diff --git a/src/FileConventions/FileConventions.fsproj b/src/FileConventions/FileConventions.fsproj index 9c8c6d17..962df27b 100644 --- a/src/FileConventions/FileConventions.fsproj +++ b/src/FileConventions/FileConventions.fsproj @@ -13,6 +13,7 @@ + diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 8fbfce9b..4dd6e4fd 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -7,6 +7,8 @@ open System.Text.RegularExpressions open Mono open Mono.Unix.Native +open YamlDotNet +open YamlDotNet.RepresentationModel let HasCorrectShebang(fileInfo: FileInfo) = let fileText = File.ReadLines fileInfo.FullName @@ -398,4 +400,49 @@ let DetectNotUsingSnakeCaseInScriptName(fileInfo: FileInfo) = let DetectNotUsingKebabCaseInGitHubCIJobs(fileInfo: FileInfo) = assert (fileInfo.FullName.EndsWith ".yml") - false + + let read yaml = + use reader = new StringReader(yaml) + let stream = YamlStream() + stream.Load(reader) + stream.Documents + + let doc = read(File.ReadAllText fileInfo.FullName) + + let ymlNode = doc.[0].RootNode + + // Borrowed from https://stackoverflow.com/questions/46697298/whats-the-best-way-to-parse-yaml-in-f-on-net-core + let getMapping(ymlNode: YamlNode) = + let node = ymlNode :?> YamlMappingNode + + let mapping = + node.Children + |> Seq.map(fun kvp -> + let keyNode = kvp.Key :?> YamlScalarNode + keyNode.Value, kvp.Value + ) + |> Map.ofSeq + + mapping + + let jobNames = + match ymlNode.NodeType with + | YamlNodeType.Mapping -> + let mapping = getMapping ymlNode + let maybeJobs = mapping.TryFind "jobs" + + match maybeJobs with + | Some jobs -> + let mapping = getMapping jobs + (mapping |> Map.toSeq |> Seq.map fst) + | None -> Seq.empty + | _ -> Seq.empty + + jobNames + |> Seq.map(fun jobName -> + let isKebabCase = + jobName.ToLower() = jobName && not(jobName.Contains("_")) + + isKebabCase + ) + |> Seq.contains false