Skip to content

Commit

Permalink
show statusCheck documentation on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Oct 24, 2024
1 parent 7854071 commit e8d8200
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 34 deletions.
37 changes: 23 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ defaults:
shell: pwsh

jobs:
check_documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
- run: dotnet run --project src/DocumentationGenerator/DocumentationGenerator.csproj
- run: git status
if: failure()

compute_package_version:
runs-on: ubuntu-latest
outputs:
Expand All @@ -47,9 +56,9 @@ jobs:
env:
RepositoryBranch: ${{github.ref}}
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4
uses: actions/setup-dotnet@v4

- run: dotnet run --project src/ListDotNetTypes/ListDotNetTypes.csproj -- src/Meziantou.Analyzer/Resources/

Expand All @@ -69,7 +78,7 @@ jobs:
- run: dotnet pack src/Meziantou.Analyzer.pack.csproj --configuration Release --no-build /p:Version=${{ needs.compute_package_version.outputs.package_version }}
- run: dotnet pack src/Meziantou.Analyzer.Annotations/Meziantou.Analyzer.Annotations.csproj --configuration Release

- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
Expand All @@ -80,10 +89,10 @@ jobs:
runs-on: ubuntu-latest
needs: [ create_nuget ]
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- uses: actions/checkout@v4
- name: Setup .NET Core (global.json)
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
uses: actions/setup-dotnet@v4
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
Expand Down Expand Up @@ -113,12 +122,12 @@ jobs:
roslyn-version: [ 'roslyn3.8', 'roslyn4.2', 'roslyn4.4', 'roslyn4.6', 'roslyn4.8', 'default' ]
fail-fast: false
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- uses: actions/checkout@v4
- name: Setup .NET Core (global.json)
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4
uses: actions/setup-dotnet@v4
- run: dotnet test --configuration ${{ matrix.configuration }} --logger trx --logger "GitHubActions;report-warnings=false" --collect:"XPlat Code Coverage" --blame-hang --blame-hang-timeout 2min --results-directory "${{ env.TestResultsDirectory }}" /p:WarningsAsErrors=true /p:RoslynVersion=${{ matrix.roslyn-version}}
name: Run tests
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.runs-on }}-${{ matrix.roslyn-version }}-${{ matrix.configuration }}
Expand All @@ -128,17 +137,17 @@ jobs:

deploy:
runs-on: 'ubuntu-latest'
needs: [ validate_nuget, build_and_test ]
needs: [ check_documentation, validate_nuget, build_and_test ]
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Setup .NET Core
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4
uses: actions/setup-dotnet@v4
- run: |
Write-Host "Current ref: $env:GITHUB_REF"
Write-Host "Searching nupkg in folder: ${{ env.NuGetDirectory }}"
Expand Down Expand Up @@ -167,7 +176,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- uses: actions/checkout@v4
- run: 'gh release create "${{ needs.compute_package_version.outputs.package_version }}" --generate-notes --notes "NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/${{ needs.compute_package_version.outputs.package_version }}>"'
env:
GH_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion .github/workflows/close-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
issues: write
pull-requests: write
steps:
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9
- uses: actions/stale@v9
with:
days-before-issue-stale: 60
days-before-issue-close: 14
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Meziantou.DotNet.CodingStandard" Version="1.0.125">
<PackageReference Include="Meziantou.DotNet.CodingStandard" Version="1.0.135">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Polyfill" Version="1.0.39">
<PackageReference Include="Meziantou.Polyfill" Version="1.0.40">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ If you are already using other analyzers, you can check [which rules are duplica
|[MA0162](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0162.md)|Usage|Use Process.Start overload with ProcessStartInfo|ℹ️|||
|[MA0163](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0163.md)|Usage|UseShellExecute must be false when redirecting standard input or output|⚠️|✔️||
|[MA0164](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0164.md)|Style|Use parentheses to make not pattern clearer|⚠️|✔️|✔️|
|[MA0165](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0165.md)|Usage|Make interpolated string|👻|✔️|✔️|

<!-- rules -->

Expand Down
3 changes: 2 additions & 1 deletion src/DocumentationGenerator/DocumentationGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Meziantou.Framework.FullPath" Version="1.0.13" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 30 additions & 8 deletions src/DocumentationGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
using System.Text;
using System.Text.Encodings.Web;
using System.Text.RegularExpressions;
using Meziantou.Framework;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;

if (args.Length == 0)
if (!FullPath.CurrentDirectory().TryFindFirstAncestorOrSelf(p => Directory.Exists(p / ".git"), out var outputFolder))
{
Console.Error.WriteLine("You must specify the output folder");
return;
Console.WriteLine("Cannot find the current git folder");
return 1;
}

var outputFolder = Path.GetFullPath(args[0]);
var fileWritten = 0;

var assemblies = new[] { typeof(Meziantou.Analyzer.Rules.CommaAnalyzer).Assembly, typeof(Meziantou.Analyzer.Rules.CommaFixer).Assembly };
var diagnosticAnalyzers = assemblies.SelectMany(assembly => assembly.GetExportedTypes())
Expand Down Expand Up @@ -59,14 +60,14 @@
var readmeContent = await File.ReadAllTextAsync(readmePath);
var newContent = Regex.Replace(readmeContent, "(?<=<!-- rules -->\\r?\\n).*(?=<!-- rules -->)", "\n" + GenerateRulesTable(diagnosticAnalyzers, codeFixProviders, addTitle: false) + "\n", RegexOptions.Singleline);
newContent = Regex.Replace(newContent, "(?<=<!-- suppressions -->\\r?\\n).*(?=<!-- suppressions -->)", "\n" + GenerateSuppressorsTable(diagnosticSuppressors) + "\n", RegexOptions.Singleline);
await File.WriteAllTextAsync(readmePath, newContent);
WriteFileIfChanged(readmePath, newContent);
}

// Update doc readme
{
var path = Path.GetFullPath(Path.Combine(outputFolder, "docs", "README.md"));
Console.WriteLine(path);
await File.WriteAllTextAsync(path, sb.ToString());
WriteFileIfChanged(path, sb.ToString());
}

// Update title in rule pages
Expand All @@ -79,15 +80,36 @@
{
var lines = await File.ReadAllLinesAsync(detailPath);
lines[0] = title;
File.WriteAllLines(detailPath, lines);
WriteFileIfChanged(detailPath, string.Join('\n', lines) + "\n");
}
else
{
await File.WriteAllTextAsync(detailPath, title);
WriteFileIfChanged(detailPath, title);
}
}
}

return fileWritten;

void WriteFileIfChanged(string path, string content)
{
content = content.ReplaceLineEndings("\n");

if (!File.Exists(path))
{
File.WriteAllText(path, content);
fileWritten++;
return;
}

var existingContent = File.ReadAllText(path).ReplaceLineEndings();
if (existingContent != content)
{
File.WriteAllText(path, content);
fileWritten++;
}
}

static string GenerateRulesTable(List<DiagnosticAnalyzer> diagnosticAnalyzers, List<CodeFixProvider> codeFixProviders, bool addTitle = true)
{
var sb = new StringBuilder();
Expand Down
8 changes: 0 additions & 8 deletions src/DocumentationGenerator/Properties/launchSettings.json

This file was deleted.

0 comments on commit e8d8200

Please sign in to comment.