diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 43a06ea1..e389d9f8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -169,6 +169,8 @@ jobs: run: dotnet fsi scripts/eofConvention.fsx - name: Check all .fsx scripts have shebang run: dotnet fsi scripts/shebangConvention.fsx + - name: Check all F# scripts have execute permission + run: dotnet fsi scripts/executableConvention.fsx - name: Check there are no mixed line-endings in any files run: dotnet fsi scripts/mixedLineEndings.fsx - name: Check there are no unpinned GitHubActions image versions diff --git a/ReadMe.md b/ReadMe.md index 709e597f..b5b9a446 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -6,6 +6,7 @@ This is a repository that contains several useful things that other `nblockchain - [Workflow guidelines](docs/WorkflowGuidelines.md). - Scripts that aid maintainability: * [Detection of .fsx scripts without shebang](scripts/shebangConvention.fsx). + * [Detection of .fsx files without +x attrib](scripts/executableConvention.fsx). * [F# scripts compilation](scripts/compileFSharpScripts.fsx). * [EOF without EOL detection](scripts/eofConvention.fsx). * [Mixed line-endings detection](scripts/mixedLineEndings.fsx). @@ -23,6 +24,5 @@ This is a repository that contains several useful things that other `nblockchain All in all, this is mainly documentation, and some tooling to detect bad practices. More things to come: -- Detect .fsx files without +x attrib. - Detect old versions of FSharpLint and fantomas/fantomless being used. - Detect old versions of .editorconfig or Directory.Build.props being used. diff --git a/scripts/checkCommits1by1.fsx b/scripts/checkCommits1by1.fsx old mode 100644 new mode 100755 diff --git a/scripts/compileFSharpScripts.fsx b/scripts/compileFSharpScripts.fsx old mode 100644 new mode 100755 diff --git a/scripts/eofConvention.fsx b/scripts/eofConvention.fsx old mode 100644 new mode 100755 index 32bfb983..3f2b712b --- a/scripts/eofConvention.fsx +++ b/scripts/eofConvention.fsx @@ -3,6 +3,8 @@ open System.IO open System +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Helpers.fs" #load "../src/FileConventions/Library.fs" diff --git a/scripts/executableConvention.fsx b/scripts/executableConvention.fsx new file mode 100755 index 00000000..cecaf6b5 --- /dev/null +++ b/scripts/executableConvention.fsx @@ -0,0 +1,20 @@ +#!/usr/bin/env -S dotnet fsi + +open System +open System.IO + +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" +#load "../src/FileConventions/Library.fs" +#load "../src/FileConventions/Helpers.fs" + +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo + +let invalidFiles = + Helpers.GetInvalidFiles + rootDir + "*.fsx" + (fun fileInfo -> not(FileConventions.IsExecutable fileInfo)) + +Helpers.AssertNoInvalidFiles + invalidFiles + "The following files don't have execute permission:" diff --git a/scripts/inconsistentVersionsInFSharpScripts.fsx b/scripts/inconsistentVersionsInFSharpScripts.fsx old mode 100644 new mode 100755 index e7347996..93922496 --- a/scripts/inconsistentVersionsInFSharpScripts.fsx +++ b/scripts/inconsistentVersionsInFSharpScripts.fsx @@ -3,6 +3,8 @@ open System.IO open System.Linq +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/inconsistentVersionsInGitHubCI.fsx b/scripts/inconsistentVersionsInGitHubCI.fsx old mode 100644 new mode 100755 index 80bd9a1c..f8041a45 --- a/scripts/inconsistentVersionsInGitHubCI.fsx +++ b/scripts/inconsistentVersionsInGitHubCI.fsx @@ -2,6 +2,8 @@ open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/mixedLineEndings.fsx b/scripts/mixedLineEndings.fsx old mode 100644 new mode 100755 index 7b404c98..427826a6 --- a/scripts/mixedLineEndings.fsx +++ b/scripts/mixedLineEndings.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx old mode 100644 new mode 100755 index 6ffb8801..54bd123d --- a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx +++ b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/shebangConvention.fsx b/scripts/shebangConvention.fsx old mode 100644 new mode 100755 index 89e1f0fb..965a9aad --- a/scripts/shebangConvention.fsx +++ b/scripts/shebangConvention.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedDotnetPackageVersions.fsx b/scripts/unpinnedDotnetPackageVersions.fsx old mode 100644 new mode 100755 index f4042960..56da33c0 --- a/scripts/unpinnedDotnetPackageVersions.fsx +++ b/scripts/unpinnedDotnetPackageVersions.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedDotnetToolInstallVersions.fsx b/scripts/unpinnedDotnetToolInstallVersions.fsx old mode 100644 new mode 100755 index 0d99b0f4..92f35dcc --- a/scripts/unpinnedDotnetToolInstallVersions.fsx +++ b/scripts/unpinnedDotnetToolInstallVersions.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedGitHubActionsImageVersions.fsx b/scripts/unpinnedGitHubActionsImageVersions.fsx old mode 100644 new mode 100755 index 451bdeb6..07d31cc9 --- a/scripts/unpinnedGitHubActionsImageVersions.fsx +++ b/scripts/unpinnedGitHubActionsImageVersions.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/unpinnedNugetPackageReferenceVersions.fsx b/scripts/unpinnedNugetPackageReferenceVersions.fsx old mode 100644 new mode 100755 index 15aa408e..72e0e74b --- a/scripts/unpinnedNugetPackageReferenceVersions.fsx +++ b/scripts/unpinnedNugetPackageReferenceVersions.fsx @@ -3,6 +3,8 @@ open System open System.IO +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #load "../src/FileConventions/Helpers.fs" diff --git a/scripts/wrapLatestCommitMsg.fsx b/scripts/wrapLatestCommitMsg.fsx old mode 100644 new mode 100755 index bf38c0d6..5b6592b0 --- a/scripts/wrapLatestCommitMsg.fsx +++ b/scripts/wrapLatestCommitMsg.fsx @@ -4,6 +4,8 @@ open System.IO open System open System.Text.RegularExpressions +#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" + #load "../src/FileConventions/Library.fs" #r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" diff --git a/src/FileConventions.Test/DummyFiles/DummyExecutable.fsx b/src/FileConventions.Test/DummyFiles/DummyExecutable.fsx new file mode 100644 index 00000000..e69de29b diff --git a/src/FileConventions.Test/DummyFiles/DummyNotExecutable.fs b/src/FileConventions.Test/DummyFiles/DummyNotExecutable.fs new file mode 100644 index 00000000..e69de29b diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 21c768db..e32fe7a4 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -5,6 +5,8 @@ open System.IO open NUnit.Framework open NUnit.Framework.Constraints +open Fsdk +open Fsdk.Process open FileConventions @@ -549,3 +551,38 @@ let NonVerboseFlagsInGitHubCI6() = )) Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false) + + +[] +let IsExecutableTest1() = + let filePath = + Path.Combine(__SOURCE_DIRECTORY__, "DummyFiles", "DummyExecutable.fsx") + + Fsdk + .Process + .Execute( + { + Command = "chmod" + Arguments = sprintf "+x %s" filePath + }, + Echo.All + ) + .UnwrapDefault() + |> ignore + + let fileInfo = (FileInfo filePath) + Assert.That(IsExecutable fileInfo, Is.EqualTo true) + + +[] +let IsExecutableTest2() = + let fileInfo = + (FileInfo( + Path.Combine( + __SOURCE_DIRECTORY__, + "DummyFiles", + "DummyNotExecutable.fs" + ) + )) + + Assert.That(IsExecutable fileInfo, Is.EqualTo false) diff --git a/src/FileConventions.Test/FileConventions.Test.fsproj b/src/FileConventions.Test/FileConventions.Test.fsproj index 656568a1..88064c27 100644 --- a/src/FileConventions.Test/FileConventions.Test.fsproj +++ b/src/FileConventions.Test/FileConventions.Test.fsproj @@ -19,6 +19,7 @@ + diff --git a/src/FileConventions/FileConventions.fsproj b/src/FileConventions/FileConventions.fsproj index 02d61dda..9c8c6d17 100644 --- a/src/FileConventions/FileConventions.fsproj +++ b/src/FileConventions/FileConventions.fsproj @@ -10,4 +10,9 @@ + + + + + diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 5ef78b15..6a5ea374 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -5,6 +5,9 @@ open System.IO open System.Linq open System.Text.RegularExpressions +open Mono +open Mono.Unix.Native + let HasCorrectShebang(fileInfo: FileInfo) = let fileText = File.ReadLines fileInfo.FullName @@ -383,3 +386,7 @@ let NonVerboseFlags(fileInfo: FileInfo) = |> Seq.length numInvalidFlags > 0 + +let IsExecutable(fileInfo: FileInfo) = + let hasExecuteAccess = Syscall.access(fileInfo.FullName, AccessModes.X_OK) + hasExecuteAccess = 0