Skip to content

Commit 39a832d

Browse files
authored
More refinements (#277)
* Do dotnet tool restore in targets file * Ensure formatting * At least 7 on build machines * dont format so often * debug ci part 1 * debug ci part 1 * debug ci part 1 * Allow for release/debug builds
1 parent 807cdfd commit 39a832d

File tree

19 files changed

+299
-247
lines changed

19 files changed

+299
-247
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ on:
1111
jobs:
1212
build:
1313
strategy:
14+
fail-fast: false
1415
matrix:
16+
configuration: [Debug, Release]
1517
os: [ubuntu-latest, windows-latest, macOS-latest]
1618
runs-on: ${{ matrix.os }}
1719

@@ -23,16 +25,19 @@ jobs:
2325
global-json-file: global.json
2426
dotnet-version: |
2527
6.x
28+
7.x
2629
2730
- name: Build via Bash
2831
if: runner.os != 'Windows'
2932
run: |
3033
chmod +x ./build.sh
3134
./build.sh IntegrationTests
3235
env:
36+
CONFIGURATION: ${{ matrix.configuration }}
3337
CI: true
3438
- name: Build via Windows
3539
if: runner.os == 'Windows'
3640
run: ./build.cmd IntegrationTests
3741
env:
42+
CONFIGURATION: ${{ matrix.configuration }}
3843
CI: true

Content/Console/.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
build:
1818
strategy:
1919
matrix:
20+
configuration: [Debug, Release]
2021
os: [ubuntu-latest, windows-latest, macOS-latest]
2122
runs-on: ${{ matrix.os }}
2223

@@ -29,6 +30,7 @@ jobs:
2930
with:
3031
dotnet-version: |
3132
6.x
33+
7.x
3234
global-json-file: global.json
3335

3436
- name: Build
@@ -39,11 +41,13 @@ jobs:
3941
chmod +x ./build.sh
4042
./build.sh
4143
env:
44+
CONFIGURATION: ${{ matrix.configuration }}
4245
CI: true
4346
- name: Build
4447
if: runner.os == 'Windows'
4548
run: |
4649
dotnet --info
4750
./build.cmd
4851
env:
52+
CONFIGURATION: ${{ matrix.configuration }}
4953
CI: true

Content/Console/Directory.Build.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
<!--
2+
This file allows overriding of properties for all projects in the directory.
3+
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
4+
-->
5+
16
<Project>
27
<PropertyGroup>
3-
<!-- summary is not migrated from project.json, but you can use the <Description> property for that if needed. -->
48
<PackageTags>f#, fsharp</PackageTags>
59
<PackageProjectUrl>https://github.com/MyGithubUsername/MyLib.1</PackageProjectUrl>
610
<PackageLicenseUrl>https://github.com/MyGithubUsername/MyLib.1/blob/master/LICENSE.md</PackageLicenseUrl>
711
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
812
<RepositoryType>git</RepositoryType>
913
<Authors>MyGithubUsername</Authors>
1014
<RepositoryUrl>https://github.com/MyGithubUsername/MyLib.1</RepositoryUrl>
11-
<!-- owners is not supported in MSBuild -->
1215
</PropertyGroup>
1316
<PropertyGroup>
1417
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
This file allows overriding of properties for all projects in the directory.
3+
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
4+
-->
5+
<Project>
6+
7+
<PropertyGroup>
8+
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
9+
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
10+
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)</_DotnetToolRestoreOutputFile>
11+
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild</_DotnetFantomasOutputFile>
12+
</PropertyGroup>
13+
14+
<!-- Make sure that dotnet tools (including paket) are restored before restoring any project -->
15+
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences;PaketRestore" Inputs="$(_DotnetToolManifestFile)" Outputs="$(_DotnetToolRestoreOutputFile)">
16+
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
17+
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
18+
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
19+
</Target>
20+
21+
<!-- Make sure that files are formatted before building -->
22+
<Target Name="Format" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
23+
<Exec Command="dotnet fantomas ." StandardOutputImportance="High" StandardErrorImportance="High" />
24+
<Touch Files="$(_DotnetFantomasOutputFile)" AlwaysCreate="True" ForceTouch="True" />
25+
</Target>
26+
</Project>

Content/Console/build.cmd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
echo Restoring dotnet tools...
2-
dotnet tool restore
3-
41
dotnet run --project ./build/build.fsproj -- -t %*

Content/Console/build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
set -eu
44
set -o pipefail
55

6-
echo "Restoring dotnet tools..."
7-
dotnet tool restore
8-
96
FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@"

Content/Console/build/build.fs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ let environVarAsBoolOrDefault varName defaultValue =
2929
with _ ->
3030
defaultValue
3131

32+
33+
let isCI = lazy environVarAsBoolOrDefault "CI" false
34+
3235
//-----------------------------------------------------------------------------
3336
// Metadata and Configuration
3437
//-----------------------------------------------------------------------------
3538

3639
let productName = "MyLib.1"
3740

41+
42+
let rootDirectory =
43+
__SOURCE_DIRECTORY__
44+
</> ".."
45+
3846
let sln =
3947
__SOURCE_DIRECTORY__
4048
</> ".."
@@ -175,16 +183,16 @@ let failOnBadExitAndPrint (p: ProcessResult) =
175183
failwithf "failed with exitcode %d" p.ExitCode
176184

177185
let rec retryIfInCI times fn =
178-
match Environment.environVarOrNone "CI" with
179-
| Some _ ->
186+
if isCI.Value then
180187
if times > 1 then
181188
try
182189
fn ()
183190
with _ ->
184191
retryIfInCI (times - 1) fn
185192
else
186193
fn ()
187-
| _ -> fn ()
194+
else
195+
fn ()
188196

189197

190198
let allReleaseChecks () =
@@ -544,14 +552,15 @@ let githubRelease _ =
544552
|> GitHub.publishDraft
545553
|> Async.RunSynchronously
546554

555+
547556
let formatCode _ =
548-
let result = dotnet.fantomas "."
557+
let result = dotnet.fantomas $"{rootDirectory}"
549558

550559
if not result.OK then
551560
printfn "Errors while formatting all files: %A" result.Messages
552561

553-
let checkFormatCode _ =
554-
let result = dotnet.fantomas "--check ."
562+
let checkFormatCode ctx =
563+
let result = dotnet.fantomas $"{rootDirectory} --check"
555564

556565
if result.ExitCode = 0 then
557566
Trace.log "No files need formatting"
@@ -560,6 +569,7 @@ let checkFormatCode _ =
560569
else
561570
Trace.logf "Errors while formatting: %A" result.Errors
562571

572+
563573
let initTargets () =
564574
BuildServer.install [ GitHubActions.Installer ]
565575

@@ -635,7 +645,7 @@ let initTargets () =
635645
==>! "GitRelease"
636646

637647
"DotnetRestore"
638-
==> "CheckFormatCode"
648+
=?> ("CheckFormatCode", isCI.Value)
639649
==> "DotnetBuild"
640650
// ==> "FSharpAnalyzers"
641651
==> "DotnetTest"

Content/Library/.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
build:
1313
strategy:
1414
matrix:
15+
configuration: [Debug, Release]
1516
os: [ubuntu-latest, windows-latest, macOS-latest]
1617
runs-on: ${{ matrix.os }}
1718

@@ -23,6 +24,7 @@ jobs:
2324
global-json-file: global.json
2425
dotnet-version: |
2526
6.x
27+
7.x
2628
2729
- name: Build via Bash
2830
if: runner.os != 'Windows'
@@ -31,10 +33,12 @@ jobs:
3133
./build.sh
3234
env:
3335
CI: true
36+
CONFIGURATION: ${{ matrix.configuration }}
3437
ENABLE_COVERAGE: true
3538
- name: Build via Windows
3639
if: runner.os == 'Windows'
3740
run: ./build.cmd
3841
env:
3942
CI: true
43+
CONFIGURATION: ${{ matrix.configuration }}
4044
ENABLE_COVERAGE: true

Content/Library/Directory.Build.props

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
<!--
3+
This file allows overriding of properties for all projects in the directory.
4+
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
5+
-->
6+
17
<Project>
28
<PropertyGroup>
39
<PackageTags>f#, fsharp</PackageTags>
@@ -13,7 +19,7 @@
1319
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1420
</PropertyGroup>
1521
<ItemGroup>
16-
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="/"/>
17-
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" Pack="true" PackagePath="/"/>
22+
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="/"/>
23+
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" Pack="true" PackagePath="/"/>
1824
</ItemGroup>
1925
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
This file allows overriding of properties for all projects in the directory.
3+
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
4+
-->
5+
<Project>
6+
7+
<PropertyGroup>
8+
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
9+
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
10+
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)</_DotnetToolRestoreOutputFile>
11+
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild</_DotnetFantomasOutputFile>
12+
</PropertyGroup>
13+
14+
<!-- Make sure that dotnet tools (including paket) are restored before restoring any project -->
15+
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences;PaketRestore" Inputs="$(_DotnetToolManifestFile)" Outputs="$(_DotnetToolRestoreOutputFile)">
16+
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
17+
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
18+
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
19+
</Target>
20+
21+
<!-- Make sure that files are formatted before building -->
22+
<Target Name="Format" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
23+
<Exec Command="dotnet fantomas ." StandardOutputImportance="High" StandardErrorImportance="High" />
24+
<Touch Files="$(_DotnetFantomasOutputFile)" AlwaysCreate="True" ForceTouch="True" />
25+
</Target>
26+
</Project>

0 commit comments

Comments
 (0)