Skip to content

Commit 028b1e0

Browse files
committed
resharper-code-checkを追加
1 parent 3e5ee27 commit 028b1e0

2 files changed

Lines changed: 164 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ permissions:
1111
pages: write # GitHub Pages ブランチへの書き込み権限
1212

1313
jobs:
14+
code-quality:
15+
name: Code Quality Check 🔍
16+
uses: ./.github/workflows/resharper-code-check.yml
17+
1418
build:
1519
name: Build my project 🏗️
1620
runs-on: ubuntu-latest
21+
needs: code-quality
1722
steps:
1823
- name: Free up disk space 🧹
1924
run: |
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: ReSharper Code Quality Check
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
workflow_call:
9+
10+
jobs:
11+
code-quality:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v4
20+
with:
21+
dotnet-version: '8.0.x'
22+
23+
- name: Cache NuGet packages
24+
uses: actions/cache@v3
25+
with:
26+
path: ~/.nuget/packages
27+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-nuget-
30+
31+
- name: Install ReSharper Command Line Tools
32+
run: |
33+
dotnet tool install -g JetBrains.ReSharper.GlobalTools
34+
35+
- name: Restore NuGet packages
36+
run: dotnet restore void-red.sln
37+
38+
- name: Verify ReSharper settings file exists
39+
run: |
40+
if [ -f void-red.sln.DotSettings ]; then
41+
echo "✅ Rider設定ファイル (void-red.sln.DotSettings) が見つかりました"
42+
echo "設定ファイルの内容:"
43+
head -n 10 void-red.sln.DotSettings
44+
else
45+
echo "❌ Rider設定ファイルが見つかりません"
46+
exit 1
47+
fi
48+
49+
- name: Run ReSharper Code Inspection
50+
run: |
51+
jb inspectcode void-red.sln \
52+
--output=inspectcode-results.xml \
53+
--format=xml \
54+
--severity=WARNING \
55+
--settings=void-red.sln.DotSettings \
56+
--exclude="**/*.Generated.cs;**/obj/**;**/bin/**;**/Library/**;**/Temp/**;**/Packages/**;**/PackageCache/**" \
57+
--verbosity=WARN
58+
59+
- name: Check inspection results
60+
run: |
61+
if [ -f inspectcode-results.xml ]; then
62+
# XMLファイルから警告やエラーの数を抽出
63+
ISSUES=$(grep -c '<Issue' inspectcode-results.xml || echo "0")
64+
echo "Found $ISSUES code quality issues"
65+
66+
if [ "$ISSUES" -gt 0 ]; then
67+
echo "::warning::Found $ISSUES code quality issues"
68+
69+
# 主要な問題を表示
70+
echo "## Code Quality Issues:" >> $GITHUB_STEP_SUMMARY
71+
echo "" >> $GITHUB_STEP_SUMMARY
72+
73+
# XMLから問題の詳細を抽出して表示
74+
python3 -c "
75+
import xml.etree.ElementTree as ET
76+
import sys
77+
import os
78+
79+
try:
80+
tree = ET.parse('inspectcode-results.xml')
81+
root = tree.getroot()
82+
83+
issues_found = False
84+
for issue in root.findall('.//Issue'):
85+
issues_found = True
86+
type_id = issue.get('TypeId', 'Unknown')
87+
file_path = issue.get('File', 'Unknown')
88+
line = issue.get('Line', 'Unknown')
89+
severity = issue.get('Severity', 'Unknown')
90+
message = issue.get('Message', 'No message')
91+
92+
# GitHub Actionsのサマリーに追加
93+
summary_line = f'**{severity}**: {type_id} in {file_path}:{line}'
94+
print(summary_line)
95+
96+
# GitHub Actionsのアノテーションとして出力
97+
if severity in ['ERROR', 'WARNING']:
98+
annotation_type = 'error' if severity == 'ERROR' else 'warning'
99+
print(f'::{\annotation_type} file={file_path},line={line}::{type_id}: {message}')
100+
101+
if not issues_found:
102+
print('No issues found!')
103+
104+
except Exception as e:
105+
print(f'Error parsing results: {e}')
106+
sys.exit(1)
107+
" >> $GITHUB_STEP_SUMMARY
108+
109+
# エラーレベルの問題があった場合はfailさせる
110+
ERROR_COUNT=$(grep -c 'Severity=\"ERROR\"' inspectcode-results.xml || echo "0")
111+
if [ "$ERROR_COUNT" -gt 0 ]; then
112+
echo "::error::Found $ERROR_COUNT error-level issues"
113+
exit 1
114+
fi
115+
else
116+
echo "✅ No code quality issues found!" >> $GITHUB_STEP_SUMMARY
117+
fi
118+
else
119+
echo "::error::Inspection results file not found"
120+
exit 1
121+
fi
122+
123+
- name: Upload inspection results
124+
uses: actions/upload-artifact@v3
125+
if: always()
126+
with:
127+
name: resharper-inspection-results
128+
path: inspectcode-results.xml
129+
retention-days: 30
130+
131+
- name: Comment PR with results
132+
if: github.event_name == 'pull_request'
133+
uses: actions/github-script@v7
134+
with:
135+
script: |
136+
const fs = require('fs');
137+
138+
if (fs.existsSync('inspectcode-results.xml')) {
139+
const xml = fs.readFileSync('inspectcode-results.xml', 'utf8');
140+
const issueCount = (xml.match(/<Issue/g) || []).length;
141+
142+
let comment = `## ReSharper Code Quality Check Results\n\n`;
143+
144+
if (issueCount === 0) {
145+
comment += `✅ **No code quality issues found!**\n\n`;
146+
comment += `Great job! Your code follows the project's coding standards.`;
147+
} else {
148+
comment += `⚠️ **Found ${issueCount} code quality issue(s)**\n\n`;
149+
comment += `Please review the [inspection results](${context.payload.pull_request.html_url}/checks) and fix the issues.\n\n`;
150+
comment += `The detailed results have been uploaded as an artifact.`;
151+
}
152+
153+
github.rest.issues.createComment({
154+
issue_number: context.issue.number,
155+
owner: context.repo.owner,
156+
repo: context.repo.repo,
157+
body: comment
158+
});
159+
}

0 commit comments

Comments
 (0)