Bench Mako PR #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bench Mako PR | |
on: | |
workflow_dispatch: | |
inputs: | |
prNumber: | |
description: "PR number" | |
required: true | |
type: string | |
jobs: | |
create-comment: | |
runs-on: ubuntu-latest | |
outputs: | |
comment-id: ${{ steps.create-comment.outputs.result }} | |
steps: | |
- id: create-comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.MAKO_BOT_ACCESS_TOKEN }} | |
result-encoding: string | |
script: | | |
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` | |
const urlLink = `[Open](${url})` | |
const { data: comment } = await github.rest.issues.createComment({ | |
issue_number: context.payload.inputs.prNumber, | |
owner: context.repo.owner, | |
repo: 'mako', | |
body: `⏳ Triggered benchmark: ${urlLink}` | |
}) | |
return comment.id | |
bench: | |
runs-on: ubuntu-latest | |
needs: [create-comment] | |
strategy: | |
matrix: | |
shardIndex: [1] | |
shardTotal: [1] | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Init env | |
uses: ./.github/actions/env | |
- uses: ./.github/actions/build-mako | |
with: | |
path: ${{ env.MAKO_DIR }} | |
- name: Install hyperfine | |
run: sudo apt-get update && sudo apt-get install -y hyperfine | |
- name: Run benchmark | |
run: node bin/cli.js bench | |
comment-results: | |
runs-on: ubuntu-latest | |
needs: [create-comment, bench] | |
if: always() | |
steps: | |
- name: Read benchmark results | |
id: read_results | |
run: | | |
const fs = require('fs'); | |
const path = '.mako/benchmark-results.md'; | |
const result = fs.readFileSync(path, 'utf8'); | |
echo "::set-output name=benchmark_results::${result}" | |
- name: Update comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.MAKO_BOT_ACCESS_TOKEN }} | |
script: | | |
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` | |
const urlLink = `[Open](${url})` | |
const result = `${{ steps.read_results.outputs.benchmark_results }}` | |
const body = ` | |
📝 Benchmark detail: ${urlLink} | |
${result} | |
` | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: 'mako', | |
comment_id: `${{ needs.create-comment.outputs.comment-id }}`, | |
body | |
}) |