Skip to content

Commit 552cc6e

Browse files
committed
GitHubCI,scripts: new script for fantomless
This way we can run it outside this repo.
1 parent 4d91a99 commit 552cc6e

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,4 @@ jobs:
250250
dotnet fsi scripts/runFSharpLint.fsx
251251
- name: fantomless
252252
run: |
253-
dotnet tool install fantomless-tool --version 4.7.997-prerelease
254-
dotnet fantomless --recurse .
255-
git diff --exit-code
253+
dotnet fsi scripts/runFantomless.fsx

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This is a repository that contains several useful things that other `nblockchain
2626
All in all, this is mainly documentation, and some tooling to detect bad practices.
2727

2828
More things to come:
29-
- Detect old versions of fantomas/fantomless being used.
29+
- Detect old versions of fantomas being used.
3030
- Detect old versions of .editorconfig or Directory.Build.props being used.
3131
- Detect GitHubCI bad practices, such as:
3232
* Missing important triggers such as push or pull_request, workflow_dispatch, schedule.

scripts/runFantomless.fsx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env -S dotnet fsi
2+
3+
open System
4+
open System.IO
5+
6+
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
7+
8+
open Fsdk
9+
10+
#load "../src/FileConventions/Helpers.fs"
11+
12+
let version = "4.7.997-prerelease"
13+
14+
let args = Fsdk.Misc.FsxOnlyArguments()
15+
16+
match args with
17+
| [] -> ()
18+
| _ ->
19+
failwithf
20+
"Too many arguments (this script doesn't receive any arguments): %A"
21+
args
22+
23+
let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo
24+
let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo
25+
26+
let targetDir, _ = Helpers.PreferLessDeeplyNestedDir currentDir rootDir
27+
28+
let formattingConfigFileName = ".editorconfig"
29+
30+
let formattingDefaultConfigFile =
31+
Path.Combine(rootDir.FullName, formattingConfigFileName) |> FileInfo
32+
33+
let formattingConfigFileInTargetDir =
34+
Path.Combine(targetDir.FullName, formattingConfigFileName) |> FileInfo
35+
36+
if formattingDefaultConfigFile.Exists
37+
&& not formattingConfigFileInTargetDir.Exists then
38+
formattingDefaultConfigFile.CopyTo(
39+
formattingConfigFileInTargetDir.FullName,
40+
false
41+
)
42+
|> ignore<FileInfo>
43+
44+
let formattingConfigFileInCurrentDir =
45+
Path.Combine(currentDir.FullName, formattingConfigFileName) |> FileInfo
46+
47+
if formattingDefaultConfigFile.Exists
48+
&& not formattingConfigFileInCurrentDir.Exists then
49+
formattingDefaultConfigFile.CopyTo(
50+
formattingConfigFileInCurrentDir.FullName,
51+
false
52+
)
53+
|> ignore<FileInfo>
54+
55+
Fsdk
56+
.Process
57+
.Execute(
58+
{
59+
Command = "dotnet"
60+
Arguments = sprintf "new tool-manifest --force"
61+
},
62+
Fsdk.Process.Echo.All
63+
)
64+
.UnwrapDefault()
65+
|> ignore<string>
66+
67+
Fsdk
68+
.Process
69+
.Execute(
70+
{
71+
Command = "dotnet"
72+
Arguments =
73+
sprintf "tool install fantomless-tool --version %s" version
74+
},
75+
Fsdk.Process.Echo.All
76+
)
77+
.UnwrapDefault()
78+
|> ignore<string>
79+
80+
Fsdk
81+
.Process
82+
.Execute(
83+
{
84+
Command = "dotnet"
85+
Arguments = sprintf "fantomless --recurse %s" targetDir.FullName
86+
},
87+
Fsdk.Process.Echo.All
88+
)
89+
.UnwrapDefault()
90+
|> ignore<string>
91+
92+
// If this is run in a GitHub Actions environment, check for changes
93+
if not String.IsNullOrWhitespace(Environment.GetEnvironmentVariable "GITHUB_EVENT_PATH") then
94+
Fsdk
95+
.Process
96+
.Execute(
97+
{
98+
Command = "git"
99+
Arguments = "diff --exit-code"
100+
},
101+
Fsdk.Process.Echo.All
102+
)
103+
.UnwrapDefault()
104+
|> ignore<string>

0 commit comments

Comments
 (0)