Skip to content

ci: update actions used in gh-pages #45

ci: update actions used in gh-pages

ci: update actions used in gh-pages #45

Workflow file for this run

name: Benchmark for PR
on:
pull_request:
types: [opened, synchronize]
branches:
- master
jobs:
pre_build:
permissions:
actions: write
contents: read
name: Duplicate Actions Detection
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: "true"
bench:
name: Run benches
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 需要完整历史以切换到 PR 的基分支
# 设置 Rust 工具链
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
# 安装 critcmp
- name: Install critcmp
run: cargo install critcmp
# 先在基分支上运行基准测试
- name: Run benchmark on base branch
run: |
git checkout ${{ github.event.pull_request.base.sha }}
cargo bench --workspace -- --save-baseline base
# 切换到 PR 分支运行基准测试
- name: Run benchmark on PR
run: |
git checkout ${{ github.event.pull_request.head.sha }}
cargo bench --workspace -- --save-baseline pr
# 比较结果并生成评论
- name: Compare and comment results
run: |
# 生成比较结果
BENCH_RESULT=$(critcmp --color never base pr)
# 生成评论内容
echo "BENCHMARK_COMMENT<<EOF" >> $GITHUB_ENV
echo "### 📊 Benchmark Performance Report" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo '```console' >> $GITHUB_ENV
echo "$BENCH_RESULT" >> $GITHUB_ENV
echo '```' >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo "Generated by GitHub Actions on $(date)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "$BENCH_RESULT"
# 查找之前的评论
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '### 📊 Benchmark Performance Report'
# 更新或创建评论
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ env.BENCHMARK_COMMENT }}
edit-mode: replace