Skip to content

Commit 5f52cf3

Browse files
committed
Reconfigured Pipelines
1 parent f010a13 commit 5f52cf3

File tree

2 files changed

+178
-277
lines changed

2 files changed

+178
-277
lines changed

.github/workflows/benchmarks.yml

Lines changed: 176 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,183 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
7-
# built on .NET Core.
8-
# To learn how to migrate your existing application to .NET Core,
9-
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
10-
#
11-
# To configure this workflow:
12-
#
13-
# 1. Configure environment variables
14-
# GitHub sets default environment variables for every workflow run.
15-
# Replace the variables relative to your project in the "env" section below.
16-
#
17-
# 2. Signing
18-
# Generate a signing certificate in the Windows Application
19-
# Packaging Project or add an existing signing certificate to the project.
20-
# Next, use PowerShell to encode the .pfx file using Base64 encoding
21-
# by running the following Powershell script to generate the output string:
22-
#
23-
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
24-
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
25-
#
26-
# Open the output file, SigningCertificate_Encoded.txt, and copy the
27-
# string inside. Then, add the string to the repo as a GitHub secret
28-
# and name it "Base64_Encoded_Pfx."
29-
# For more information on how to configure your signing certificate for
30-
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
31-
#
32-
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
33-
# See "Build the Windows Application Packaging project" below to see how the secret is used.
34-
#
35-
# For more information on GitHub Actions, refer to https://github.com/features/actions
36-
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
37-
# refer to https://github.com/microsoft/github-actions-for-desktop-apps
38-
39-
name: .NET Core Desktop
1+
name: Benchmarks
402

413
on:
42-
push:
43-
branches: [ "main" ]
444
pull_request:
45-
branches: [ "main" ]
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
branches:
7+
- main
8+
- main-version-*
9+
paths-ignore:
10+
- "src/HotChocolate/AspNetCore/benchmarks/k6/performance-data.json"
4611

47-
jobs:
48-
49-
build:
50-
51-
strategy:
52-
matrix:
53-
configuration: [Debug, Release]
12+
concurrency:
13+
group: benchmarks-${{ github.event.pull_request.number }}
14+
cancel-in-progress: true
5415

55-
runs-on: windows-latest # For a list of available runner types, refer to
56-
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
57-
58-
env:
59-
Solution_Name: your-solution-name # Replace with your solution name, i.e. MyWpfApp.sln.
60-
Test_Project_Path: your-test-project-path # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
61-
Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
62-
Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.
16+
jobs:
17+
check-changes:
18+
name: Check for Changes
19+
runs-on: ubuntu-latest
20+
outputs:
21+
src_changes: ${{ steps.check-src.outputs.src_changes }}
22+
steps:
23+
- name: Checkout Repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 2
27+
show-progress: false
28+
29+
- name: Check for changes in src directory or workflow files
30+
id: check-src
31+
run: |
32+
src_changes=$(git diff --name-only HEAD~1 HEAD -- ./src)
33+
workflow_changes=$(git diff --name-only HEAD~1 HEAD -- .github/workflows/benchmarks.yml)
34+
35+
if [[ -n "$src_changes" ]] || [[ -n "$workflow_changes" ]]; then
36+
echo "src_changes=true" >> $GITHUB_OUTPUT
37+
else
38+
echo "src_changes=false" >> $GITHUB_OUTPUT
39+
fi
40+
41+
hotchocolate-core:
42+
name: "HotChocolate Core Benchmarks"
43+
needs: check-changes
44+
if: needs.check-changes.outputs.src_changes == 'true' && github.event.pull_request.draft == false
45+
runs-on: benchmarking
46+
permissions:
47+
contents: write
48+
pull-requests: write
6349

6450
steps:
65-
- name: Checkout
66-
uses: actions/checkout@v4
67-
with:
68-
fetch-depth: 0
69-
70-
# Install the .NET Core workload
71-
- name: Install .NET Core
72-
uses: actions/setup-dotnet@v4
73-
with:
74-
dotnet-version: 8.0.x
75-
76-
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
77-
- name: Setup MSBuild.exe
78-
uses: microsoft/setup-msbuild@v2
79-
80-
# Execute all unit tests in the solution
81-
- name: Execute unit tests
82-
run: dotnet test
83-
84-
# Restore the application to populate the obj folder with RuntimeIdentifiers
85-
- name: Restore the application
86-
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
87-
env:
88-
Configuration: ${{ matrix.configuration }}
89-
90-
# Decode the base 64 encoded pfx and save the Signing_Certificate
91-
- name: Decode the pfx
92-
run: |
93-
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
94-
$certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
95-
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
96-
97-
# Create the app package by building and packaging the Windows Application Packaging project
98-
- name: Create the app package
99-
run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
100-
env:
101-
Appx_Bundle: Always
102-
Appx_Bundle_Platforms: x86|x64
103-
Appx_Package_Build_Mode: StoreUpload
104-
Configuration: ${{ matrix.configuration }}
105-
106-
# Remove the pfx
107-
- name: Remove the pfx
108-
run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx
109-
110-
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
111-
- name: Upload build artifacts
112-
uses: actions/upload-artifact@v4
113-
with:
114-
name: MSIX Package
115-
path: ${{ env.Wap_Project_Directory }}\AppPackages
51+
- name: Checkout PR code
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
show-progress: false
56+
57+
- name: Restore dependencies
58+
run: dotnet restore src/HotChocolate/AspNetCore/benchmarks/k6/eShop.slnx
59+
60+
- name: Start AppHost and wait for readiness
61+
working-directory: src/HotChocolate/AspNetCore/benchmarks/k6/Catalog.AppHost
62+
run: |
63+
echo "Starting AppHost..."
64+
dotnet run > /tmp/apphost.log 2>&1 &
65+
APPHOST_PID=$!
66+
echo "APPHOST_PID=$APPHOST_PID" >> $GITHUB_ENV
67+
68+
echo "Waiting for server to be ready..."
69+
for i in {1..30}; do
70+
if curl -s -o /dev/null -w "%{http_code}" http://localhost:5224/graphql -X POST \
71+
-H "Content-Type: application/json" \
72+
-d '{"query": "{ __typename }"}' | grep -q "200"; then
73+
echo "Server is ready!"
74+
break
75+
fi
76+
echo "Waiting... ($i/30)"
77+
sleep 2
78+
done
79+
80+
- name: Run performance tests and collect data
81+
working-directory: src/HotChocolate/AspNetCore/benchmarks/k6
82+
run: |
83+
chmod +x run-and-collect.sh
84+
./run-and-collect.sh performance-data-current.json
85+
86+
- name: Stop AppHost
87+
if: always()
88+
run: |
89+
if [ -n "$APPHOST_PID" ]; then
90+
kill $APPHOST_PID 2>/dev/null || true
91+
wait $APPHOST_PID 2>/dev/null || true
92+
fi
93+
94+
- name: Commit and push performance data to current branch
95+
working-directory: src/HotChocolate/AspNetCore/benchmarks/k6
96+
run: |
97+
# Copy the performance data to the tracked filename
98+
cp performance-data-current.json performance-data.json
99+
100+
# Configure git
101+
git config user.name "github-actions[bot]"
102+
git config user.email "github-actions[bot]@users.noreply.github.com"
103+
104+
# Add and commit the performance data
105+
git add performance-data.json
106+
107+
# Only commit if there are changes
108+
if ! git diff --staged --quiet; then
109+
git commit -m "Update performance data [skip ci]"
110+
git push origin HEAD:${{ github.head_ref }}
111+
else
112+
echo "No changes to performance data"
113+
fi
114+
115+
- name: Fetch baseline performance data from main
116+
run: |
117+
git fetch origin main:main
118+
if git show main:src/HotChocolate/AspNetCore/benchmarks/k6/performance-data.json > baseline-performance.json 2>/dev/null; then
119+
echo "Baseline data fetched successfully"
120+
cat baseline-performance.json
121+
else
122+
echo "No baseline data found on main branch"
123+
# Don't create the file - let the comparison script handle missing baseline
124+
rm -f baseline-performance.json
125+
fi
126+
127+
- name: Compare performance and generate report
128+
working-directory: src/HotChocolate/AspNetCore/benchmarks/k6
129+
run: |
130+
chmod +x compare-performance.sh
131+
./compare-performance.sh performance-data-current.json ../../../../../baseline-performance.json performance-report.md
132+
133+
- name: Comment PR with performance report
134+
uses: actions/github-script@v7
135+
with:
136+
github-token: ${{ secrets.GITHUB_TOKEN }}
137+
script: |
138+
const fs = require('fs');
139+
const reportPath = 'src/HotChocolate/AspNetCore/benchmarks/k6/performance-report.md';
140+
141+
let report;
142+
try {
143+
report = fs.readFileSync(reportPath, 'utf8');
144+
} catch (error) {
145+
console.error('Failed to read performance report:', error);
146+
return;
147+
}
148+
149+
// Add timestamp and commit info to the report
150+
const timestamp = new Date().toUTCString();
151+
const commitSha = context.sha.substring(0, 7);
152+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
153+
154+
const commentBody = `${report}\n\n---\n*Run [${context.runId}](${runUrl}) " Commit ${commitSha} " ${timestamp}*`;
155+
156+
// Always create a new comment
157+
await github.rest.issues.createComment({
158+
owner: context.repo.owner,
159+
repo: context.repo.repo,
160+
issue_number: context.issue.number,
161+
body: commentBody,
162+
});
163+
164+
- name: Upload performance data as artifact
165+
uses: actions/upload-artifact@v4
166+
if: always()
167+
with:
168+
name: performance-data
169+
path: |
170+
src/HotChocolate/AspNetCore/benchmarks/k6/performance-data-current.json
171+
src/HotChocolate/AspNetCore/benchmarks/k6/performance-report.md
172+
/tmp/apphost.log
173+
retention-days: 30
174+
175+
- name: Check for performance regression
176+
working-directory: src/HotChocolate/AspNetCore/benchmarks/k6
177+
run: |
178+
# Fail the build if there's a significant performance regression
179+
if grep -q "� \*\*Performance regression detected" performance-report.md; then
180+
echo "::warning::Performance regression detected! Please review the performance report."
181+
# Uncomment the next line to fail the build on regression
182+
# exit 1
183+
fi

0 commit comments

Comments
 (0)