From 5cfecd53c043683e5c27745316e391e1b311612b Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 28 Mar 2023 16:27:24 +0330 Subject: [PATCH 1/9] FileConventions.Test: add failing test Add failing test for DetectNotUsingSnakeCaseInScriptName function. --- .../DummyFiles/dummy_snake_case.fsx | 3 +++ src/FileConventions.Test/FileConventions.Test.fs | 10 ++++++++++ src/FileConventions/Library.fs | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/dummy_snake_case.fsx diff --git a/src/FileConventions.Test/DummyFiles/dummy_snake_case.fsx b/src/FileConventions.Test/DummyFiles/dummy_snake_case.fsx new file mode 100644 index 000000000..23c3e513e --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/dummy_snake_case.fsx @@ -0,0 +1,3 @@ +#!/usr/bin/env -S dotnet fsi + +printfn "Hello World!" diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index e32fe7a42..9e9ea531f 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -586,3 +586,13 @@ let IsExecutableTest2() = )) Assert.That(IsExecutable fileInfo, Is.EqualTo false) + + +[] +let DetectNotUsingSnakeCaseInScriptName1() = + let fileInfo = + (FileInfo( + Path.Combine(dummyFilesDirectory.FullName, "dummy_snake_case.fsx") + )) + + Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo false) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 6a5ea3748..38d787fb2 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -390,3 +390,7 @@ let NonVerboseFlags(fileInfo: FileInfo) = let IsExecutable(fileInfo: FileInfo) = let hasExecuteAccess = Syscall.access(fileInfo.FullName, AccessModes.X_OK) hasExecuteAccess = 0 + +let DetectNotUsingSnakeCaseInScriptName(fileInfo: FileInfo) = + printfn "%A" fileInfo.FullName + true From 81850f65ccad859a840b3bf897ed9e11b23a5d3a Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 28 Mar 2023 16:47:07 +0330 Subject: [PATCH 2/9] FileConventions: implement function Implement DetectNotUsingSnakeCaseInScriptName function. --- src/FileConventions/Library.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 38d787fb2..31a258145 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -392,5 +392,5 @@ let IsExecutable(fileInfo: FileInfo) = hasExecuteAccess = 0 let DetectNotUsingSnakeCaseInScriptName(fileInfo: FileInfo) = - printfn "%A" fileInfo.FullName - true + let fileName = fileInfo.Name + not(fileName.ToLower() = fileName) From 82f844acf9c18c1b6d436871aaf8846675535d8e Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 28 Mar 2023 16:49:10 +0330 Subject: [PATCH 3/9] FileConventions.Test: add another test Add test for DetectNotUsingSnakeCaseInScriptName function. --- .../DummyFiles/DummyPascalCase.fsx | 3 +++ src/FileConventions.Test/FileConventions.Test.fs | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/DummyPascalCase.fsx diff --git a/src/FileConventions.Test/DummyFiles/DummyPascalCase.fsx b/src/FileConventions.Test/DummyFiles/DummyPascalCase.fsx new file mode 100644 index 000000000..23c3e513e --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyPascalCase.fsx @@ -0,0 +1,3 @@ +#!/usr/bin/env -S dotnet fsi + +printfn "Hello World!" diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 9e9ea531f..08962d4d9 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -596,3 +596,13 @@ let DetectNotUsingSnakeCaseInScriptName1() = )) Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo false) + + +[] +let DetectNotUsingSnakeCaseInScriptName2() = + let fileInfo = + (FileInfo( + Path.Combine(dummyFilesDirectory.FullName, "DummyPascalCase.fsx") + )) + + Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo true) From 8bbe614da89fcc252f4e2de5f9579af2404ec06d Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 28 Mar 2023 16:54:09 +0330 Subject: [PATCH 4/9] FileConventions.Test: add failing test Add failing test for DetectNotUsingSnakeCaseInScriptName function. --- src/FileConventions.Test/DummyFiles/kebab-case.fsx | 3 +++ src/FileConventions.Test/FileConventions.Test.fs | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/kebab-case.fsx diff --git a/src/FileConventions.Test/DummyFiles/kebab-case.fsx b/src/FileConventions.Test/DummyFiles/kebab-case.fsx new file mode 100644 index 000000000..23c3e513e --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/kebab-case.fsx @@ -0,0 +1,3 @@ +#!/usr/bin/env -S dotnet fsi + +printfn "Hello World!" diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 08962d4d9..15534ca6e 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -606,3 +606,11 @@ let DetectNotUsingSnakeCaseInScriptName2() = )) Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo true) + + +[] +let DetectNotUsingSnakeCaseInScriptName3() = + let fileInfo = + (FileInfo(Path.Combine(dummyFilesDirectory.FullName, "kebab-case.fsx"))) + + Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo true) From ccc72d75b0ea6d5ed604961f75579a07edb296d8 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 28 Mar 2023 17:02:35 +0330 Subject: [PATCH 5/9] FileConventions: fix the function Fix DetectNotUsingSnakeCaseInScriptName function. --- src/FileConventions/Library.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 31a258145..641ec9dde 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -393,4 +393,5 @@ let IsExecutable(fileInfo: FileInfo) = let DetectNotUsingSnakeCaseInScriptName(fileInfo: FileInfo) = let fileName = fileInfo.Name - not(fileName.ToLower() = fileName) + let snakeCase = fileName.ToLower() = fileName && not(fileName.Contains "-") + not(snakeCase) From 674d4f7930ee4e474b838fac2b6d2645d26952c2 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 28 Mar 2023 17:12:16 +0330 Subject: [PATCH 6/9] FileConventions.Test: add failing test Add failing test for DetectNotUsingKebabCaseInGitHubCIJobs function. --- .../DummyFiles/DummyCIWithPascalCaseJobName.yml | 11 +++++++++++ src/FileConventions.Test/FileConventions.Test.fs | 13 +++++++++++++ src/FileConventions/Library.fs | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/DummyCIWithPascalCaseJobName.yml diff --git a/src/FileConventions.Test/DummyFiles/DummyCIWithPascalCaseJobName.yml b/src/FileConventions.Test/DummyFiles/DummyCIWithPascalCaseJobName.yml new file mode 100644 index 000000000..763ad1f01 --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyCIWithPascalCaseJobName.yml @@ -0,0 +1,11 @@ +name: CI + +on: [push, pull_request] + +jobs: + FileConventions: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Print "Hello World!" + run: echo "Hello World!" diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 15534ca6e..30f28e343 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -614,3 +614,16 @@ let DetectNotUsingSnakeCaseInScriptName3() = (FileInfo(Path.Combine(dummyFilesDirectory.FullName, "kebab-case.fsx"))) Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo true) + + +[] +let DetectNotUsingKebabCaseInGitHubCIJobs1() = + let fileInfo = + (FileInfo( + Path.Combine( + dummyFilesDirectory.FullName, + "DummyCIWithPascalCaseJobName.yml" + ) + )) + + Assert.That(DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, Is.EqualTo true) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 641ec9dde..8fbfce9ba 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -395,3 +395,7 @@ let DetectNotUsingSnakeCaseInScriptName(fileInfo: FileInfo) = let fileName = fileInfo.Name let snakeCase = fileName.ToLower() = fileName && not(fileName.Contains "-") not(snakeCase) + +let DetectNotUsingKebabCaseInGitHubCIJobs(fileInfo: FileInfo) = + assert (fileInfo.FullName.EndsWith ".yml") + false From 50de51912995fde9fa885177d6e16945c4da456b Mon Sep 17 00:00:00 2001 From: realmarv Date: Wed, 29 Mar 2023 14:16:06 +0330 Subject: [PATCH 7/9] FileConventions: implement the function Implement DetectNotUsingKebabCaseInGitHubCIJobs function. --- scripts/eofConvention.fsx | 2 +- scripts/executableConvention.fsx | 1 + .../inconsistentVersionsInFSharpScripts.fsx | 2 +- scripts/inconsistentVersionsInGitHubCI.fsx | 2 +- scripts/mixedLineEndings.fsx | 2 +- .../nonVerboseFlagsInGitHubCIAndScripts.fsx | 2 +- scripts/shebangConvention.fsx | 2 +- scripts/unpinnedDotnetPackageVersions.fsx | 2 +- scripts/unpinnedDotnetToolInstallVersions.fsx | 2 +- .../unpinnedGitHubActionsImageVersions.fsx | 2 +- .../unpinnedNugetPackageReferenceVersions.fsx | 2 +- scripts/wrapLatestCommitMsg.fsx | 1 + src/FileConventions/FileConventions.fsproj | 1 + src/FileConventions/Library.fs | 49 ++++++++++++++++++- 14 files changed, 61 insertions(+), 11 deletions(-) diff --git a/scripts/eofConvention.fsx b/scripts/eofConvention.fsx index 3f2b712b9..f2c37233c 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 cecaf6b5b..9789f7e96 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 93922496e..b62c8a038 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 f8041a45d..17e06f884 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 427826a61..777d627a7 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 54bd123d5..41d9a17d2 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 965a9aad3..b3b5752f9 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 56da33c01..b6f065072 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 92f35dcc6..de6e3fad6 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 07d31cc97..e3eabd47f 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 72e0e74b5..54d9766e3 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 5b6592b0e..709bf6ae9 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 9c8c6d177..962df27b0 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 8fbfce9ba..4dd6e4fda 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 From c1901e10d58f810eacd5951e260129bae223462e Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 30 Mar 2023 11:30:19 +0330 Subject: [PATCH 8/9] FileConventions.Test: add more tests Add tests for DetectNotUsingKebabCaseInGitHubCIJobs function. --- .../DummyCIWithKebabCaseJobName.yml | 11 +++++ ...CIWithMultipleJobsAndKebabCaseJobNames.yml | 18 ++++++++ ...ithMultipleJobsAndOnePascalCaseJobName.yml | 18 ++++++++ .../FileConventions.Test.fs | 45 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/DummyCIWithKebabCaseJobName.yml create mode 100644 src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndKebabCaseJobNames.yml create mode 100644 src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndOnePascalCaseJobName.yml diff --git a/src/FileConventions.Test/DummyFiles/DummyCIWithKebabCaseJobName.yml b/src/FileConventions.Test/DummyFiles/DummyCIWithKebabCaseJobName.yml new file mode 100644 index 000000000..ec5f065b4 --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyCIWithKebabCaseJobName.yml @@ -0,0 +1,11 @@ +name: CI + +on: [push, pull_request] + +jobs: + file-conventions: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Print "Hello World!" + run: echo "Hello World!" diff --git a/src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndKebabCaseJobNames.yml b/src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndKebabCaseJobNames.yml new file mode 100644 index 000000000..0f6532c0d --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndKebabCaseJobNames.yml @@ -0,0 +1,18 @@ +name: CI + +on: [push, pull_request] + +jobs: + first-job: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Print "Hello World!" + run: echo "Hello World!" + + second-job: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Print "Hello World!" + run: echo "Hello World!" diff --git a/src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndOnePascalCaseJobName.yml b/src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndOnePascalCaseJobName.yml new file mode 100644 index 000000000..3eb5e7e66 --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyCIWithMultipleJobsAndOnePascalCaseJobName.yml @@ -0,0 +1,18 @@ +name: CI + +on: [push, pull_request] + +jobs: + first-job: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Print "Hello World!" + run: echo "Hello World!" + + SecondJob: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Print "Hello World!" + run: echo "Hello World!" diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 30f28e343..5e9114561 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -627,3 +627,48 @@ let DetectNotUsingKebabCaseInGitHubCIJobs1() = )) Assert.That(DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, Is.EqualTo true) + + +[] +let DetectNotUsingKebabCaseInGitHubCIJobs2() = + let fileInfo = + (FileInfo( + Path.Combine( + dummyFilesDirectory.FullName, + "DummyCIWithKebabCaseJobName.yml" + ) + )) + + Assert.That( + DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, + Is.EqualTo false + ) + + +[] +let DetectNotUsingKebabCaseInGitHubCIJobs3() = + let fileInfo = + (FileInfo( + Path.Combine( + dummyFilesDirectory.FullName, + "DummyCIWithMultipleJobsAndKebabCaseJobNames.yml" + ) + )) + + Assert.That( + DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, + Is.EqualTo false + ) + + +[] +let DetectNotUsingKebabCaseInGitHubCIJobs4() = + let fileInfo = + (FileInfo( + Path.Combine( + dummyFilesDirectory.FullName, + "DummyCIWithMultipleJobsAndOnePascalCaseJobName.yml" + ) + )) + + Assert.That(DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, Is.EqualTo true) From 00903392504f8fe0f635e50c7b2cac4b7ee8687f Mon Sep 17 00:00:00 2001 From: realmarv Date: Wed, 29 Mar 2023 15:49:56 +0330 Subject: [PATCH 9/9] scripts: add new script Add not_respecting_some_naming_conventions.fsx script to detect if some naming conventions are respected. Fixes https://github.com/nblockchain/conventions/issues/93 --- .github/workflows/CI.yml | 28 +++++++------ ...Commits1by1.fsx => check_commits_1by1.fsx} | 2 +- ...Scripts.fsx => compile_fsharp_scripts.fsx} | 0 .../{eofConvention.fsx => eof_convention.fsx} | 0 ...nvention.fsx => executable_convention.fsx} | 0 .../{gitPush1by1.fsx => git_push_1by1.fsx} | 0 ...consistent_versions_in_fsharp_scripts.fsx} | 0 ... => inconsistent_versions_in_githubci.fsx} | 0 ...LineEndings.fsx => mixed_line_endings.fsx} | 0 ...verbose_flags_in_githubci_and_scripts.fsx} | 0 ...not_respecting_some_naming_conventions.fsx | 42 +++++++++++++++++++ ...gConvention.fsx => shebang_convention.fsx} | 0 ...x => unpinned_dotnet_package_versions.fsx} | 0 ...unpinned_dotnet_tool_install_versions.fsx} | 0 ...npinned_github_actions_image_versions.fsx} | 0 ...nned_nuget_package_reference_versions.fsx} | 0 ...mmitMsg.fsx => wrap_latest_commit_msg.fsx} | 0 17 files changed, 58 insertions(+), 14 deletions(-) rename scripts/{checkCommits1by1.fsx => check_commits_1by1.fsx} (99%) rename scripts/{compileFSharpScripts.fsx => compile_fsharp_scripts.fsx} (100%) rename scripts/{eofConvention.fsx => eof_convention.fsx} (100%) rename scripts/{executableConvention.fsx => executable_convention.fsx} (100%) rename scripts/{gitPush1by1.fsx => git_push_1by1.fsx} (100%) rename scripts/{inconsistentVersionsInFSharpScripts.fsx => inconsistent_versions_in_fsharp_scripts.fsx} (100%) rename scripts/{inconsistentVersionsInGitHubCI.fsx => inconsistent_versions_in_githubci.fsx} (100%) rename scripts/{mixedLineEndings.fsx => mixed_line_endings.fsx} (100%) rename scripts/{nonVerboseFlagsInGitHubCIAndScripts.fsx => non_verbose_flags_in_githubci_and_scripts.fsx} (100%) create mode 100755 scripts/not_respecting_some_naming_conventions.fsx rename scripts/{shebangConvention.fsx => shebang_convention.fsx} (100%) rename scripts/{unpinnedDotnetPackageVersions.fsx => unpinned_dotnet_package_versions.fsx} (100%) rename scripts/{unpinnedDotnetToolInstallVersions.fsx => unpinned_dotnet_tool_install_versions.fsx} (100%) rename scripts/{unpinnedGitHubActionsImageVersions.fsx => unpinned_github_actions_image_versions.fsx} (100%) rename scripts/{unpinnedNugetPackageReferenceVersions.fsx => unpinned_nuget_package_reference_versions.fsx} (100%) rename scripts/{wrapLatestCommitMsg.fsx => wrap_latest_commit_msg.fsx} (100%) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e389d9f80..c04de7c4d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -32,7 +32,7 @@ jobs: - name: Compile the conventions solution run: dotnet build --configuration Release conventions.sln - name: Compile F# scripts - run: dotnet fsi scripts/compileFSharpScripts.fsx + run: dotnet fsi scripts/compile_fsharp_scripts.fsx file-conventions-tests: name: Run FileConventions-lib unit tests @@ -166,30 +166,32 @@ jobs: apt install --yes --no-install-recommends dotnet6 - name: Check all files end with EOL - run: dotnet fsi scripts/eofConvention.fsx + run: dotnet fsi scripts/eof_convention.fsx - name: Check all .fsx scripts have shebang - run: dotnet fsi scripts/shebangConvention.fsx + run: dotnet fsi scripts/shebang_convention.fsx - name: Check all F# scripts have execute permission - run: dotnet fsi scripts/executableConvention.fsx + run: dotnet fsi scripts/executable_convention.fsx - name: Check there are no mixed line-endings in any files - run: dotnet fsi scripts/mixedLineEndings.fsx + run: dotnet fsi scripts/mixed_line_endings.fsx - name: Check there are no unpinned GitHubActions image versions - run: dotnet fsi scripts/unpinnedGitHubActionsImageVersions.fsx + run: dotnet fsi scripts/unpinned_github_actions_image_versions.fsx - name: Check there are no unpinned dotnet package versions - run: dotnet fsi scripts/unpinnedDotnetPackageVersions.fsx + run: dotnet fsi scripts/unpinned_dotnet_package_versions.fsx - name: Check there are no unpinned nuget package reference versions in F# scripts - run: dotnet fsi scripts/unpinnedNugetPackageReferenceVersions.fsx + run: dotnet fsi scripts/unpinned_nuget_package_reference_versions.fsx - name: Check there are no unpinned versions in `dotnet tool install` commands - run: dotnet fsi scripts/unpinnedDotnetToolInstallVersions.fsx + run: dotnet fsi scripts/unpinned_dotnet_tool_install_versions.fsx + - name: Check if script names (.fsx, .bat, and .sh files) are snake_case and CI job names are kebab-case. + run: dotnet fsi scripts/not_respecting_some_naming_conventions.fsx - name: Check commits 1 by 1 if: github.event_name == 'pull_request' - run: dotnet fsi scripts/checkCommits1by1.fsx + run: dotnet fsi scripts/check_commits_1by1.fsx - name: Check there are no inconsistent versions GitHubCI files - run: dotnet fsi scripts/inconsistentVersionsInGitHubCI.fsx + run: dotnet fsi scripts/inconsistent_versions_in_githubci.fsx - name: Check there are no inconsistent versions in nuget package references of F# scripts - run: dotnet fsi scripts/inconsistentVersionsInFSharpScripts.fsx + run: dotnet fsi scripts/inconsistent_versions_in_fsharp_scripts.fsx - name: Check there are no non-verbose flags in scripts and CI YML files - run: dotnet fsi scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx + run: dotnet fsi scripts/non_verbose_flags_in_githubci_and_scripts.fsx - name: Install prettier run: npm install prettier@2.8.3 - name: Change file permissions diff --git a/scripts/checkCommits1by1.fsx b/scripts/check_commits_1by1.fsx similarity index 99% rename from scripts/checkCommits1by1.fsx rename to scripts/check_commits_1by1.fsx index 353f91950..3e672d544 100755 --- a/scripts/checkCommits1by1.fsx +++ b/scripts/check_commits_1by1.fsx @@ -920,7 +920,7 @@ if notUsedGitPush1by1 then sprintf "Please push the commits one by one to make sure every commit has a CI status; using this script is recommended:%s%s" Environment.NewLine - "https://github.com/nblockchain/conventions/blob/master/scripts/gitPush1by1.fsx" + "https://github.com/nblockchain/conventions/blob/master/scripts/git_push_1by1.fsx" Console.Error.WriteLine errMsg Environment.Exit 2 diff --git a/scripts/compileFSharpScripts.fsx b/scripts/compile_fsharp_scripts.fsx similarity index 100% rename from scripts/compileFSharpScripts.fsx rename to scripts/compile_fsharp_scripts.fsx diff --git a/scripts/eofConvention.fsx b/scripts/eof_convention.fsx similarity index 100% rename from scripts/eofConvention.fsx rename to scripts/eof_convention.fsx diff --git a/scripts/executableConvention.fsx b/scripts/executable_convention.fsx similarity index 100% rename from scripts/executableConvention.fsx rename to scripts/executable_convention.fsx diff --git a/scripts/gitPush1by1.fsx b/scripts/git_push_1by1.fsx similarity index 100% rename from scripts/gitPush1by1.fsx rename to scripts/git_push_1by1.fsx diff --git a/scripts/inconsistentVersionsInFSharpScripts.fsx b/scripts/inconsistent_versions_in_fsharp_scripts.fsx similarity index 100% rename from scripts/inconsistentVersionsInFSharpScripts.fsx rename to scripts/inconsistent_versions_in_fsharp_scripts.fsx diff --git a/scripts/inconsistentVersionsInGitHubCI.fsx b/scripts/inconsistent_versions_in_githubci.fsx similarity index 100% rename from scripts/inconsistentVersionsInGitHubCI.fsx rename to scripts/inconsistent_versions_in_githubci.fsx diff --git a/scripts/mixedLineEndings.fsx b/scripts/mixed_line_endings.fsx similarity index 100% rename from scripts/mixedLineEndings.fsx rename to scripts/mixed_line_endings.fsx diff --git a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx b/scripts/non_verbose_flags_in_githubci_and_scripts.fsx similarity index 100% rename from scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx rename to scripts/non_verbose_flags_in_githubci_and_scripts.fsx diff --git a/scripts/not_respecting_some_naming_conventions.fsx b/scripts/not_respecting_some_naming_conventions.fsx new file mode 100755 index 000000000..71a2b5e4d --- /dev/null +++ b/scripts/not_respecting_some_naming_conventions.fsx @@ -0,0 +1,42 @@ +#!/usr/bin/env -S dotnet fsi + +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" + +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo + +let invalidYmlFiles = + Helpers.GetInvalidFiles + rootDir + "*.yml" + FileConventions.DetectNotUsingKebabCaseInGitHubCIJobs + +Helpers.AssertNoInvalidFiles + invalidYmlFiles + "Please use kebab-case for CI job names in the following files:" + +let scriptExtensions = + seq { + ".fsx" + ".bat" + ".sh" + } + +let scriptsWithInvalidNames = + scriptExtensions + |> Seq.map(fun extension -> + Helpers.GetInvalidFiles + rootDir + ("*" + extension) + FileConventions.DetectNotUsingSnakeCaseInScriptName + ) + |> Seq.concat + +Helpers.AssertNoInvalidFiles + scriptsWithInvalidNames + "Please use snake_case for naming the following scripts:" diff --git a/scripts/shebangConvention.fsx b/scripts/shebang_convention.fsx similarity index 100% rename from scripts/shebangConvention.fsx rename to scripts/shebang_convention.fsx diff --git a/scripts/unpinnedDotnetPackageVersions.fsx b/scripts/unpinned_dotnet_package_versions.fsx similarity index 100% rename from scripts/unpinnedDotnetPackageVersions.fsx rename to scripts/unpinned_dotnet_package_versions.fsx diff --git a/scripts/unpinnedDotnetToolInstallVersions.fsx b/scripts/unpinned_dotnet_tool_install_versions.fsx similarity index 100% rename from scripts/unpinnedDotnetToolInstallVersions.fsx rename to scripts/unpinned_dotnet_tool_install_versions.fsx diff --git a/scripts/unpinnedGitHubActionsImageVersions.fsx b/scripts/unpinned_github_actions_image_versions.fsx similarity index 100% rename from scripts/unpinnedGitHubActionsImageVersions.fsx rename to scripts/unpinned_github_actions_image_versions.fsx diff --git a/scripts/unpinnedNugetPackageReferenceVersions.fsx b/scripts/unpinned_nuget_package_reference_versions.fsx similarity index 100% rename from scripts/unpinnedNugetPackageReferenceVersions.fsx rename to scripts/unpinned_nuget_package_reference_versions.fsx diff --git a/scripts/wrapLatestCommitMsg.fsx b/scripts/wrap_latest_commit_msg.fsx similarity index 100% rename from scripts/wrapLatestCommitMsg.fsx rename to scripts/wrap_latest_commit_msg.fsx