From 8b4a6a742b7aaf2bee10729d92f42107da0e480d 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 81d82bc68..a70e17f45 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -639,3 +639,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 e471f54cd..fa8003a3e 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -495,3 +495,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 09d545ddd99e61c6abaea990a278bc2c5fdf8c00 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 fa8003a3e..982e8afe9 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -497,5 +497,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 183cb5dc3f059b5c67e03cdabd92e18c75cf4f6b 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 a70e17f45..558c7ee32 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -649,3 +649,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 6b63de00aabbcbfbc4593b6061c1127608aa7336 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 558c7ee32..e7f44a454 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -659,3 +659,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 99aea917fdc5f59f6837bb70c6dcc5f1e127a703 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 982e8afe9..c790a6f63 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -498,4 +498,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 8b00f4f1b5753897194cee761e929c60af2ea6f6 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 e7f44a454..525040e1a 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -667,3 +667,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 c790a6f63..aa13a9070 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -500,3 +500,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 e87ca00443e7eb43578318375d94cf8804c8062f 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. --- src/FileConventions/Library.fs | 48 +++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index aa13a9070..9fcfcd81a 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -7,6 +7,7 @@ open System.Text.RegularExpressions open Mono open Mono.Unix.Native +open YamlDotNet open YamlDotNet.RepresentationModel let SplitByEOLs (text: string) (numberOfEOLs: uint) = @@ -503,4 +504,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 5290c31970d5ab65f4c167fb123effe859f694d3 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 525040e1a..2e9caa263 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -680,3 +680,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 06b2c65c216d66899704ccec373579abda3352ee 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 | 34 ++++++++------- ...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 ...ent_nuget_versions_in_dotnet_projects.fsx} | 0 ...in_dotnet_projects_and_fsharp_scripts.fsx} | 0 ...tent_nuget_versions_in_fsharp_scripts.fsx} | 0 ...nconsistent_versions_in_fsharp_scripts.fsx | 23 ++++++++++ ... => 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 ...e_reference_versions_in_fsharp_scripts.fsx | 25 +++++++++++ ...package_reference_versions_in_projects.fsx | 28 +++++++++++++ ...mmitMsg.fsx => wrap_latest_commit_msg.fsx} | 0 22 files changed, 137 insertions(+), 17 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/{inconsistentNugetVersionsInDotNetProjects.fsx => inconsistent_nuget_versions_in_dotnet_projects.fsx} (100%) rename scripts/{inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx => inconsistent_nuget_versions_in_dotnet_projects_and_fsharp_scripts.fsx} (100%) rename scripts/{inconsistentNugetVersionsInFSharpScripts.fsx => inconsistent_nuget_versions_in_fsharp_scripts.fsx} (100%) create mode 100755 scripts/inconsistent_versions_in_fsharp_scripts.fsx 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/{unpinnedNugetPackageReferenceVersionsInProjects.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/{unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx => unpinned_nuget_package_reference_versions.fsx} (100%) create mode 100755 scripts/unpinned_nuget_package_reference_versions_in_fsharp_scripts.fsx create mode 100755 scripts/unpinned_nuget_package_reference_versions_in_projects.fsx rename scripts/{wrapLatestCommitMsg.fsx => wrap_latest_commit_msg.fsx} (100%) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5c23e7db2..bb93e2bc5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,7 +40,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 @@ -195,36 +195,38 @@ jobs: apt install --yes --no-install-recommends dotnet-sdk-8.0 - 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 - - name: Check there are no unpinned nuget package reference versions in .NET project files - run: dotnet fsi scripts/unpinnedNugetPackageReferenceVersionsInProjects.fsx + run: dotnet fsi scripts/unpinned_github_actions_image_versions.fsx + - name: Check there are no unpinned dotnet package versions + 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/unpinnedNugetPackageReferenceVersionsInFSharpScripts.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/inconsistentNugetVersionsInFSharpScripts.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: Sanity check nuget packages of .NET projects run: | dotnet restore - dotnet fsi scripts/inconsistentNugetVersionsInDotNetProjects.fsx + dotnet fsi scripts/inconsistent_nuget_versions_in_dotnet_projects.fsx - name: Check there are no inconsistent versions in nuget package references of F# scripts and projects - run: dotnet fsi scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx + run: dotnet fsi scripts/inconsistent_nuget_versions_in_dotnet_projects_and_fsharp_scripts.fsx - name: Install prettier run: npm install --verbose 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 5641260f0..4efcbd9be 100755 --- a/scripts/checkCommits1by1.fsx +++ b/scripts/check_commits_1by1.fsx @@ -1340,7 +1340,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.WriteLine() Console.Error.WriteLine errMsg 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/inconsistentNugetVersionsInDotNetProjects.fsx b/scripts/inconsistent_nuget_versions_in_dotnet_projects.fsx similarity index 100% rename from scripts/inconsistentNugetVersionsInDotNetProjects.fsx rename to scripts/inconsistent_nuget_versions_in_dotnet_projects.fsx diff --git a/scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx b/scripts/inconsistent_nuget_versions_in_dotnet_projects_and_fsharp_scripts.fsx similarity index 100% rename from scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx rename to scripts/inconsistent_nuget_versions_in_dotnet_projects_and_fsharp_scripts.fsx diff --git a/scripts/inconsistentNugetVersionsInFSharpScripts.fsx b/scripts/inconsistent_nuget_versions_in_fsharp_scripts.fsx similarity index 100% rename from scripts/inconsistentNugetVersionsInFSharpScripts.fsx rename to scripts/inconsistent_nuget_versions_in_fsharp_scripts.fsx diff --git a/scripts/inconsistent_versions_in_fsharp_scripts.fsx b/scripts/inconsistent_versions_in_fsharp_scripts.fsx new file mode 100755 index 000000000..5458c12e7 --- /dev/null +++ b/scripts/inconsistent_versions_in_fsharp_scripts.fsx @@ -0,0 +1,23 @@ +#!/usr/bin/env -S dotnet fsi + +open System.IO +open System.Linq + +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" +#r "nuget: YamlDotNet, Version=16.1.3" + +#load "../src/FileConventions/Library.fs" +#load "../src/FileConventions/Helpers.fs" + +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo +let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo + +let targetDir = Helpers.PreferLessDeeplyNestedDir currentDir rootDir + +let inconsistentVersionsInFsharpScripts = + Helpers.GetFiles targetDir "*.fsx" + |> FileConventions.DetectInconsistentVersionsInNugetRefsInFSharpScripts + +if inconsistentVersionsInFsharpScripts then + failwith + "You shouldn't use inconsistent versions in nuget package references of F# scripts." 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..8fa59e2fc --- /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=16.1.3" +#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/unpinnedNugetPackageReferenceVersionsInProjects.fsx b/scripts/unpinned_dotnet_package_versions.fsx similarity index 100% rename from scripts/unpinnedNugetPackageReferenceVersionsInProjects.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/unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx b/scripts/unpinned_nuget_package_reference_versions.fsx similarity index 100% rename from scripts/unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx rename to scripts/unpinned_nuget_package_reference_versions.fsx diff --git a/scripts/unpinned_nuget_package_reference_versions_in_fsharp_scripts.fsx b/scripts/unpinned_nuget_package_reference_versions_in_fsharp_scripts.fsx new file mode 100755 index 000000000..d48fc1e29 --- /dev/null +++ b/scripts/unpinned_nuget_package_reference_versions_in_fsharp_scripts.fsx @@ -0,0 +1,25 @@ +#!/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=16.1.3" + +#load "../src/FileConventions/Library.fs" +#load "../src/FileConventions/Helpers.fs" + +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo + +let invalidFiles = + Helpers.GetInvalidFiles + rootDir + "*.fsx" + FileConventions.DetectMissingVersionsInNugetPackageReferences + +let message = + "The following files shouldn't miss the version number in `#r \"nuget: ` refs of F# scripts." + + Environment.NewLine + + "Please use the exact version of the package instead." + +Helpers.AssertNoInvalidFiles invalidFiles message diff --git a/scripts/unpinned_nuget_package_reference_versions_in_projects.fsx b/scripts/unpinned_nuget_package_reference_versions_in_projects.fsx new file mode 100755 index 000000000..7d3a73f05 --- /dev/null +++ b/scripts/unpinned_nuget_package_reference_versions_in_projects.fsx @@ -0,0 +1,28 @@ +#!/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=16.1.3" + +#load "../src/FileConventions/Library.fs" +#load "../src/FileConventions/Helpers.fs" + +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo +let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo + +let targetDir = Helpers.PreferLessDeeplyNestedDir currentDir rootDir + +let invalidFiles = + Helpers.GetInvalidFiles + targetDir + "*.*proj" + FileConventions.DetectAsteriskInPackageReferenceItems + +let message = + "The following files shouldn't use asterisk (*) in PackageReference items of .NET projects." + + Environment.NewLine + + "Please use the exact version of the package instead." + +Helpers.AssertNoInvalidFiles invalidFiles message 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