Skip to content

Commit a03d440

Browse files
authored
Msbuild unformatted files are no longer treated as error on linux (#1396)
The changes for #1311 seem to work in windows, but cause problems in linux. Files that aren't formatted are no longer treated as errors. closes #1357
1 parent b48176e commit a03d440

File tree

12 files changed

+118
-17
lines changed

12 files changed

+118
-17
lines changed

.csharpierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Uploads/
1+
Uploads/
2+
3+
Tests/MsBuild/TestCases/

.github/workflows/validate_pull_request.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ jobs:
2727
dotnet tool restore
2828
dotnet csharpier . --check
2929
test_msbuild:
30-
runs-on: ubuntu-latest
30+
strategy:
31+
matrix:
32+
os: [ ubuntu-latest, windows-latest ]
33+
runs-on: ${{ matrix.os }}
3134
name: Test CSharpier.MSBuild
3235
steps:
3336
- uses: actions/checkout@v2
3437
- uses: actions/setup-dotnet@v3
35-
- run: |
38+
- env:
39+
GithubOS: ${{matrix.os}}
40+
run: |
3641
pwsh ./Tests/MsBuild/Run.ps1
37-

Src/CSharpier.MsBuild/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ One way to test the changes in the build/* files
44
- Edit those files at `C:\Users\[Username]\.nuget\packages\csharpier.msbuild\[VersionNumber]\build`
55
- Ensure you revert those files and make the same changes to the files here.
66

7-
Another way
8-
- the validate PR GH action does this, currently only uses the net8 sdk
9-
- dotnet pack Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj -o nupkg /p:Version=0.0.1
10-
- docker build -f ./Tests/CSharpier.MsBuild.Test/Dockerfile .
7+
Some automated tests exist
8+
- the validate PR GH action runs these
9+
- cd ./Tests/MsBuild
10+
- ./Run.ps1 - some of these don't seem to work well locally
11+
12+
Other things that would be really really nice to automate
13+
- formats files in debug
14+
- formats files if told to in release
15+
- checks files if told to in debug
16+
- log levels

Tests/MsBuild/.csharpierignore

Whitespace-only changes.

Tests/MsBuild/Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
</Project>

Tests/MsBuild/Run.ps1

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ if (Test-Path $basePath) {
1616

1717
New-Item $basePath -ItemType Directory | Out-Null
1818

19-
$failureMessage = ""
19+
$failureMessages = @()
2020

2121
foreach ($scenario in $scenarios) {
22+
# these fail on windows in GH and because they use docker for the scenarios we don't need to run them twice anyway
23+
if ($env:GithubOS -eq "windows-latest") {
24+
continue
25+
}
26+
2227
Write-Host "::group::$($scenario.name)"
2328

2429
$scenarioPath = Join-Path $basePath $scenario.name
30+
Write-Host $scenarioPath
2531
New-Item $scenarioPath -ItemType Directory | Out-Null
2632

2733
$dockerFile = Join-Path $scenarioPath "DockerFile"
@@ -38,7 +44,7 @@ RUN dotnet build -c Release
3844
$csprojFile = Join-Path $scenarioPath "Project.csproj"
3945

4046
$csharpierFrameworkVersion = ""
41-
if ($null -ne $scenario.csharpier_frameworkVersion) {
47+
if ([bool]($scenario.PSobject.Properties.name -match "csharpier_frameworkVersion")) {
4248
$csharpierFrameworkVersion = "
4349
<CSharpier_FrameworkVersion>$($scenario.csharpier_frameworkVersion)</CSharpier_FrameworkVersion>
4450
"
@@ -61,14 +67,47 @@ RUN dotnet build -c Release
6167
docker build . -f $dockerFile
6268

6369
if ($LASTEXITCODE -ne 0) {
64-
$failureMessage += "::error::The scenario $($scenario.name) failed to build. See the logs above for details`n"
70+
$failureMessages += "The scenario $($scenario.name) failed to build. See the logs above for details"
6571
}
6672

6773
Write-Host "::endgroup::"
6874
}
6975

70-
if ($failureMessage -ne "") {
71-
Write-Host $failureMessage
76+
77+
Write-Host "::group::UnformattedFileCausesError"
78+
$output = [TestHelper]::RunTestCase("UnformattedFileCausesError", $true)
79+
Write-Host "::endgroup::"
80+
81+
Write-Host "::group::FileThatCantCompileCausesOneError"
82+
$output = [TestHelper]::RunTestCase("FileThatCantCompileCausesOneError", $true)
83+
if (-not($output.Contains("1 Error(s)"))) {
84+
$failureMessages += "The TestCase FileThatCantCompileCausesOneError did not contain the text '1 Error(s)1"
85+
}
86+
87+
Write-Host "::endgroup::"
88+
89+
if ($failureMessages.Length -ne 0) {
90+
foreach ($message in $failureMessages) {
91+
Write-Host "::error::$message`n"
92+
}
7293
exit 1
7394
}
7495

96+
class TestHelper {
97+
static [string] RunTestCase([string] $testCase, [bool] $expectErrorCode) {
98+
$output = (& dotnet build -c Release ./TestCases/$($testCase)/Project.csproj) | Out-String
99+
Write-Host $output
100+
101+
$expectedExitCode = 0
102+
if ($expectErrorCode -eq $true) {
103+
$expectedExitCode = 1
104+
}
105+
106+
if ($LASTEXITCODE -ne $expectedExitCode) {
107+
$failureMessages += "The TestCase $testCase did not return an exit code of $expectedExitCode"
108+
}
109+
110+
return $output
111+
}
112+
}
113+

Tests/MsBuild/Scenarios.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
[
22
{
3-
"name": "sdk:8.0_netstandard2.0",
3+
"name": "sdk-8.0_netstandard2.0",
44
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
55
"targetFrameworks": "netstandard2.0"
66
},
77
{
8-
"name": "sdk:8.0_net8.0-windows",
8+
"name": "sdk-8.0_net8.0-windows",
99
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
1010
"targetFrameworks": "net8.0-windows"
1111
},
1212
{
13-
"name": "sdk:8.0_net6.0;net7.07",
13+
"name": "sdk-8.0_net6.0;net7.07",
1414
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
1515
"targetFrameworks": "net6.0;net7.0"
1616
},
1717
{
18-
"name": "sdk:8.0_csharpier-net8.0",
18+
"name": "sdk-8.0_csharpier-net8.0",
1919
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
2020
"targetFrameworks": "netstandard2.0",
2121
"csharpier_frameworkVersion": "net8.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace Net8;
2+
3+
public class Class1
4+
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="CSharpier.MsBuild" Version="0.0.1">
8+
<PrivateAssets>all</PrivateAssets>
9+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
10+
</PackageReference>
11+
</ItemGroup>
12+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="CSharpier.MsBuild" Version="0.0.1">
8+
<PrivateAssets>all</PrivateAssets>
9+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
10+
</PackageReference>
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)