add workflow run to trigger clippy annotation on pr

Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
This commit is contained in:
Jerens Lensun 2025-06-04 09:59:18 +08:00
parent 5ea329855d
commit 5eb3c56c95
2 changed files with 59 additions and 3 deletions

56
.github/workflows/lint-annotation.yml vendored Normal file
View file

@ -0,0 +1,56 @@
name: Lint Annotation On PR
on:
workflow_run:
workflows: [Main]
types:
- completed
jobs:
pr-annotation:
name: Create PR annotation
runs-on: ubuntu-22.04
outputs:
configuration: ${{ steps.configuration.outputs.result }}
steps:
- uses: actions/download-artifact@v4
with:
name: clippy-lint-result
- name: Retrieve Head Sha
run: |
echo "HEAD_SHA=$(cat ./pr/head_sha)" >> $GITHUB_OUTPUT
id: head_sha
- name: Comment on PR with E2E results
if: ${{ !cancelled() }}
uses: actions/github-script@v7.0.1
with:
script: |
const fs = require('fs')
const headSha = fs.readFileSync('./pr/head_sha', 'utf8').trim()
const data = fs.readFileSync('./temp/clippy-output.json', 'utf8')
const annotations = JSON.parse(data)
if (!Array.isArray(annotations) || annotations.length === 0) {
console.log("✅ No annotations to report.");
return;
}
if (annotations.length > 10) {
console.warn("⚠️ GitHub only allows 10 annotations per check run. Truncated.");
}
const limitedAnnotations = annotations.slice(0, 10); // GitHub limit
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: "Rust Clippy Lint Report",
head_sha: headSha,
status: "completed",
conclusion: "neutral",
output: {
title: "Rust Clippy Code Annotations",
summary: `${limitedAnnotations.length} issue(s) reported`,
annotations: limitedAnnotations
}
});

View file

@ -47,12 +47,12 @@ jobs:
- name: Give permission to script
run: |
chmod +x ./etc/ci/clippy-annotation.sh
- name: Save PR number & Create temp directory
- name: Save Head Sha & Create temp directory
if: ${{ !cancelled() }}
run: |
mkdir -p ./pr
mkdir -p ./temp
echo ${{ github.event.number }} > ./pr/number
echo ${{ github.event.pull_request.head.sha }} > ./pr/head_sha
- name: Clippy
run: |
./mach clippy --message-format=json --use-crown --locked -- -- --deny warnings | ./etc/ci/clippy-annotation.sh > temp/clippy-output.json
@ -63,7 +63,7 @@ jobs:
name: clippy-lint-result
path: |
temp/clippy-output.json
pr/number
pr/head_sha
retention-days: 14
- name: Tidy
run: ./mach test-tidy --no-progress --all