Skip to content

Commit

Permalink
chore: try out codspeed for CI benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 1, 2024
1 parent bc746d8 commit e2c2ce3
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: codspeed-benchmarks

on:
pull_request:
branches:
- "main"
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version: '22.x'
cache: pnpm
- run: pnpm install
- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: pnpm bench
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"lint": "tsc && biome check && pnpm -s dlx [email protected] lint",
"format": "biome check --fix --unsafe",
"test": "vitest run --coverage",
"bench": "vitest bench",
"prepublishOnly": "tsc && biome check --fix && pnpm -s build"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@codspeed/vitest-plugin": "^3.1.0",
"@vitest/coverage-v8": "1.6.0",
"tsup": "^8.1.0",
"typescript": "^5.5.2",
Expand Down
144 changes: 144 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { defineConfig } from 'vitest/config'
import codspeed from '@codspeed/vitest-plugin'
import { defineConfig, UserConfig } from 'vitest/config'

// FIXME: vitest doesn‘t provide the Plugin type???
type Plugin = Extract<UserConfig['plugins'], any[]>[number]

const resolve = (specifier: string) =>
new URL(import.meta.resolve(specifier)).pathname

export default defineConfig({
export default defineConfig(({ mode }) => ({
test: {
globals: true,
coverage: {
Expand All @@ -16,4 +20,7 @@ export default defineConfig({
radashi: resolve('./src/mod.js'),
},
},
})
plugins: [
mode === 'benchmark' && process.env.CI ? (codspeed() as Plugin) : [],
],
}))

0 comments on commit e2c2ce3

Please sign in to comment.