Skip to content

Commit

Permalink
fix CI and improve benchmark reporting (#22)
Browse files Browse the repository at this point in the history
* improve benchmark reporting

* improve bench reporting
  • Loading branch information
geseq authored Oct 16, 2024
1 parent a0ac20d commit 8df1672
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 189 deletions.
73 changes: 52 additions & 21 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
contents: read
pull-requests: write
statuses: write
checks: write

jobs:
build:
Expand All @@ -24,48 +25,78 @@ jobs:
- name: Build
run: go build -v ./...

- name: Install go-junit-report
run: go install github.com/jstemmer/go-junit-report/v2@latest
- name: Run Tests and Generate Test Report
run: |
mkdir -p reports
go test -v -json ./... > reports/report.json
go test -v ./... 2>&1 | go-junit-report > reports/report.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: 'reports/report.json'
files: 'reports/report.xml'
check_name: 'Go Tests'
comment_title: 'Go Test Results'
commit: ${{ github.event.pull_request.head.sha }}
commit: ${{ github.event.pull_request.head.sha || github.sha }}
github_token: ${{ secrets.GITHUB_TOKEN }}
hide_comments: 'all but latest'
deduplicate_classes_by_file_name: true

benchmark:
name: Run Go benchmarks
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Checkout PR
uses: actions/checkout@v4

- uses: actions/setup-go@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.x'

- name: Run benchmarks
- name: Run PR benchmarks
run: |
mkdir -p benchmarks
go test -bench . -benchmem -run=^$ ./... > benchmarks/benchmark.txt
go test -v -bench . -benchmem -run=^$ ./... > benchmarks/pr_benchmark.txt
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
clean: false

- name: Run main benchmarks
run: |
go test -v -bench . -benchmem -run=^$ ./... > benchmarks/main_benchmark.txt
- name: Process benchmark results
run: |
{
echo "PR Benchmarks:"
cat benchmarks/pr_benchmark.txt
echo $'\n\nMain Benchmarks:'
cat benchmarks/main_benchmark.txt
} > benchmarks/comparison.txt
- name: Store benchmark result
uses: actions/upload-artifact@v3
with:
name: benchmark-comparison
path: benchmarks/comparison.txt

- name: Post Benchmark Results
uses: rhysd/github-action-benchmark@v1
- name: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
tool: 'go'
output-file-path: 'benchmarks/benchmark.txt'
github-token: ${{ secrets.GITHUB_TOKEN }}
ref: 'main'
comment-on-alert: true
alert-threshold: '15%'
fail-on-alert: true
summary-always: true
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const benchmarkResults = fs.readFileSync('benchmarks/comparison.txt', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Benchmark Comparison\n\n```\n' + benchmarkResults + '\n```'
})
Loading

0 comments on commit 8df1672

Please sign in to comment.