From c4b727ddf777953fa4b8c390fa0bd46cc7dd5f73 Mon Sep 17 00:00:00 2001 From: mrickard Date: Mon, 15 Jul 2024 17:30:16 -0400 Subject: [PATCH 1/4] ci: Added benchmark test GHA, with branch-and-version filenaming for output --- .github/workflows/benchmark-tests.yml | 68 +++++++++++++++++++++++++++ bin/run-bench.js | 9 +++- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/benchmark-tests.yml diff --git a/.github/workflows/benchmark-tests.yml b/.github/workflows/benchmark-tests.yml new file mode 100644 index 0000000000..9ef2bcfc8b --- /dev/null +++ b/.github/workflows/benchmark-tests.yml @@ -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 + diff --git a/bin/run-bench.js b/bin/run-bench.js index 08d02cb022..bc2f0e7dda 100644 --- a/bin/run-bench.js +++ b/bin/run-bench.js @@ -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)) @@ -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}`) } From f3d03e34e65d9e33a8c5aef5da94fa1bee1befc8 Mon Sep 17 00:00:00 2001 From: mrickard Date: Tue, 16 Jul 2024 16:43:09 -0400 Subject: [PATCH 2/4] ci: Replaced pr and push triggers for benchmark tests with weekly cron Signed-off-by: mrickard --- .github/workflows/benchmark-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark-tests.yml b/.github/workflows/benchmark-tests.yml index 9ef2bcfc8b..362f4c7382 100644 --- a/.github/workflows/benchmark-tests.yml +++ b/.github/workflows/benchmark-tests.yml @@ -1,9 +1,9 @@ name: Benchmark Tests on: - push: - pull_request: workflow_dispatch: + schedule: + - cron: '0 10 * * 1' env: # Enable versioned runner quiet mode to make CI output easier to read: From cd596e4ffca6cb76b145429f11cd340b80b99858 Mon Sep 17 00:00:00 2001 From: mrickard Date: Tue, 16 Jul 2024 17:01:59 -0400 Subject: [PATCH 3/4] ci: Removed should-run check Signed-off-by: mrickard --- .github/workflows/benchmark-tests.yml | 35 --------------------------- 1 file changed, 35 deletions(-) diff --git a/.github/workflows/benchmark-tests.yml b/.github/workflows/benchmark-tests.yml index 362f4c7382..ca08cb66b4 100644 --- a/.github/workflows/benchmark-tests.yml +++ b/.github/workflows/benchmark-tests.yml @@ -10,42 +10,7 @@ env: 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: From 4912ee6d50cdbd69c4e0604f5ef57a4a3682359c Mon Sep 17 00:00:00 2001 From: mrickard Date: Wed, 17 Jul 2024 10:13:14 -0400 Subject: [PATCH 4/4] ci: Added archiving of benchmark output Signed-off-by: mrickard --- .github/workflows/benchmark-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/benchmark-tests.yml b/.github/workflows/benchmark-tests.yml index ca08cb66b4..52f4d07970 100644 --- a/.github/workflows/benchmark-tests.yml +++ b/.github/workflows/benchmark-tests.yml @@ -30,4 +30,9 @@ jobs: run: node ./bin/run-bench.js --filename=${{ github.base_ref || 'main' }}_${{ matrix.node-version }} - name: Verify Benchmark Output run: ls benchmark_results + - name: Archive Benchmark Test + uses: actions/upload-artifact@v4 + with: + name: benchmark-tests-${{ github.base_ref || 'main' }}-${{ matrix.node-version }} + path: ./benchmark_results