Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force Tool Restore and Formatting. Build for Debug and Release Configuration #277

Merged
merged 8 commits into from
Sep 17, 2023
Merged
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
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>
Comment on lines +15 to +19
Copy link
Owner Author

@TheAngryByrd TheAngryByrd Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tarmil, I used the Directory.Build.targets file from FSharp.SystemTextJson but I still had to make some changes to make it work from a complete clean clone.

Specifically the MakeDir to ensure the path exists and the BeforeTargets=PaketRestore.

Tagging you in case you want to use this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch indeed!


<!-- 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