Skip to content

Commit

Permalink
Benchmarking and Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed May 16, 2024
1 parent 34d2abd commit e844250
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
branches:
- "main"

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace }}/nuget

permissions:
# deployments permission to deploy GitHub pages website
deployments: write
# contents permission to update benchmark contents in gh-pages branch
contents: write

jobs:
benchmark:
name: Performance regression check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Run benchmark
run: cd benchmarks && dotnet run -c Release --exporters json --filter '*'

- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
with:
name: Benchmark.Net Benchmark
tool: 'benchmarkdotnet'
output-file-path: Benchmarking/Benchmarks/BenchmarkDotNet.Artifacts/results/Benchmarks.ResolveBenchmarks-report-full-compressed.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
summary-always: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
103 changes: 103 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build and Test
on:
push:
branches:
- "main"
pull_request:
branches:
- "*"
release:
types:
- published

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace }}/nuget

defaults:
run:
shell: sh

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Restore
run: dotnet restore yang-compiler.sln
- name: Build
run: dotnet build yang-compiler.sln --no-restore
- name: Test
run: dotnet test yang-compiler.sln --no-build --no-restore

pack-release:
if: github.event_name == 'release'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Pack Generator
run: dotnet pack TODO.csproj -o "${{ env.NuGetDirectory }}" --property:RepositoryCommit="${{ env.COMMIT_SHA }}" --property:InformationalVersion="${{ github.ref_name }}" --property:AssemblyVersion="${{ github.ref_name }}" --property:FileVersion="${{ github.ref_name }}" --property:Version="${{ github.ref_name }}"
- name: Pack Attributes
run: dotnet pack TODO.csproj -o "${{ env.NuGetDirectory }}" --property:RepositoryCommit="${{ env.COMMIT_SHA }}" --property:InformationalVersion="${{ github.ref_name }}" --property:AssemblyVersion="${{ github.ref_name }}" --property:FileVersion="${{ github.ref_name }}" --property:Version="${{ github.ref_name }}"
- uses: actions/upload-artifact@v4
with:
name: nuget-packages
if-no-files-found: error
retention-days: 1
path: ${{ env.NuGetDirectory }}/*.nupkg

deploy:
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [pack-release]
steps:
- uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ${{ env.NuGetDirectory }}
- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Publish Nuget packages
run: |
for file in $(find "${{ env.NuGetDirectory }}" -type f -name "*.nupkg"); do
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json
done
benchmark:
name: Performance regression check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Run benchmark
run: cd benchmarks && dotnet run -c Release --exporters json --filter '*'

- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
with:
name: Benchmark.Net Benchmark
tool: 'benchmarkdotnet'
output-file-path: benchmarks/BenchmarkDotNet.Artifacts/results/Benchmarks.ResolveBenchmarks-report-full-compressed.json
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1"/>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="1.1.1"/>
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.9.2"/>
<PackageVersion Include="Antlr4.Runtime.Standard" Version="4.13.1"/>
<PackageVersion Include="Antlr4BuildTasks" Version="12.8.0"/>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12"/>
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using YangParser;
using YangParser.SemanticModel;

namespace Benchmarks;

[JsonExporterAttribute.Full]
[JsonExporterAttribute.FullCompressed]
public class ParsingBenchmarks
{
private string source;
private YangStatement statement;

[GlobalSetup]
public void Setup()
{
source = File.ReadAllText("../../../../lin.yang");
statement = Parser.Parse("lin.yang", source);
}

[Benchmark]
public YangStatement Parse() => Parser.Parse("lin.yang", source);

[Benchmark]
public IStatement SemanticModel() => StatementFactory.Create(statement);
}

internal static class Program
{
private static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<ParsingBenchmarks>();
}
}
24 changes: 24 additions & 0 deletions benchmarks/benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\YangParser\YangParser.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="lin.yang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
Loading

0 comments on commit e844250

Please sign in to comment.