From ebae690540d4c8035aecec7cd0a8125b650f9a1c Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 9 Mar 2023 13:48:18 +0330 Subject: [PATCH 1/5] FileConventions.Test: add failing tests Add failing tests for IsExecutable function. --- .../DummyFiles/DummyExecutable.fsx | 0 .../DummyFiles/DummyNotExecutable.fs | 0 .../FileConventions.Test.fs | 37 +++++++++++++++++++ .../FileConventions.Test.fsproj | 1 + src/FileConventions/Library.fs | 4 ++ 5 files changed, 42 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/DummyExecutable.fsx create mode 100644 src/FileConventions.Test/DummyFiles/DummyNotExecutable.fs 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/Library.fs b/src/FileConventions/Library.fs index 5ef78b15..644c0d7a 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -383,3 +383,7 @@ let NonVerboseFlags(fileInfo: FileInfo) = |> Seq.length numInvalidFlags > 0 + +let IsExecutable(fileInfo: FileInfo) = + printfn "File path: %s" fileInfo.FullName + false From f319f27285d8fd0cb69d6ce6415352b2ff5c41b3 Mon Sep 17 00:00:00 2001 From: realmarv Date: Wed, 15 Feb 2023 16:57:55 +0330 Subject: [PATCH 2/5] FileConventions: implement IsExecutable function --- scripts/eofConvention.fsx | 2 ++ scripts/inconsistentVersionsInFSharpScripts.fsx | 2 ++ scripts/inconsistentVersionsInGitHubCI.fsx | 2 ++ scripts/mixedLineEndings.fsx | 2 ++ scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx | 2 ++ scripts/shebangConvention.fsx | 2 ++ scripts/unpinnedDotnetPackageVersions.fsx | 2 ++ scripts/unpinnedDotnetToolInstallVersions.fsx | 2 ++ scripts/unpinnedGitHubActionsImageVersions.fsx | 2 ++ scripts/unpinnedNugetPackageReferenceVersions.fsx | 2 ++ scripts/wrapLatestCommitMsg.fsx | 2 ++ src/FileConventions/FileConventions.fsproj | 5 +++++ src/FileConventions/Library.fs | 7 +++++-- 13 files changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/eofConvention.fsx b/scripts/eofConvention.fsx index 32bfb983..3f2b712b 100644 --- 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/inconsistentVersionsInFSharpScripts.fsx b/scripts/inconsistentVersionsInFSharpScripts.fsx index e7347996..93922496 100644 --- 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 index 80bd9a1c..f8041a45 100644 --- 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 index 7b404c98..427826a6 100644 --- 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 index 6ffb8801..54bd123d 100644 --- 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 index 89e1f0fb..965a9aad 100644 --- 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 index f4042960..56da33c0 100644 --- 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 index 0d99b0f4..92f35dcc 100644 --- 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 index 451bdeb6..07d31cc9 100644 --- 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 index 15aa408e..72e0e74b 100644 --- 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 index bf38c0d6..5b6592b0 100644 --- 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/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 644c0d7a..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 @@ -385,5 +388,5 @@ let NonVerboseFlags(fileInfo: FileInfo) = numInvalidFlags > 0 let IsExecutable(fileInfo: FileInfo) = - printfn "File path: %s" fileInfo.FullName - false + let hasExecuteAccess = Syscall.access(fileInfo.FullName, AccessModes.X_OK) + hasExecuteAccess = 0 From 52f8cae276770cbfbe568b37ea248dae959a9418 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 27 Feb 2023 11:26:43 +0330 Subject: [PATCH 3/5] scripts/executableConvention: add --- scripts/executableConvention.fsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/executableConvention.fsx diff --git a/scripts/executableConvention.fsx b/scripts/executableConvention.fsx new file mode 100644 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:" From 8c1980ff5567bdd1d426698d53a14d92b40a1c68 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 13 Mar 2023 11:33:40 +0330 Subject: [PATCH 4/5] GitHubCI: run executableConvention.fsx --- .github/workflows/CI.yml | 2 ++ scripts/checkCommits1by1.fsx | 0 scripts/compileFSharpScripts.fsx | 0 scripts/eofConvention.fsx | 0 scripts/executableConvention.fsx | 0 scripts/inconsistentVersionsInFSharpScripts.fsx | 0 scripts/inconsistentVersionsInGitHubCI.fsx | 0 scripts/mixedLineEndings.fsx | 0 scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx | 0 scripts/shebangConvention.fsx | 0 scripts/unpinnedDotnetPackageVersions.fsx | 0 scripts/unpinnedDotnetToolInstallVersions.fsx | 0 scripts/unpinnedGitHubActionsImageVersions.fsx | 0 scripts/unpinnedNugetPackageReferenceVersions.fsx | 0 scripts/wrapLatestCommitMsg.fsx | 0 15 files changed, 2 insertions(+) mode change 100644 => 100755 scripts/checkCommits1by1.fsx mode change 100644 => 100755 scripts/compileFSharpScripts.fsx mode change 100644 => 100755 scripts/eofConvention.fsx mode change 100644 => 100755 scripts/executableConvention.fsx mode change 100644 => 100755 scripts/inconsistentVersionsInFSharpScripts.fsx mode change 100644 => 100755 scripts/inconsistentVersionsInGitHubCI.fsx mode change 100644 => 100755 scripts/mixedLineEndings.fsx mode change 100644 => 100755 scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx mode change 100644 => 100755 scripts/shebangConvention.fsx mode change 100644 => 100755 scripts/unpinnedDotnetPackageVersions.fsx mode change 100644 => 100755 scripts/unpinnedDotnetToolInstallVersions.fsx mode change 100644 => 100755 scripts/unpinnedGitHubActionsImageVersions.fsx mode change 100644 => 100755 scripts/unpinnedNugetPackageReferenceVersions.fsx mode change 100644 => 100755 scripts/wrapLatestCommitMsg.fsx 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/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 diff --git a/scripts/executableConvention.fsx b/scripts/executableConvention.fsx old mode 100644 new mode 100755 diff --git a/scripts/inconsistentVersionsInFSharpScripts.fsx b/scripts/inconsistentVersionsInFSharpScripts.fsx old mode 100644 new mode 100755 diff --git a/scripts/inconsistentVersionsInGitHubCI.fsx b/scripts/inconsistentVersionsInGitHubCI.fsx old mode 100644 new mode 100755 diff --git a/scripts/mixedLineEndings.fsx b/scripts/mixedLineEndings.fsx old mode 100644 new mode 100755 diff --git a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx old mode 100644 new mode 100755 diff --git a/scripts/shebangConvention.fsx b/scripts/shebangConvention.fsx old mode 100644 new mode 100755 diff --git a/scripts/unpinnedDotnetPackageVersions.fsx b/scripts/unpinnedDotnetPackageVersions.fsx old mode 100644 new mode 100755 diff --git a/scripts/unpinnedDotnetToolInstallVersions.fsx b/scripts/unpinnedDotnetToolInstallVersions.fsx old mode 100644 new mode 100755 diff --git a/scripts/unpinnedGitHubActionsImageVersions.fsx b/scripts/unpinnedGitHubActionsImageVersions.fsx old mode 100644 new mode 100755 diff --git a/scripts/unpinnedNugetPackageReferenceVersions.fsx b/scripts/unpinnedNugetPackageReferenceVersions.fsx old mode 100644 new mode 100755 diff --git a/scripts/wrapLatestCommitMsg.fsx b/scripts/wrapLatestCommitMsg.fsx old mode 100644 new mode 100755 From fdd02558ddc834db4b12b5e2c7822d3023b7cb03 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 13 Mar 2023 12:02:40 +0330 Subject: [PATCH 5/5] ReadMe: update --- ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.