Skip to content

fix CI and improve benchmark reporting #105

fix CI and improve benchmark reporting

fix CI and improve benchmark reporting #105

Workflow file for this run

name: Go
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
statuses: write
checks: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "stable"
- 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 ./... 2>&1 | go-junit-report > reports/report.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: 'reports/report.xml'
check_name: 'Go Tests'
comment_title: 'Go Test Results'
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
steps:
- name: Checkout PR
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.x'
- name: Run PR benchmarks
run: |
mkdir -p benchmarks
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: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
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```'
})