Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect if some naming conventions are respected #99

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/eofConvention.fsx → scripts/eof_convention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
42 changes: 42 additions & 0 deletions scripts/not_respecting_some_naming_conventions.fsx
Original file line number Diff line number Diff line change
@@ -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:"
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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!"
Original file line number Diff line number Diff line change
@@ -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!"
Original file line number Diff line number Diff line change
@@ -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!"
Original file line number Diff line number Diff line change
@@ -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!"
3 changes: 3 additions & 0 deletions src/FileConventions.Test/DummyFiles/DummyPascalCase.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S dotnet fsi

printfn "Hello World!"
3 changes: 3 additions & 0 deletions src/FileConventions.Test/DummyFiles/dummy_snake_case.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S dotnet fsi

printfn "Hello World!"
3 changes: 3 additions & 0 deletions src/FileConventions.Test/DummyFiles/kebab-case.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S dotnet fsi

printfn "Hello World!"
86 changes: 86 additions & 0 deletions src/FileConventions.Test/FileConventions.Test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,89 @@ let IsExecutableTest2() =
))

Assert.That(IsExecutable fileInfo, Is.EqualTo false)


[<Test>]
let DetectNotUsingSnakeCaseInScriptName1() =
let fileInfo =
(FileInfo(
Path.Combine(dummyFilesDirectory.FullName, "dummy_snake_case.fsx")
))

Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo false)


[<Test>]
let DetectNotUsingSnakeCaseInScriptName2() =
let fileInfo =
(FileInfo(
Path.Combine(dummyFilesDirectory.FullName, "DummyPascalCase.fsx")
))

Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo true)


[<Test>]
let DetectNotUsingSnakeCaseInScriptName3() =
let fileInfo =
(FileInfo(Path.Combine(dummyFilesDirectory.FullName, "kebab-case.fsx")))

Assert.That(DetectNotUsingSnakeCaseInScriptName fileInfo, Is.EqualTo true)


[<Test>]
let DetectNotUsingKebabCaseInGitHubCIJobs1() =
let fileInfo =
(FileInfo(
Path.Combine(
dummyFilesDirectory.FullName,
"DummyCIWithPascalCaseJobName.yml"
)
))

Assert.That(DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, Is.EqualTo true)


[<Test>]
let DetectNotUsingKebabCaseInGitHubCIJobs2() =
let fileInfo =
(FileInfo(
Path.Combine(
dummyFilesDirectory.FullName,
"DummyCIWithKebabCaseJobName.yml"
)
))

Assert.That(
DetectNotUsingKebabCaseInGitHubCIJobs fileInfo,
Is.EqualTo false
)


[<Test>]
let DetectNotUsingKebabCaseInGitHubCIJobs3() =
let fileInfo =
(FileInfo(
Path.Combine(
dummyFilesDirectory.FullName,
"DummyCIWithMultipleJobsAndKebabCaseJobNames.yml"
)
))

Assert.That(
DetectNotUsingKebabCaseInGitHubCIJobs fileInfo,
Is.EqualTo false
)


[<Test>]
let DetectNotUsingKebabCaseInGitHubCIJobs4() =
let fileInfo =
(FileInfo(
Path.Combine(
dummyFilesDirectory.FullName,
"DummyCIWithMultipleJobsAndOnePascalCaseJobName.yml"
)
))

Assert.That(DetectNotUsingKebabCaseInGitHubCIJobs fileInfo, Is.EqualTo true)
1 change: 1 addition & 0 deletions src/FileConventions/FileConventions.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Mono.Posix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="YamlDotNet" Version="13.0.2" />
</ItemGroup>

</Project>
Loading
Loading