-
-
Notifications
You must be signed in to change notification settings - Fork 450
102 lines (86 loc) · 3.22 KB
/
comment-clippy-warnings.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Clippy Check
on:
pull_request:
branches: [master]
types: [opened, reopened, synchronize, ready_for_review]
jobs:
clippy:
name: Run Clippy
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: Install deps
run: |
sudo apt update
sudo apt install libgtk-3-dev libsoup2.4-dev libjavascriptcoregtk-4.0-dev libwebkit2gtk-4.0-dev
- name: Run Clippy
id: clippy
run: |
# Run Clippy and filter output for the root workspace
CLIPPY_OUTPUT=$(cargo clippy --all-targets --all-features -- -W clippy::all 2>&1 | grep -vE "^(\s*Updating|\s*Download|\s*Compiling|\s*Checking|Finished)")
# Run Clippy and filter output for /libraries/rawkit
cd libraries/rawkit
CLIPPY_OUTPUT+=$'\n\n'
CLIPPY_OUTPUT+=$(cargo clippy --all-targets --all-features -- -W clippy::all 2>&1 | grep -vE "^(\s*Updating|\s*Download|\s*Compiling|\s*Checking|Finished)")
cd ../..
# Escape special characters for JSON
ESCAPED_OUTPUT=$(echo "$CLIPPY_OUTPUT" | jq -sR .)
echo "CLIPPY_OUTPUT=$ESCAPED_OUTPUT" >> $GITHUB_OUTPUT
if echo "$CLIPPY_OUTPUT" | grep -qE "^(warning|error)"; then
echo "CLIPPY_ISSUES_FOUND=true" >> $GITHUB_OUTPUT
else
echo "CLIPPY_ISSUES_FOUND=false" >> $GITHUB_OUTPUT
fi
- name: Delete previous comments
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComments = comments.filter((comment) =>
comment.user.type === 'Bot' && comment.body.includes('Clippy Warnings/Errors')
);
for (const comment of botComments) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
});
}
- name: Comment PR
if: steps.clippy.outputs.CLIPPY_ISSUES_FOUND == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const clippy_output = ${{ steps.clippy.outputs.CLIPPY_OUTPUT }};
const output = `
<details open>
<summary>Found Clippy warnings</summary>
#### Clippy Warnings/Errors
\`\`\`
${clippy_output}
\`\`\`
</details>
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})