Bench Mako PR #2
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 | |
- name: List files | |
run: ls -la | |
- name: Upload benchmark results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: benchmark-results | |
path: ./benchmark-results.md | |
if-no-files-found: error | |
comment-results: | |
runs-on: ubuntu-latest | |
needs: [create-comment, bench] | |
if: always() | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check current working directory | |
run: pwd | |
- name: Download benchmark results | |
uses: actions/download-artifact@v4 | |
with: | |
name: benchmark-results | |
path: ./ | |
- name: List files | |
run: ls -la | |
- name: Output file content | |
run: | | |
cat benchmark-results.md | |
- name: Read benchmark results | |
id: read_results | |
run: | | |
# 读取 Markdown 表格内容 | |
BENCHMARK_RESULTS=$(cat benchmark-results.md) | |
# 去掉反引号 | |
CLEANED_RESULTS=$(echo "$BENCHMARK_RESULTS" | sed 's/`//g') | |
# 将处理后的结果输出到 GITHUB_OUTPUT | |
echo "benchmark_results<<EOF" >> $GITHUB_OUTPUT | |
echo "$CLEANED_RESULTS" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Update 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 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 | |
}) |