Skip to content

Commit 88c6168

Browse files
committed
Add GitHub Actions workflow for benchmarks and update dependencies
- Create a new workflow for running benchmarks on push and pull request events. - Update BenchmarkDotNet package version to 0.15.3. - Add benchmark project path to build script and define a new benchmark target. - Ignore BenchmarkDotNet artifacts in .gitignore.
1 parent cb7a618 commit 88c6168

File tree

4 files changed

+170
-1
lines changed

4 files changed

+170
-1
lines changed

.github/workflows/benchmark.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Benchmarks
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
concurrency:
19+
group: "benchmarks"
20+
cancel-in-progress: false
21+
22+
jobs:
23+
build-and-benchmark:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v5
27+
- name: Setup Pages
28+
uses: actions/configure-pages@v3
29+
- name: Setup necessary dotnet SDKs
30+
uses: actions/setup-dotnet@v4
31+
with:
32+
global-json-file: global.json
33+
dotnet-version: |
34+
8.x
35+
9.x
36+
- name: Run benchmarks
37+
run: |
38+
chmod +x ./build.sh
39+
./build.sh Benchmarks
40+
env:
41+
CI: true
42+
CONFIGURATION: Release
43+
- name: Store benchmark result
44+
uses: benchmark-action/github-action-benchmark@v1
45+
with:
46+
name: IcedTasks Benchmark
47+
tool: 'benchmarkdotnet'
48+
output-file-path: 'BenchmarkDotNet.Artifacts/results/*.json'
49+
github-token: ${{ secrets.GITHUB_TOKEN }}
50+
auto-push: false # Changed from true to false
51+
# Show alert with commit comment on detecting possible performance regression
52+
alert-threshold: '200%'
53+
comment-on-alert: true
54+
fail-on-alert: false
55+
alert-comment-cc-users: '@TheAngryByrd'
56+
57+
- name: Download latest GitHub Pages artifact
58+
run: |
59+
# Get the latest successful run ID from the docs workflow
60+
RUN_ID=$(gh run list --workflow="Deploy Docs" --status=success --limit=1 --json databaseId --jq '.[0].databaseId')
61+
62+
if [ ! -z "$RUN_ID" ] && [ "$RUN_ID" != "null" ]; then
63+
echo "Found docs workflow run: $RUN_ID"
64+
# Download the github-pages artifact from that run
65+
gh run download $RUN_ID --name github-pages --dir existing-pages
66+
echo "artifact_downloaded=true" >> $GITHUB_ENV
67+
else
68+
echo "No successful docs workflow run found"
69+
echo "artifact_downloaded=false" >> $GITHUB_ENV
70+
fi
71+
env:
72+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
continue-on-error: true
74+
75+
- name: Extract existing pages and add benchmarks
76+
run: |
77+
# Create a combined directory for deployment
78+
mkdir -p combined-site
79+
80+
# If we successfully downloaded existing pages, extract them
81+
if [ "$artifact_downloaded" = "true" ] && [ -d "existing-pages" ]; then
82+
echo "Extracting existing pages artifact..."
83+
# GitHub Pages artifacts are typically tar.gz files
84+
if [ -f "existing-pages/artifact.tar.gz" ]; then
85+
cd existing-pages
86+
tar -xzf artifact.tar.gz
87+
cd ..
88+
# Copy existing pages to combined site (skip the tar file itself)
89+
find existing-pages -type f ! -name "*.tar.gz" -exec cp {} combined-site/ \;
90+
find existing-pages -type d ! -name "existing-pages" -exec mkdir -p combined-site/{} \; 2>/dev/null || true
91+
elif [ -f "existing-pages/artifact.tar" ]; then
92+
cd existing-pages
93+
tar -xf artifact.tar
94+
cd ..
95+
find existing-pages -type f ! -name "*.tar" -exec cp {} combined-site/ \;
96+
else
97+
# Just copy all files if no tar found
98+
cp -r existing-pages/* combined-site/ 2>/dev/null || true
99+
fi
100+
echo "Existing pages extracted successfully"
101+
else
102+
echo "No existing pages found, creating basic site structure..."
103+
# Create a basic index if no existing pages
104+
echo '<html><head><title>IcedTasks</title></head><body><h1>IcedTasks</h1><p><a href="benchmarks/">View Benchmarks</a></p></body></html>' > combined-site/index.html
105+
fi
106+
107+
# Copy benchmark results to benchmarks subdirectory
108+
mkdir -p combined-site/benchmarks
109+
if [ -d "benchmark-data-repository/dpcs/benchmark-data" ]; then
110+
cp -r benchmark-data-repository/dpcs/benchmark-data/* combined-site/benchmarks/
111+
echo "Benchmark data copied to combined-site/benchmarks/"
112+
fi
113+
114+
# List what we have in combined-site for debugging
115+
echo "Contents of combined-site:"
116+
ls -la combined-site/ || true
117+
echo "Contents of combined-site/benchmarks:"
118+
ls -la combined-site/benchmarks/ || true
119+
120+
- name: Upload combined pages artifact
121+
uses: actions/upload-pages-artifact@v3
122+
with:
123+
path: combined-site
124+
125+
# Deployment job
126+
deploy:
127+
# Only deploy on pushes to master branch, not on pull requests
128+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
129+
environment:
130+
name: github-pages
131+
url: ${{ steps.deployment.outputs.page_url }}
132+
runs-on: ubuntu-latest
133+
needs: build-and-benchmark
134+
steps:
135+
- name: Deploy to GitHub Pages
136+
id: deployment
137+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,5 @@ temp/
276276
.fsdocs
277277
runtime-scripts/
278278
docs/
279+
280+
BenchmarkDotNet.Artifacts/

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0"/>
1717

1818
<!-- Benchmarks -->
19-
<PackageVersion Include="BenchmarkDotNet" Version="0.13.9"/>
19+
<PackageVersion Include="BenchmarkDotNet" Version="0.15.3"/>
2020
<PackageVersion Include="Ply" Version="0.3.1"/>
2121

2222
<!-- Test -->

build/build.fs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ let releaseBranch = "master"
9292
let readme = "README.md"
9393
let changelogFile = "CHANGELOG.md"
9494

95+
let fsharpBenchmarksProj =
96+
rootDirectory
97+
</> "benchmarks"
98+
</> "FSharpBenchmarks"
99+
</> "benchmarks.fsproj"
100+
95101
let tagFromVersionNumber versionNumber = sprintf "v%s" versionNumber
96102

97103
let READMElink = Uri(Uri(gitHubRepoUrl), $"blob/{releaseBranch}/{readme}")
@@ -620,6 +626,28 @@ let watchDocs ctx =
620626
DocsTool.watch (string configuration)
621627

622628

629+
let benchmarks _ =
630+
let args = [
631+
"--project"
632+
fsharpBenchmarksProj
633+
"-c"
634+
"Release"
635+
"-f"
636+
"net8.0"
637+
"--"
638+
"--exporters"
639+
"json"
640+
"--filter"
641+
"*"
642+
"--runtimes"
643+
"net9.0"
644+
"net8.0"
645+
"--job=short"
646+
]
647+
648+
dotnet.run id (String.concat " " args)
649+
|> failOnBadExitAndPrint
650+
623651
let initTargets () =
624652
BuildServer.install [ GitHubActions.Installer ]
625653

@@ -662,6 +690,8 @@ let initTargets () =
662690
Target.create "CleanDocsCache" cleanDocsCache
663691
Target.create "BuildDocs" buildDocs
664692
Target.create "WatchDocs" watchDocs
693+
Target.create "Benchmarks" benchmarks
694+
665695

666696
//-----------------------------------------------------------------------------
667697
// Target Dependencies

0 commit comments

Comments
 (0)