diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 426b63cf..2cea4465 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -250,6 +250,4 @@ jobs: dotnet fsi scripts/runFSharpLint.fsx - name: fantomless run: | - dotnet tool install fantomless-tool --version 4.7.997-prerelease - dotnet fantomless --recurse . - git diff --exit-code + dotnet fsi scripts/runFantomless.fsx diff --git a/ReadMe.md b/ReadMe.md index 2f9c75c6..7a321e57 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -26,7 +26,7 @@ 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 old versions of fantomas/fantomless being used. +- Detect old versions of fantomas being used. - Detect old versions of .editorconfig or Directory.Build.props being used. - Detect GitHubCI bad practices, such as: * Missing important triggers such as push or pull_request, workflow_dispatch, schedule. diff --git a/scripts/runFantomless.fsx b/scripts/runFantomless.fsx new file mode 100755 index 00000000..3ba4459f --- /dev/null +++ b/scripts/runFantomless.fsx @@ -0,0 +1,111 @@ +#!/usr/bin/env -S dotnet fsi + +open System +open System.IO + +#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" + +open Fsdk + +#load "../src/FileConventions/Helpers.fs" + +let version = "4.7.997-prerelease" + +let args = Fsdk.Misc.FsxOnlyArguments() + +match args with +| [] -> () +| _ -> + failwithf + "Too many arguments (this script doesn't receive any arguments): %A" + args + +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo +let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo + +let targetDir, _ = Helpers.PreferLessDeeplyNestedDir currentDir rootDir + +let formattingConfigFileName = ".editorconfig" + +let formattingDefaultConfigFile = + Path.Combine(rootDir.FullName, formattingConfigFileName) |> FileInfo + +let formattingConfigFileInTargetDir = + Path.Combine(targetDir.FullName, formattingConfigFileName) |> FileInfo + +if formattingDefaultConfigFile.Exists + && not formattingConfigFileInTargetDir.Exists then + formattingDefaultConfigFile.CopyTo( + formattingConfigFileInTargetDir.FullName, + false + ) + |> ignore + +let formattingConfigFileInCurrentDir = + Path.Combine(currentDir.FullName, formattingConfigFileName) |> FileInfo + +if formattingDefaultConfigFile.Exists + && not formattingConfigFileInCurrentDir.Exists then + formattingDefaultConfigFile.CopyTo( + formattingConfigFileInCurrentDir.FullName, + false + ) + |> ignore + +Fsdk + .Process + .Execute( + { + Command = "dotnet" + Arguments = sprintf "new tool-manifest --force" + }, + Fsdk.Process.Echo.All + ) + .UnwrapDefault() +|> ignore + +Fsdk + .Process + .Execute( + { + Command = "dotnet" + Arguments = + sprintf "tool install fantomless-tool --version %s" version + }, + Fsdk.Process.Echo.All + ) + .UnwrapDefault() +|> ignore + +Fsdk + .Process + .Execute( + { + Command = "dotnet" + Arguments = sprintf "fantomless --recurse %s" targetDir.FullName + }, + Fsdk.Process.Echo.All + ) + .UnwrapDefault() +|> ignore + +// If this is run in a GitHub Actions environment, check for changes +if + not + ( + String.IsNullOrWhiteSpace( + Environment.GetEnvironmentVariable "GITHUB_EVENT_PATH" + ) + ) +then + Fsdk + .Process + .Execute( + { + Command = "git" + Arguments = "diff --exit-code" + }, + Fsdk.Process.Echo.All + ) + .UnwrapDefault() + |> ignore