Repository navigation
91 lines (76 loc) · 2.99 KB
/
Copy pathdeadcode.yml
File metadata and controls
91 lines (76 loc) · 2.99 KB
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
name: Deadcode Analysis
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
# Run weekly on Sundays at 2 AM UTC
- cron: '0 2 * * 0'
jobs:
deadcode-analysis:
name: Deadcode Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Install dependencies
run: |
go install golang.org/x/tools/cmd/deadcode@latest
sudo apt-get update
sudo apt-get install -y jq
- name: Run deadcode analysis
run: |
chmod +x scripts/deadcode-ci.sh
./scripts/deadcode-ci.sh --max-prod 100 --max-tests 200 --max-test-only 50
- name: Upload deadcode report
uses: actions/upload-artifact@v3
if: always()
with:
name: deadcode-report
path: deadcode-report.json
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = require('path');
// Read deadcode report if it exists
let report = null;
try {
const reportPath = path.join(process.cwd(), 'deadcode-report.json');
if (fs.existsSync(reportPath)) {
report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
}
} catch (error) {
console.log('Could not read deadcode report:', error.message);
}
// Generate comment
let comment = '## 🔍 Deadcode Analysis Results\n\n';
if (report) {
comment += `- **Production dead code**: ${report.results.production_dead_code_count} functions\n`;
comment += `- **Dead code with tests**: ${report.results.dead_code_with_tests_count} functions\n`;
comment += `- **Test-only functions**: ${report.results.test_only_functions_count} functions\n\n`;
if (report.results.production_dead_code_count > 0) {
comment += '⚠️ **Warning**: Production dead code detected. Consider removing unreachable functions.\n\n';
}
if (report.results.test_only_functions_count > 20) {
comment += '⚠️ **Warning**: High number of test-only functions. Consider if these are needed.\n\n';
}
comment += 'For detailed analysis, run `make deadcode` locally.\n';
} else {
comment += 'Deadcode analysis completed successfully.\n';
comment += 'For detailed results, check the workflow artifacts.\n';
}
// Post comment
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});