11name : Code Linting
22
33on :
4- pull_request_target :
5- types : [opened, synchronize]
4+ pull_request :
5+ branches : [main]
6+ workflow_dispatch :
67
78jobs :
89 lint :
@@ -27,22 +28,32 @@ jobs:
2728
2829 - name : Run linter
2930 run : |
30- FILES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.zig$' || true)
31- echo "changed files: $FILES"
31+ echo "Base SHA: ${{ github.event.pull_request.base.sha }}"
32+ echo "Head SHA: ${{ github.event.pull_request.head.sha }}"
33+
34+ # Get changed .zig files
35+ FILES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.zig$' || true)
36+ echo "Changed files: $FILES"
37+
3238 if [ -n "$FILES" ]; then
33- ./tools/linter/zig-out/bin/linter $FILES > lint_results.json
39+ echo "$FILES" | xargs ./tools/linter/zig-out/bin/linter > lint_results.json
3440 else
3541 echo "[]" > lint_results.json
3642 fi
3743
38- - name : Post comments
44+ # Debug output
45+ echo "Lint results:"
46+ cat lint_results.json
47+
48+
49+ - name : Post comments with metadata
3950 uses : actions/github-script@v7
4051 with :
4152 github-token : ${{ secrets.GITHUB_TOKEN }}
4253 script : |
4354 const fs = require('fs');
55+ const crypto = require('crypto');
4456
45- // Check if lint results file exists and has content
4657 if (!fs.existsSync('lint_results.json')) {
4758 console.log('No lint results file found');
4859 return;
5566 }
5667
5768 const issues = JSON.parse(content);
58- console.log(`Found ${issues.length} lint issues`);
69+
70+ const existingComments = await github.rest.pulls.listReviewComments({
71+ owner: context.repo.owner,
72+ repo: context.repo.repo,
73+ pull_number: context.issue.number
74+ });
75+
76+ const botComments = existingComments.data.filter(comment =>
77+ comment.user.login === 'github-actions[bot]' &&
78+ comment.body.includes('<!-- lint-comment')
79+ );
80+
81+ const existingHashes = new Set();
82+ botComments.forEach(comment => {
83+ const match = comment.body.match(/<!-- lint-comment:(\w+) -->/);
84+ if (match) existingHashes.add(match[1]);
85+ });
86+
87+ let postedCount = 0;
88+ let skippedCount = 0;
5989
6090 for (const issue of issues) {
91+ const issueData = `${issue.file}:${issue.line}:${issue.message}`;
92+ const issueHash = crypto.createHash('md5').update(issueData).digest('hex').substring(0, 8);
93+
94+ if (existingHashes.has(issueHash)) {
95+ console.log(`Skipping duplicate issue: ${issueHash}`);
96+ skippedCount++;
97+ continue;
98+ }
99+
100+ const commentBody = `${issue.message}\n\n<!-- lint-comment:${issueHash} -->\n`;
101+ console.log(`comment body:`, commentBody);
102+
61103 try {
62104 await github.rest.pulls.createReviewComment({
63105 owner: context.repo.owner,
@@ -66,10 +108,12 @@ jobs:
66108 commit_id: context.payload.pull_request.head.sha,
67109 path: issue.file,
68110 line: issue.line,
69- body: issue.message
111+ body: commentBody
70112 });
71- console.log(`Posted comment for ${issue.file}:${issue.line}`) ;
113+ postedCount++ ;
72114 } catch (error) {
73- console.error(`Failed to post comment for ${issue.file}:${issue.line} :`, error.message);
115+ console.error(`Failed to post comment:`, error.message);
74116 }
75117 }
118+
119+ console.log(`Posted ${postedCount} new comments, skipped ${skippedCount} duplicates`);
0 commit comments