Skip to content

Commit

Permalink
More refinements (#277)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TheAngryByrd committed Sep 17, 2023
1 parent 807cdfd commit 39a832d
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 247 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ on:
jobs:
build:
strategy:
fail-fast: false
matrix:
configuration: [Debug, Release]
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}

Expand All @@ -23,16 +25,19 @@ jobs:
global-json-file: global.json
dotnet-version: |
6.x
7.x
- name: Build via Bash
if: runner.os != 'Windows'
run: |
chmod +x ./build.sh
./build.sh IntegrationTests
env:
CONFIGURATION: ${{ matrix.configuration }}
CI: true
- name: Build via Windows
if: runner.os == 'Windows'
run: ./build.cmd IntegrationTests
env:
CONFIGURATION: ${{ matrix.configuration }}
CI: true
4 changes: 4 additions & 0 deletions Content/Console/.github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
build:
strategy:
matrix:
configuration: [Debug, Release]
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}

Expand All @@ -29,6 +30,7 @@ jobs:
with:
dotnet-version: |
6.x
7.x
global-json-file: global.json

- name: Build
Expand All @@ -39,11 +41,13 @@ jobs:
chmod +x ./build.sh
./build.sh
env:
CONFIGURATION: ${{ matrix.configuration }}
CI: true
- name: Build
if: runner.os == 'Windows'
run: |
dotnet --info
./build.cmd
env:
CONFIGURATION: ${{ matrix.configuration }}
CI: true
7 changes: 5 additions & 2 deletions Content/Console/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!--
This file allows overriding of properties for all projects in the directory.
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
-->

<Project>
<PropertyGroup>
<!-- summary is not migrated from project.json, but you can use the <Description> property for that if needed. -->
<PackageTags>f#, fsharp</PackageTags>
<PackageProjectUrl>https://github.com/MyGithubUsername/MyLib.1</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/MyGithubUsername/MyLib.1/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<Authors>MyGithubUsername</Authors>
<RepositoryUrl>https://github.com/MyGithubUsername/MyLib.1</RepositoryUrl>
<!-- owners is not supported in MSBuild -->
</PropertyGroup>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down
26 changes: 26 additions & 0 deletions Content/Console/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
This file allows overriding of properties for all projects in the directory.
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
-->
<Project>

<PropertyGroup>
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)</_DotnetToolRestoreOutputFile>
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild</_DotnetFantomasOutputFile>
</PropertyGroup>

<!-- Make sure that dotnet tools (including paket) are restored before restoring any project -->
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences;PaketRestore" Inputs="$(_DotnetToolManifestFile)" Outputs="$(_DotnetToolRestoreOutputFile)">
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
</Target>

<!-- Make sure that files are formatted before building -->
<Target Name="Format" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
<Exec Command="dotnet fantomas ." StandardOutputImportance="High" StandardErrorImportance="High" />
<Touch Files="$(_DotnetFantomasOutputFile)" AlwaysCreate="True" ForceTouch="True" />
</Target>
</Project>
3 changes: 0 additions & 3 deletions Content/Console/build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
echo Restoring dotnet tools...
dotnet tool restore

dotnet run --project ./build/build.fsproj -- -t %*
3 changes: 0 additions & 3 deletions Content/Console/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
set -eu
set -o pipefail

echo "Restoring dotnet tools..."
dotnet tool restore

FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@"
24 changes: 17 additions & 7 deletions Content/Console/build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ let environVarAsBoolOrDefault varName defaultValue =
with _ ->
defaultValue


let isCI = lazy environVarAsBoolOrDefault "CI" false

//-----------------------------------------------------------------------------
// Metadata and Configuration
//-----------------------------------------------------------------------------

let productName = "MyLib.1"


let rootDirectory =
__SOURCE_DIRECTORY__
</> ".."

let sln =
__SOURCE_DIRECTORY__
</> ".."
Expand Down Expand Up @@ -175,16 +183,16 @@ let failOnBadExitAndPrint (p: ProcessResult) =
failwithf "failed with exitcode %d" p.ExitCode

let rec retryIfInCI times fn =
match Environment.environVarOrNone "CI" with
| Some _ ->
if isCI.Value then
if times > 1 then
try
fn ()
with _ ->
retryIfInCI (times - 1) fn
else
fn ()
| _ -> fn ()
else
fn ()


let allReleaseChecks () =
Expand Down Expand Up @@ -544,14 +552,15 @@ let githubRelease _ =
|> GitHub.publishDraft
|> Async.RunSynchronously


let formatCode _ =
let result = dotnet.fantomas "."
let result = dotnet.fantomas $"{rootDirectory}"

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

let checkFormatCode _ =
let result = dotnet.fantomas "--check ."
let checkFormatCode ctx =
let result = dotnet.fantomas $"{rootDirectory} --check"

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


let initTargets () =
BuildServer.install [ GitHubActions.Installer ]

Expand Down Expand Up @@ -635,7 +645,7 @@ let initTargets () =
==>! "GitRelease"

"DotnetRestore"
==> "CheckFormatCode"
=?> ("CheckFormatCode", isCI.Value)
==> "DotnetBuild"
// ==> "FSharpAnalyzers"
==> "DotnetTest"
Expand Down
4 changes: 4 additions & 0 deletions Content/Library/.github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
build:
strategy:
matrix:
configuration: [Debug, Release]
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}

Expand All @@ -23,6 +24,7 @@ jobs:
global-json-file: global.json
dotnet-version: |
6.x
7.x
- name: Build via Bash
if: runner.os != 'Windows'
Expand All @@ -31,10 +33,12 @@ jobs:
./build.sh
env:
CI: true
CONFIGURATION: ${{ matrix.configuration }}
ENABLE_COVERAGE: true
- name: Build via Windows
if: runner.os == 'Windows'
run: ./build.cmd
env:
CI: true
CONFIGURATION: ${{ matrix.configuration }}
ENABLE_COVERAGE: true
10 changes: 8 additions & 2 deletions Content/Library/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

<!--
This file allows overriding of properties for all projects in the directory.
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
-->

<Project>
<PropertyGroup>
<PackageTags>f#, fsharp</PackageTags>
Expand All @@ -13,7 +19,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="/"/>
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" Pack="true" PackagePath="/"/>
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="/"/>
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" Pack="true" PackagePath="/"/>
</ItemGroup>
</Project>
26 changes: 26 additions & 0 deletions Content/Library/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
This file allows overriding of properties for all projects in the directory.
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
-->
<Project>

<PropertyGroup>
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)</_DotnetToolRestoreOutputFile>
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild</_DotnetFantomasOutputFile>
</PropertyGroup>

<!-- Make sure that dotnet tools (including paket) are restored before restoring any project -->
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences;PaketRestore" Inputs="$(_DotnetToolManifestFile)" Outputs="$(_DotnetToolRestoreOutputFile)">
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
</Target>

<!-- Make sure that files are formatted before building -->
<Target Name="Format" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
<Exec Command="dotnet fantomas ." StandardOutputImportance="High" StandardErrorImportance="High" />
<Touch Files="$(_DotnetFantomasOutputFile)" AlwaysCreate="True" ForceTouch="True" />
</Target>
</Project>
3 changes: 0 additions & 3 deletions Content/Library/build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
echo Restoring dotnet tools...
dotnet tool restore

dotnet run --project ./build/build.fsproj -- -t %*
3 changes: 0 additions & 3 deletions Content/Library/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
set -eu
set -o pipefail

echo "Restoring dotnet tools..."
dotnet tool restore

FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@"
Loading

0 comments on commit 39a832d

Please sign in to comment.