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

Msbuild unformatted files are no longer treated as error on linux #1396

Merged
merged 6 commits into from
Dec 7, 2024
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
4 changes: 3 additions & 1 deletion .csharpierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Uploads/
Uploads/

Tests/MsBuild/TestCases/
10 changes: 7 additions & 3 deletions .github/workflows/validate_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ jobs:
dotnet tool restore
dotnet csharpier . --check
test_msbuild:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
name: Test CSharpier.MSBuild
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v3
- run: |
- env:
GithubOS: ${{matrix.os}}
run: |
pwsh ./Tests/MsBuild/Run.ps1

14 changes: 10 additions & 4 deletions Src/CSharpier.MsBuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ One way to test the changes in the build/* files
- Edit those files at `C:\Users\[Username]\.nuget\packages\csharpier.msbuild\[VersionNumber]\build`
- Ensure you revert those files and make the same changes to the files here.

Another way
- the validate PR GH action does this, currently only uses the net8 sdk
- dotnet pack Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj -o nupkg /p:Version=0.0.1
- docker build -f ./Tests/CSharpier.MsBuild.Test/Dockerfile .
Some automated tests exist
- the validate PR GH action runs these
- cd ./Tests/MsBuild
- ./Run.ps1 - some of these don't seem to work well locally

Other things that would be really really nice to automate
- formats files in debug
- formats files if told to in release
- checks files if told to in debug
- log levels
Empty file added Tests/MsBuild/.csharpierignore
Empty file.
5 changes: 5 additions & 0 deletions Tests/MsBuild/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
49 changes: 44 additions & 5 deletions Tests/MsBuild/Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ if (Test-Path $basePath) {

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

$failureMessage = ""
$failureMessages = @()

foreach ($scenario in $scenarios) {
# these fail on windows in GH and because they use docker for the scenarios we don't need to run them twice anyway
if ($env:GithubOS -eq "windows-latest") {
continue
}

Write-Host "::group::$($scenario.name)"

$scenarioPath = Join-Path $basePath $scenario.name
Write-Host $scenarioPath
New-Item $scenarioPath -ItemType Directory | Out-Null

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

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

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

Write-Host "::endgroup::"
}

if ($failureMessage -ne "") {
Write-Host $failureMessage

Write-Host "::group::UnformattedFileCausesError"
$output = [TestHelper]::RunTestCase("UnformattedFileCausesError", $true)
Write-Host "::endgroup::"

Write-Host "::group::FileThatCantCompileCausesOneError"
$output = [TestHelper]::RunTestCase("FileThatCantCompileCausesOneError", $true)
if (-not($output.Contains("1 Error(s)"))) {
$failureMessages += "The TestCase FileThatCantCompileCausesOneError did not contain the text '1 Error(s)1"
}

Write-Host "::endgroup::"

if ($failureMessages.Length -ne 0) {
foreach ($message in $failureMessages) {
Write-Host "::error::$message`n"
}
exit 1
}

class TestHelper {
static [string] RunTestCase([string] $testCase, [bool] $expectErrorCode) {
$output = (& dotnet build -c Release ./TestCases/$($testCase)/Project.csproj) | Out-String
Write-Host $output

$expectedExitCode = 0
if ($expectErrorCode -eq $true) {
$expectedExitCode = 1
}

if ($LASTEXITCODE -ne $expectedExitCode) {
$failureMessages += "The TestCase $testCase did not return an exit code of $expectedExitCode"
}

return $output
}
}

8 changes: 4 additions & 4 deletions Tests/MsBuild/Scenarios.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[
{
"name": "sdk:8.0_netstandard2.0",
"name": "sdk-8.0_netstandard2.0",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "netstandard2.0"
},
{
"name": "sdk:8.0_net8.0-windows",
"name": "sdk-8.0_net8.0-windows",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "net8.0-windows"
},
{
"name": "sdk:8.0_net6.0;net7.07",
"name": "sdk-8.0_net6.0;net7.07",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "net6.0;net7.0"
},
{
"name": "sdk:8.0_csharpier-net8.0",
"name": "sdk-8.0_csharpier-net8.0",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "netstandard2.0",
"csharpier_frameworkVersion": "net8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Net8;

public class Class1
{

Check failure on line 4 in Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs

View workflow job for this annotation

GitHub Actions / Test CSharpier.MSBuild (ubuntu-latest)

} expected

Check failure on line 4 in Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs

View workflow job for this annotation

GitHub Actions / Test CSharpier.MSBuild (ubuntu-latest)

} expected

Check failure on line 4 in Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs

View workflow job for this annotation

GitHub Actions / Test CSharpier.MSBuild (windows-latest)

} expected

Check failure on line 4 in Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs

View workflow job for this annotation

GitHub Actions / Test CSharpier.MSBuild (windows-latest)

} expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions Tests/MsBuild/TestCases/UnformattedFileCausesError/Project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Net8;

public class Class1
{


}
10 changes: 10 additions & 0 deletions Tests/MsBuild/nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<packageSources>
<add key="Local" value="nupkg" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceMapping>
<packageSource key="Local">
<package pattern="CSharpier.MsBuild" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
Loading