Skip to content

Commit

Permalink
ci: Added benchmark test GHA, with branch-and-version filenaming for …
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
mrickard committed Jul 16, 2024
1 parent 1b51a68 commit d711dd9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/benchmark-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Benchmark Tests

on:
push:
pull_request:
workflow_dispatch:

env:
# Enable versioned runner quiet mode to make CI output easier to read:
OUTPUT_MODE: quiet

jobs:
should_run:
# We only want the test suites to run when code has changed, or when
# a dependency update has occurred.
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
javascript_changed: ${{ steps.filter.outputs.javascript }}
deps_changed: ${{ steps.deps.outputs.divergent }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
id: filter
with:
filters: |
javascript:
- 'api.js'
- 'esm-loader.mjs'
- 'index.js'
- 'stub_api.js'
- 'lib/**/*.{js,json,mjs,cjs}'
- 'test/**/*.{js,json,mjs,cjs}'
- uses: jsumners-nr/gha-node-deps-divergent@643628fe0da51ec025e984c4644f17fd9f9e93f6
id: deps
with:
base-sha: ${{ github.base_ref || 'main' }}
current-sha: ${{ github.sha }}

benchmarks:
needs:
- should_run
if: github.event_name == 'workflow_dispatch' ||
(needs.should_run.outputs.javascript_changed == 'true' ||
needs.should_run.outputs.deps_changed == 'true')
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Run Benchmark Tests
run: node ./bin/run-bench.js --filename=${{ github.base_ref || 'main' }}_${{ matrix.node-version }}
- name: Verify Benchmark Output
run: ls benchmark_results

9 changes: 7 additions & 2 deletions bin/run-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const globs = []
const opts = Object.create(null)

process.argv.slice(2).forEach(function forEachFileArg(file) {
if (/^--/.test(file)) {
if (/^--/.test(file) && file.indexOf('=') > -1) {
// this one has a value assigned
const arg = file.substring(2).split('=')
opts[arg[0]] = arg[1]
} else if (/^--/.test(file)) {
opts[file.substring(2)] = true
} else if (/[*]/.test(file)) {
globs.push(path.join(benchpath, file))
Expand Down Expand Up @@ -69,13 +73,14 @@ class Printer {
/* eslint-enable no-console */
}
const resultPath = 'benchmark_results'
const filePrefix = opts.filename ? `${opts.filename}` : 'benchmark'
try {
await fs.stat(resultPath)
} catch (e) {
await fs.mkdir(resultPath)
}
const content = JSON.stringify(this._tests, null, 2)
const fileName = `${resultPath}/benchmark_${new Date().getTime()}.json`
const fileName = `${resultPath}/${filePrefix}_${new Date().getTime()}.json`
await fs.writeFile(fileName, content)
console.log(`Done! Test output written to ${fileName}`)
}
Expand Down

0 comments on commit d711dd9

Please sign in to comment.