Skip to content

Commit ef5891d

Browse files
committed
Add Benchmark project
* update workflow actions to replace github-script download with download-artifact * Run benchmarks as part of PR * Add benchmark summary to job
1 parent d34aa0f commit ef5891d

16 files changed

+364
-242
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ updates:
1111
# Check for updates to GitHub Actions every weekday
1212
interval: "weekly"
1313

14-
- package-ecosystem: "nuget"
14+
- package-ecosystem: "nuget"
1515
directory: "/src/NHapi.Base"
1616
schedule:
1717
interval: "weekly"
18-
- package-ecosystem: "nuget"
19-
directory: "/src/ModelGenerator"
18+
- package-ecosystem: "nuget"
19+
directory: "/src/ModelGenerator"
2020
schedule:
2121
interval: "weekly"
2222
- package-ecosystem: "nuget"

.github/workflows/build-status.yml

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,61 @@ jobs:
1212
matrix:
1313
os: [ubuntu-latest, windows-latest, macOS-latest]
1414
steps:
15-
- uses: actions/checkout@v4
16-
17-
- name: Setup .NET Core
18-
uses: actions/setup-dotnet@v4
19-
with:
20-
global-json-file: global.json
21-
22-
- name: Restore nHapi (Windows)
23-
if: matrix.os == 'windows-latest'
24-
run: |
25-
dotnet restore nHapi.sln --configfile build\.nuget\NuGet.config
26-
27-
- name: Restore nHapi (Non-Windows)
28-
if: matrix.os != 'windows-latest'
29-
run: |
30-
dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config
31-
32-
- name: Build nHapi
33-
run: |
34-
dotnet build nHapi.sln -c Release --no-restore
35-
36-
- name: Run tests for all target frameworks (Windows)
37-
if: matrix.os == 'windows-latest'
38-
run: |
39-
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --results-directory TestResults -c Release -f net462 --no-restore --no-build
40-
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
41-
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
42-
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --results-directory TestResults -c Release -f net462 --no-restore --no-build
43-
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
44-
45-
- name: Run tests for all target frameworks (Non-Windows)
46-
if: matrix.os != 'windows-latest'
47-
run: |
48-
dotnet test tests/NHapi.Base.NUnit/NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
49-
dotnet test tests/NHapi.NUnit.SourceGeneration/NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
50-
dotnet test tests/NHapi.NUnit/NHapi.NUnit.csproj --collect:"XPlat Code Coverage" --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
51-
52-
- name: Upload Code Coverage Report
53-
if: always() && matrix.os == 'ubuntu-latest'
54-
uses: actions/upload-artifact@v3
55-
with:
56-
name: coverage-reports
57-
path: |
58-
TestResults/
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup .NET Core
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
global-json-file: global.json
21+
22+
- name: Restore nHapi (Windows)
23+
if: matrix.os == 'windows-latest'
24+
run: |
25+
dotnet restore nHapi.sln --configfile build\.nuget\NuGet.config
26+
27+
- name: Restore nHapi (Non-Windows)
28+
if: matrix.os != 'windows-latest'
29+
run: |
30+
dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config
31+
32+
- name: Build nHapi
33+
run: |
34+
dotnet build nHapi.sln -c Release --no-restore
35+
36+
- name: Run tests for all target frameworks (Windows)
37+
if: matrix.os == 'windows-latest'
38+
run: |
39+
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --results-directory TestResults -c Release -f net462 --no-restore --no-build
40+
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
41+
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
42+
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --results-directory TestResults -c Release -f net462 --no-restore --no-build
43+
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
44+
45+
- name: Run Benchmatks (Windows)
46+
if: matrix.os == 'windows-latest'
47+
run: |
48+
dotnet run -c Release --project tests\NHapi.Benchmarks\NHapi.Benchmarks.csproj -f net8.0 --no-restore --no-build
49+
50+
- name: Run tests for all target frameworks (Non-Windows)
51+
if: matrix.os != 'windows-latest'
52+
run: |
53+
dotnet test tests/NHapi.Base.NUnit/NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
54+
dotnet test tests/NHapi.NUnit.SourceGeneration/NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
55+
dotnet test tests/NHapi.NUnit/NHapi.NUnit.csproj --collect:"XPlat Code Coverage" --results-directory TestResults -c Release -f net8.0 --no-restore --no-build
56+
57+
- name: Upload Benchmark Results
58+
if: always() && matrix.os == 'windows-latest'
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: benchmark-results
62+
path: BenchmarkDotNet.Artifacts\results
63+
64+
- name: Upload Code Coverage Report
65+
if: always() && matrix.os == 'ubuntu-latest'
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: coverage-reports
69+
path: TestResults/
5970

6071
publish-coverage-results:
6172
needs: build-and-test
@@ -66,8 +77,8 @@ jobs:
6677
steps:
6778
- uses: actions/checkout@v4
6879

69-
- name: 'Download artifact'
70-
uses: actions/download-artifact@v3
80+
- name: "Download artifact"
81+
uses: actions/download-artifact@v4
7182
with:
7283
name: coverage-reports
7384

@@ -83,3 +94,24 @@ jobs:
8394
with:
8495
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
8596
coverage-reports: ${{ steps.coverage-paths.outputs.COVERAGE_REPORT_PATHS }}
97+
98+
report-benchmark-results:
99+
needs: build-and-test
100+
name: Report Benchmark Results
101+
runs-on: ubuntu-latest
102+
# the build-and-test job might be skipped, we don't need to run this job then
103+
if: always()
104+
steps:
105+
- name: 'Download artifact'
106+
uses: actions/download-artifact@v4
107+
with:
108+
name: benchmark-results
109+
110+
- name: Report benchmark result
111+
uses: rhysd/github-action-benchmark@v1
112+
with:
113+
name: Benchmark.Net Benchmark
114+
tool: "benchmarkdotnet"
115+
output-file-path: BenchmarkDotNet.Artifacts/results/NHapi.Benchmarks.LargeEmbeddedFileTest-report-full-compressed.json
116+
auto-push: false
117+
summary-always: true

.github/workflows/codacy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ name: Codacy Security Scan
1515

1616
on:
1717
push:
18-
branches: [ master ]
18+
branches: [master]
1919
pull_request:
2020
# The branches below must be a subset of the branches above
21-
branches: [ master ]
21+
branches: [master]
2222
schedule:
23-
- cron: '17 1 * * 3'
23+
- cron: "17 1 * * 3"
2424

2525
permissions:
2626
contents: read
@@ -39,7 +39,7 @@ jobs:
3939

4040
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
4141
- name: Run Codacy Analysis CLI
42-
uses: codacy/codacy-analysis-cli-action@5cc54a75f9ad88159bb54046196d920e40e367a5
42+
uses: codacy/codacy-analysis-cli-action@v4
4343
with:
4444
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
4545
# You can also omit the token and run the tools that support default configurations

.github/workflows/codeql-analysis.yml

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,51 +44,50 @@ jobs:
4444
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
4545

4646
steps:
47-
- name: Checkout repository
48-
uses: actions/checkout@v4
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
4949

50-
# Initializes the CodeQL tools for scanning.
51-
- name: Initialize CodeQL
52-
uses: github/codeql-action/init@v3
53-
with:
54-
languages: ${{ matrix.language }}
55-
# If you wish to specify custom queries, you can do so here or in a config file.
56-
# By default, queries listed here will override any specified in a config file.
57-
# Prefix the list here with "+" to use these queries and those in the config file.
50+
# Initializes the CodeQL tools for scanning.
51+
- name: Initialize CodeQL
52+
uses: github/codeql-action/init@v3
53+
with:
54+
languages: ${{ matrix.language }}
55+
# If you wish to specify custom queries, you can do so here or in a config file.
56+
# By default, queries listed here will override any specified in a config file.
57+
# Prefix the list here with "+" to use these queries and those in the config file.
5858

59-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
60-
# queries: security-extended,security-and-quality
59+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
60+
# queries: security-extended,security-and-quality
6161

62+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
63+
# If this step fails, then you should remove it and run the build manually (see below)
64+
# - name: Autobuild
65+
# uses: github/codeql-action/autobuild@v3
6266

63-
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
64-
# If this step fails, then you should remove it and run the build manually (see below)
65-
# - name: Autobuild
66-
# uses: github/codeql-action/autobuild@v3
67+
- name: Setup .NET Core
68+
uses: actions/setup-dotnet@v4
69+
with:
70+
global-json-file: global.json
6771

68-
- name: Setup .NET Core
69-
uses: actions/setup-dotnet@v4
70-
with:
71-
global-json-file: global.json
72+
- name: Restore nHapi
73+
run: |
74+
dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config
7275
73-
- name: Restore nHapi
74-
run: |
75-
dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config
76+
- name: Build nHapi
77+
run: |
78+
dotnet build nHapi.sln -c Release --no-restore
7679
77-
- name: Build nHapi
78-
run: |
79-
dotnet build nHapi.sln -c Release --no-restore
80+
# ℹ️ Command-line programs to run using the OS shell.
81+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
8082

81-
# ℹ️ Command-line programs to run using the OS shell.
82-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
83+
# If the Autobuild fails above, remove it and uncomment the following three lines.
84+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
8385

84-
# If the Autobuild fails above, remove it and uncomment the following three lines.
85-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
86+
# - run: |
87+
# echo "Run, Build Application using script"
88+
# ./location_of_script_within_repo/buildscript.sh
8689

87-
# - run: |
88-
# echo "Run, Build Application using script"
89-
# ./location_of_script_within_repo/buildscript.sh
90-
91-
- name: Perform CodeQL Analysis
92-
uses: github/codeql-action/analyze@v3
93-
with:
94-
category: "/language:${{matrix.language}}"
90+
- name: Perform CodeQL Analysis
91+
uses: github/codeql-action/analyze@v3
92+
with:
93+
category: "/language:${{matrix.language}}"

.github/workflows/publish-pr-coverage-results.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,10 @@ jobs:
2121
ref: ${{ github.event.workflow_run.head_branch }}
2222

2323
- name: 'Download artifact'
24-
uses: actions/github-script@v7.0.1
24+
uses: actions/download-artifact@v4
2525
with:
26-
script: |
27-
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
28-
owner: context.repo.owner,
29-
repo: context.repo.repo,
30-
run_id: ${{github.event.workflow_run.id }},
31-
});
32-
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
33-
return artifact.name == "coverage-reports"
34-
})[0];
35-
var download = await github.rest.actions.downloadArtifact({
36-
owner: context.repo.owner,
37-
repo: context.repo.repo,
38-
artifact_id: matchArtifact.id,
39-
archive_format: 'zip',
40-
});
41-
var fs = require('fs');
42-
fs.writeFileSync('${{github.workspace}}/coverage-reports.zip', Buffer.from(download.data));
43-
- run: |
44-
unzip coverage-reports.zip
45-
rm coverage-reports.zip
26+
name: coverage-reports
27+
run-id: ${{ github.event.workflow_run.id }}
4628

4729
- name: Set Coverage Report Paths
4830
id: coverage-paths

.github/workflows/publish-pr-test-results.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,12 @@ jobs:
1616
( github.event.workflow_run.conclusion == 'success' ||
1717
github.event.workflow_run.conclusion == 'failure' ) }}
1818
steps:
19+
1920
- name: 'Download artifact'
20-
uses: actions/github-script@v7.0.1
21+
uses: actions/download-artifact@v4
2122
with:
22-
script: |
23-
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
24-
owner: context.repo.owner,
25-
repo: context.repo.repo,
26-
run_id: ${{github.event.workflow_run.id }},
27-
});
28-
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
29-
return artifact.name == "unit-test-results"
30-
})[0];
31-
var download = await github.rest.actions.downloadArtifact({
32-
owner: context.repo.owner,
33-
repo: context.repo.repo,
34-
artifact_id: matchArtifact.id,
35-
archive_format: 'zip',
36-
});
37-
var fs = require('fs');
38-
fs.writeFileSync('${{github.workspace}}/unit-test-results.zip', Buffer.from(download.data));
39-
- run: unzip unit-test-results.zip
23+
name: unit-test-results
24+
run-id: ${{ github.event.workflow_run.id }}
4025

4126
- name: Publish Unit Test Results
4227
uses: EnricoMi/publish-unit-test-result-action@v2

0 commit comments

Comments
 (0)