CI: Run benchmark (#2563)

* fix(bench): try to fix benchmark

* style: deno fmt

* fix: remove check formating

* fix: add fake token

* fix: tranform

* deno fmt

* add parseFloat

* fix unit

* refactor: change fetch target to benchrepo

* fix: oldBot

* refactor: use custom input

* ci: add tee

* style: deno fmt

* ci: cache deps

* chore: remove

* ci: add memory benchmark

* fix: fix url for main repo

* deno fmt

* ci: add comment-always

* fix: link

* just trying trigger

* ci: only push on main

* fix: type

* fix: range

* fixed

* style: deno fmt

* fix: path

* Add upload output

* style: deno fmt

* ci: add create branch on pr owner's repo

* fix: github.repository

* ci: fix remove id benchmark-action

* fix

* fix: type

* reverse change

* ci: add cache

* feat: add using cache

* bench: update name and ignore previous when ci

* style: name

* feat: fix pr message style

* add more benchmark

* deno fmt

* fix

* fix: wording

* chore: only run on success

* fix: used last head as current commit
This commit is contained in:
Jonathan Ho
2022-10-29 14:22:23 -05:00
committed by GitHub
parent 716499e865
commit 7a1a41fac8
8 changed files with 420 additions and 19 deletions
+69
View File
@@ -0,0 +1,69 @@
name: Benchmark
on:
pull_request:
push:
jobs:
benchmark:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: v1.x
# this is the performance benchmark
- name: Cache deps
run: deno cache performance/mod.ts
- name: Run Benchmark
run: NO_COLOR=true deno bench --unstable -A performance/mod.ts | tee output.txt
- name: Format Benchmark Output
run: deno run -A performance/tranformOutput.ts
# this is the memory benchmark
- name: Download db from benchmark repo
run: wget https://github.com/discordeno/benchmarks/raw/main/db.tar.gz
- name: Decompress db
run: tar -xzvf db.tar.gz
- name: Run memory benchmark
run: deno run --v8-flags="--expose-gc" -A performance/memory.ts
- name: Download previous benchmark data
uses: actions/cache@v3
with:
path: ./benchmarksResult
key: ${{ github.ref }}-benchmark
- name: Store benchmark result to cache
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "customSmallerIsBetter"
output-file-path: output.txt
external-data-json-path: benchmarksResult/data.json
- uses: actions/upload-artifact@v3
if: ${{ github.ref != 'refs/heads/main' }}
with:
name: benchmarkResults
path: benchmarksResult/data.json
- name: Store benchmark result (Main)
uses: benchmark-action/github-action-benchmark@v1
if: ${{ github.ref == 'refs/heads/main' }}
with:
tool: "customSmallerIsBetter"
output-file-path: output.txt
gh-pages-branch: "benchies"
benchmark-data-dir-path: benchmarksResult
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
- name: Save Commmit SHA
run: |
mkdir -p ./commitData
echo $GITHUB_SHA > ./commitData/sha
echo $GITHUB_REPOSITORY > ./commitData/repo
- uses: actions/upload-artifact@v3
with:
name: commitData
path: commitData/
+95
View File
@@ -0,0 +1,95 @@
name: Comment Benchmark Result
on:
workflow_run:
workflows: [Benchmark]
types:
- completed
jobs:
comment-benchmark-result:
name: Comment Benchmark Result
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: v1.x
- name: Download Commit Data Artifact
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "commitData"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/commitData.zip`, Buffer.from(download.data));
- name: Unzip Commit Data Artifact
run: unzip commitData.zip
- name: Download Result Artifact
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "benchmarkResults"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/benchmarkResults.zip`, Buffer.from(download.data));
- name: Unzip Result Artifact
run: unzip benchmarkResults.zip
- name: Generate Message
id: genMessage
run: |
MESSAGE=$(deno run -A performance/generateMessage.ts)
echo "MESSAGE<<EOF" >> $GITHUB_ENV
echo "$MESSAGE" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: "Comment on PR"
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const commit_sha = fs.readFileSync('./sha', 'utf-8');
const repo = fs.readFileSync('./repo', 'utf-8');
const pr = await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: commit_sha.slice(0,-1),
owner: repo.split('/')[0],
repo: repo.split('/')[1].slice(0,-1),
});
if (pr.data[0]) {
github.rest.issues.createComment({
issue_number: pr.data[0].number,
owner: repo.split('/')[0],
repo: repo.split('/')[1].slice(0,-1),
body: `${{ env.MESSAGE }}`
})
}