-
-
Notifications
You must be signed in to change notification settings - Fork 208
114 lines (107 loc) · 4.45 KB
/
detekt.yml
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
103
104
105
106
107
108
109
110
111
112
113
114
name: Detekt
on:
pull_request_target:
branches:
- "*"
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
detekt:
name: Run detekt
runs-on: ubuntu-latest
concurrency:
group: detekt-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
outputs:
sarif_exists: ${{ steps.check_sarif.outputs.exists }}
steps:
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- uses: ./.github/actions/setup-normal-workspace
- name: Run detekt main (w/ typing analysis)
run: |
./gradlew detektMain --stacktrace
- name: Check if SARIF file exists
if: always()
id: check_sarif
run: |
if [ -f "versions/1.8.9/build/reports/detekt/main.sarif" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Add label if detekt fails
if: ${{ failure() && steps.check_sarif.outputs.exists == 'true' }}
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Detekt'
- name: Remove label if detekt passes
if: success()
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Detekt'
- name: Annotate detekt failures
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
run: |
chmod +x .github/scripts/process_detekt_sarif.sh
./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif | tee detekt_output.txt
- name: Upload detekt output as artifact
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
uses: actions/upload-artifact@v4
with:
name: detekt-output
path: detekt_output.txt
detekt_comment:
name: Comment detekt failures on PR
runs-on: ubuntu-latest
concurrency:
group: detekt-comment-${{ github.event.pull_request.number }}
cancel-in-progress: true
needs: detekt
if: ${{ needs.detekt.outputs.sarif_exists == 'true' && failure() }}
permissions:
pull-requests: write
steps:
- name: Checkout base repo code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Download detekt output
uses: actions/download-artifact@v4
with:
name: detekt-output
path: .
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '>=21'
- name: Process detekt output and create comment
env:
PR_SHA: ${{ github.event.pull_request.head.sha }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
node .github/scripts/process_detekt_output.js
- name: Add comment to PR
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const commentBody = fs.readFileSync('detekt_comment.txt', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})