1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

[github actions] Add custom source validator

This commit is contained in:
Oliver Booth 2022-04-21 19:47:09 +01:00
parent 47bd3e1274
commit 9811a820ba
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 94 additions and 0 deletions

34
.github/workflows/source_validator.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Source Validator
on:
push:
branches:
- master
- develop
jobs:
source_validator:
runs-on: ubuntu-latest
if: "!contains(format('{0} {1}', github.event.head_commit.message, github.event.pull_request.title), '[ci-skip]')"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Add GitHub NuGet source
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Debug
- name: Run Source Validation
run: dotnet run --project X10D.SourceValidator ./X10D/src

View File

@ -0,0 +1,46 @@
using System.Text;
var directories = new Stack<string>(Directory.GetDirectories(args[0]));
var problems = 0;
var files = 0;
while (directories.Count > 0)
{
string path = Path.GetFullPath(directories.Pop());
foreach (string directory in Directory.EnumerateDirectories(path))
{
directories.Push(directory);
}
foreach (string file in Directory.EnumerateFiles(path, "*.cs"))
{
files++;
await using var stream = File.OpenRead(file);
using var reader = new StreamReader(stream, Encoding.UTF8);
var lineNumber = 1;
while (await reader.ReadLineAsync() is { } line)
{
if (line.Length > 130)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Out.WriteLine($"{file}({lineNumber}): Line is too long ({line.Length})");
Console.ResetColor();
problems++;
}
else if (line.Length > 0 && char.IsWhiteSpace(line[^1]))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Out.WriteLine($"{file}({lineNumber}): Line contains trailing whitespace");
Console.ResetColor();
problems++;
}
lineNumber++;
}
}
}
Console.Out.WriteLine($"Finished scanning {files} files, {problems} problems encountered.");
return problems;

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\X10D\X10D.csproj"/>
</ItemGroup>
</Project>