Skip to content
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
4 changes: 1 addition & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
111 changes: 111 additions & 0 deletions scripts/runFantomless.fsx
Original file line number Diff line number Diff line change
@@ -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<FileInfo>

let formattingConfigFileInCurrentDir =
Path.Combine(currentDir.FullName, formattingConfigFileName) |> FileInfo

if formattingDefaultConfigFile.Exists
&& not formattingConfigFileInCurrentDir.Exists then
formattingDefaultConfigFile.CopyTo(
formattingConfigFileInCurrentDir.FullName,
false
)
|> ignore<FileInfo>

Fsdk
.Process
.Execute(
{
Command = "dotnet"
Arguments = sprintf "new tool-manifest --force"
},
Fsdk.Process.Echo.All
)
.UnwrapDefault()
|> ignore<string>

Fsdk
.Process
.Execute(
{
Command = "dotnet"
Arguments =
sprintf "tool install fantomless-tool --version %s" version
},
Fsdk.Process.Echo.All
)
.UnwrapDefault()
|> ignore<string>

Fsdk
.Process
.Execute(
{
Command = "dotnet"
Arguments = sprintf "fantomless --recurse %s" targetDir.FullName
},
Fsdk.Process.Echo.All
)
.UnwrapDefault()
|> ignore<string>

// 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<string>