From 5fe6d23fce8caef28cdd8661412207a489c90829 Mon Sep 17 00:00:00 2001 From: realmarv Date: Wed, 29 Mar 2023 15:49:56 +0330 Subject: [PATCH] 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 | 41 +++++++++++++++++++ ...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, 57 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..13abe0743 --- /dev/null +++ b/scripts/not_respecting_some_naming_conventions.fsx @@ -0,0 +1,41 @@ +#!/usr/bin/env -S dotnet fsi + +open System +open System.IO + +#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