This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new fc425d4  chore: fix pull_request_target bug in CI
fc425d4 is described below

commit fc425d4a2522ab1ee97e3bd8fada8b3ef45dc1a9
Author: Yang Luo <[email protected]>
AuthorDate: Sat Apr 25 15:20:01 2026 +0800

    chore: fix pull_request_target bug in CI
---
 .github/workflows/benchmark-comment.yml | 35 +++++++++++++++++++++++++++++++++
 .github/workflows/pull_request.yml      | 31 ++++++++++++++++++++---------
 2 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/.github/workflows/benchmark-comment.yml 
b/.github/workflows/benchmark-comment.yml
new file mode 100644
index 0000000..85ba997
--- /dev/null
+++ b/.github/workflows/benchmark-comment.yml
@@ -0,0 +1,35 @@
+name: Post Benchmark Comment
+on:
+  workflow_run:
+    workflows: ["Benchmarks"]
+    types: [completed]
+jobs:
+  comment:
+    name: post benchmark comment
+    runs-on: ubuntu-latest
+    if: >
+      github.event.workflow_run.event == 'pull_request' &&
+      github.event.workflow_run.conclusion == 'success'
+    permissions:
+      pull-requests: write
+      actions: read
+    steps:
+      - name: Download benchmark results
+        uses: actions/download-artifact@v4
+        with:
+          name: benchmark-results
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          run-id: ${{ github.event.workflow_run.id }}
+      - name: Post comment to PR
+        uses: actions/github-script@v7
+        with:
+          script: |
+            const fs = require('fs');
+            const prNumber = parseInt(fs.readFileSync('pr_number.txt', 
'utf8').trim());
+            const benchResult = fs.readFileSync('benchmark_result.txt', 
'utf8');
+            await github.rest.issues.createComment({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: prNumber,
+              body: `## Benchmark Results\n\`\`\`\n${benchResult}\n\`\`\``
+            });
diff --git a/.github/workflows/pull_request.yml 
b/.github/workflows/pull_request.yml
index 0a95dde..e4445a9 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -1,5 +1,5 @@
 on:
-  pull_request_target:
+  pull_request:
     branches: [ master ]
 name: Benchmarks
 jobs:
@@ -7,10 +7,8 @@ jobs:
     name: run benchmark
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v5
+      - uses: actions/checkout@v4
         with:
-          ref: ${{github.event.pull_request.head.ref}}
-          repository: ${{github.event.pull_request.head.repo.full_name}}
           fetch-depth: 0
       - uses: actions-rs/toolchain@v1
         with:
@@ -29,10 +27,25 @@ jobs:
           key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
           restore-keys: |
             ${{ runner.os }}-cargo-
-      - name: Install critcmp with force
+      - name: Install critcmp
         run: cargo install critcmp --force
-      - uses: smrpn/criterion-compare-action@master 
+      - name: Run benchmarks on master
+        run: |
+          git checkout origin/master
+          cd benches && cargo bench -- --save-baseline master
+      - name: Run benchmarks on PR
+        run: |
+          git checkout ${{ github.sha }}
+          cd benches && cargo bench -- --save-baseline changes
+      - name: Generate benchmark comparison
+        run: |
+          cd benches && critcmp master changes > 
$GITHUB_WORKSPACE/benchmark_result.txt 2>&1 || true
+      - name: Save PR number
+        run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
+      - name: Upload benchmark results
+        uses: actions/upload-artifact@v4
         with:
-          cwd: benches
-          token: ${{ secrets.GITHUB_TOKEN }}
-
+          name: benchmark-results
+          path: |
+            benchmark_result.txt
+            pr_number.txt


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to