Skip to content

Commit cd17753

Browse files
committed
chore(ci): add Benchmarks workflow (manual trigger, artifact upload, optional docs publish)
1 parent 4b87441 commit cd17753

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

.github/workflows/benchmarks.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Benchmarks
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
project:
7+
description: 'Benchmark project path'
8+
required: false
9+
default: 'tests/Space.Benchmarks/Space.Benchmarks.csproj'
10+
configuration:
11+
description: 'Build configuration'
12+
required: false
13+
default: 'Release'
14+
15+
jobs:
16+
run-benchmarks:
17+
runs-on: windows-latest
18+
timeout-minutes: 60
19+
permissions:
20+
contents: write
21+
env:
22+
PUBLISH_DOCS_PAT: ${{ secrets.PUBLISH_DOCS_PAT }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v4
32+
with:
33+
dotnet-version: '8.0.x'
34+
35+
- name: Restore
36+
run: dotnet restore
37+
38+
- name: Build
39+
run: dotnet build ${{ github.event.inputs.project }} -c ${{ github.event.inputs.configuration }} --nologo --no-restore
40+
41+
- name: Run Benchmarks
42+
env:
43+
GITHUB_WORKSPACE: ${{ github.workspace }}
44+
GITHUB_REF_NAME: ${{ github.ref_name }}
45+
GITHUB_SHA: ${{ github.sha }}
46+
run: |
47+
dotnet run -c ${{ github.event.inputs.configuration }} --project ${{ github.event.inputs.project }} -- --anyCategories "*"
48+
49+
- name: Locate Reports Directory
50+
id: find_reports
51+
shell: pwsh
52+
run: |
53+
$reports = Get-ChildItem -Path "$env:GITHUB_WORKSPACE/BenchmarkReports" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1
54+
if (-not $reports) { Write-Error "No BenchmarkReports folder found"; exit 1 }
55+
echo "dir=$($reports.FullName)" >> $env:GITHUB_OUTPUT
56+
57+
- name: Upload Artifact
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: benchmark-reports
61+
62+
path: ${{ steps.find_reports.outputs.dir }}
63+
64+
# Optional: Push to docs/benchmarks (requires repo write permission & PAT)
65+
- name: Publish to docs/benchmarks
66+
if: ${{ env.PUBLISH_DOCS_PAT != '' }}
67+
env:
68+
PUBLISH_DOCS_PAT: ${{ env.PUBLISH_DOCS_PAT }}
69+
shell: pwsh
70+
run: |
71+
$dst = Join-Path $env:GITHUB_WORKSPACE "docs/benchmarks"
72+
New-Item -ItemType Directory -Force -Path $dst | Out-Null
73+
74+
$src = "${{ steps.find_reports.outputs.dir }}"
75+
$folderName = Split-Path $src -Leaf
76+
Copy-Item -Recurse -Force $src (Join-Path $dst $folderName)
77+
78+
git config user.email "actions@github.com"
79+
git config user.name "github-actions"
80+
git add docs/benchmarks
81+
git commit -m "docs(benchmarks): add $folderName" || echo "No changes to commit"
82+
83+
# Set remote with PAT and push
84+
git remote set-url origin "https://x-access-token:$env:PUBLISH_DOCS_PAT@github.com/${{ github.repository }}.git"
85+
git push origin HEAD:${{ github.ref_name }}

0 commit comments

Comments
 (0)