-
Notifications
You must be signed in to change notification settings - Fork 3
181 lines (165 loc) · 6.06 KB
/
Copy pathcontributor-check.yml
File metadata and controls
181 lines (165 loc) · 6.06 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Contributor Security Check
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
security-events: write
jobs:
contributor-validation:
name: Validate Contributor Changes
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check PR Author
shell: pwsh
run: |
$author = $env:GITHUB_ACTOR
$prNumber = $env:GITHUB_EVENT_NUMBER
Write-Host "PR Author: $author"
Write-Host "PR Number: $prNumber"
# Additional validation can be added here
- name: Analyze Changed Files
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
$baseRef = $env:GITHUB_BASE_REF
$changedFiles = git diff --name-only "origin/$baseRef"
} else {
$changedFiles = git diff --name-only HEAD~1
}
Write-Host "Changed files:"
$changedFiles | ForEach-Object { Write-Host " $_" }
# Check for changes to critical files
$criticalFiles = @(
'windowstelemetryblocker.ps1',
'modules/common.ps1',
'run.bat'
)
$criticalChanges = @()
foreach ($file in $criticalFiles) {
if ($changedFiles -contains $file) {
$criticalChanges += $file
}
}
if ($criticalChanges.Count -gt 0) {
Write-Host "[INFO] Critical files changed (review required): $($criticalChanges -join ', ')"
}
- name: Check for Suspicious Additions
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
$baseRef = $env:GITHUB_BASE_REF
$addedFiles = git diff --name-only --diff-filter=A "origin/$baseRef"
} else {
$addedFiles = git diff --name-only --diff-filter=A HEAD~1
}
$suspicious = @()
foreach ($file in $addedFiles) {
# Check for suspicious file types or locations
if ($file -match '\.(exe|dll|bat|cmd|vbs|js|jar)$' -and $file -notmatch 'run\.bat') {
$suspicious += $file
}
if ($file -match 'node_modules|\.git|temp|tmp') {
$suspicious += $file
}
}
if ($suspicious.Count -gt 0) {
Write-Host "[WARN] Suspicious files added:"
$suspicious | ForEach-Object { Write-Host " $_" }
} else {
Write-Host "[OK] No suspicious files added"
}
- name: Check for Large File Additions
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
$baseRef = $env:GITHUB_BASE_REF
$addedFiles = git diff --name-only --diff-filter=A "origin/$baseRef"
} else {
$addedFiles = git diff --name-only --diff-filter=A HEAD~1
}
$largeFiles = @()
foreach ($file in $addedFiles) {
if (Test-Path $file) {
$size = (Get-Item $file).Length
if ($size -gt 1MB) {
$largeFiles += "$file ($([math]::Round($size/1MB, 2)) MB)"
}
}
}
if ($largeFiles.Count -gt 0) {
Write-Host "[WARN] Large files added (consider Git LFS):"
$largeFiles | ForEach-Object { Write-Host " $_" }
} else {
Write-Host "[OK] No large files added"
}
- name: Validate Code Style Consistency
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
$baseRef = $env:GITHUB_BASE_REF
$changedScripts = git diff --name-only "origin/$baseRef" | Where-Object { $_ -like '*.ps1' }
} else {
$changedScripts = git diff --name-only HEAD~1 | Where-Object { $_ -like '*.ps1' }
}
$styleIssues = @()
foreach ($script in $changedScripts) {
if (Test-Path $script) {
$content = Get-Content $script -Raw
# Check for consistent region usage
if ($content -match 'region' -and $content -notmatch '#region') {
$styleIssues += "${script}: Inconsistent region syntax"
}
# Check for proper indentation (basic check)
$lines = $content -split "`n"
for ($i = 0; $i -lt [Math]::Min(50, $lines.Count); $i++) {
if ($lines[$i] -match '^\s{1,3}[^#\s]' -and $lines[$i] -notmatch '^\s{4}') {
# Allow for some flexibility in indentation
continue
}
}
}
}
if ($styleIssues.Count -gt 0) {
Write-Host "[WARN] Code style issues:"
$styleIssues | ForEach-Object { Write-Host " $_" }
} else {
Write-Host "[OK] Code style is consistent"
}
- name: Check for Test Coverage
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
$baseRef = $env:GITHUB_BASE_REF
$changedScripts = git diff --name-only "origin/$baseRef" | Where-Object { $_ -like '*.ps1' -and $_ -notlike '*test*.ps1' }
} else {
$changedScripts = git diff --name-only HEAD~1 | Where-Object { $_ -like '*.ps1' -and $_ -notlike '*test*.ps1' }
}
if ($changedScripts.Count -gt 0) {
Write-Host "[INFO] Changed scripts (consider adding tests):"
$changedScripts | ForEach-Object { Write-Host " $_" }
}
- name: Comment PR with Validation Results
if: always()
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const results = `## Contributor Security Check Results
✅ All security checks passed!
This PR has been validated for:
- Code syntax and structure
- Security patterns
- File integrity
- Contribution guidelines
Thank you for your contribution!`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: results
});