forked from violetljj/blind-assist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_open_source_readiness.ps1
More file actions
187 lines (174 loc) · 7.77 KB
/
Copy pathcheck_open_source_readiness.ps1
File metadata and controls
187 lines (174 loc) · 7.77 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
181
182
183
184
185
186
187
param(
[string]$RepoRoot = (Join-Path $PSScriptRoot '..')
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$resolvedRoot = (Resolve-Path -LiteralPath $RepoRoot).Path
$rootPrefix = $resolvedRoot.TrimEnd([System.IO.Path]::DirectorySeparatorChar) + [System.IO.Path]::DirectorySeparatorChar
$failures = [Collections.Generic.List[string]]::new()
$manifest = $null
function Resolve-PublicPath([string]$RelativePath) {
$candidate = [System.IO.Path]::GetFullPath((Join-Path $resolvedRoot $RelativePath))
if (-not $candidate.StartsWith($rootPrefix, [StringComparison]::OrdinalIgnoreCase)) {
throw "Public asset path escapes the repository: $RelativePath"
}
return $candidate
}
function Require-File([string]$RelativePath) {
$path = Resolve-PublicPath $RelativePath
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
$failures.Add("Missing open-source maintenance file: $RelativePath")
}
return $path
}
$requiredFiles = @(
'README.md',
'LICENSE',
'THIRD_PARTY_NOTICES.md',
'CONTRIBUTING.md',
'SECURITY.md',
'CODE_OF_CONDUCT.md',
'GOVERNANCE.md',
'CITATION.cff',
'docs/OPEN_SOURCE_PUBLIC_VALUE.md',
'docs/CODEX_MAINTAINER_AUTOMATION.md',
'docs/THREAT_MODEL.md',
'docs/MODEL_CARD.md',
'.github/CODEOWNERS',
'.github/dependabot.yml',
'.github/ISSUE_TEMPLATE/bug_report.yml',
'.github/ISSUE_TEMPLATE/feature_request.yml',
'.github/pull_request_template.md',
'.github/workflows/android.yml',
'.github/workflows/codeql.yml',
'.github/workflows/release.yml',
'configs/public_release_assets.json'
)
foreach ($relativePath in $requiredFiles) {
Require-File $relativePath | Out-Null
}
$manifestPath = Resolve-PublicPath 'configs/public_release_assets.json'
$verifiedAssets = @()
if (Test-Path -LiteralPath $manifestPath -PathType Leaf) {
try {
$manifest = Get-Content -Raw -LiteralPath $manifestPath -Encoding UTF8 | ConvertFrom-Json
if ($manifest.schema -ne 'blindassist_public_release_assets_v1') {
$failures.Add("Unexpected public asset manifest schema: $($manifest.schema)")
}
if (-not $manifest.assets -or @($manifest.assets).Count -eq 0) {
$failures.Add('Public asset manifest must declare at least one asset.')
}
foreach ($asset in @($manifest.assets)) {
$relativeAssetPath = [string]$asset.path
$assetPath = Resolve-PublicPath $relativeAssetPath
if (-not (Test-Path -LiteralPath $assetPath -PathType Leaf)) {
$failures.Add("Declared public asset is missing: $relativeAssetPath")
continue
}
$actualSize = (Get-Item -LiteralPath $assetPath).Length
$actualHash = (Get-FileHash -LiteralPath $assetPath -Algorithm SHA256).Hash
if ($actualSize -ne [long]$asset.size_bytes) {
$failures.Add("Public asset size mismatch for $relativeAssetPath. Expected $($asset.size_bytes), got $actualSize.")
}
if (-not $actualHash.Equals([string]$asset.sha256, [StringComparison]::OrdinalIgnoreCase)) {
$failures.Add("Public asset SHA-256 mismatch for $relativeAssetPath. Expected $($asset.sha256), got $actualHash.")
}
if (-not [string]$asset.license_expression -or -not [string]$asset.upstream_url -or -not [string]$asset.notice_path) {
$failures.Add("Public asset provenance is incomplete for $relativeAssetPath.")
}
else {
$noticePath = Resolve-PublicPath ([string]$asset.notice_path)
if (-not (Test-Path -LiteralPath $noticePath -PathType Leaf)) {
$failures.Add("Public asset notice is missing for ${relativeAssetPath}: $($asset.notice_path)")
}
elseif ((Get-Content -Raw -LiteralPath $noticePath -Encoding UTF8) -notmatch [regex]::Escape($relativeAssetPath)) {
$failures.Add("Public asset notice does not name $relativeAssetPath.")
}
}
$verifiedAssets += [pscustomobject][ordered]@{
path = $relativeAssetPath
sizeBytes = $actualSize
sha256 = $actualHash
licenseExpression = [string]$asset.license_expression
}
}
}
catch {
$failures.Add("Could not validate public asset manifest: $($_.Exception.Message)")
}
}
$readmePath = Resolve-PublicPath 'README.md'
if (Test-Path -LiteralPath $readmePath -PathType Leaf) {
$readme = Get-Content -Raw -LiteralPath $readmePath -Encoding UTF8
foreach ($requiredLink in @(
'CONTRIBUTING.md',
'GOVERNANCE.md',
'docs/MODEL_CARD.md',
'docs/CODEX_MAINTAINER_AUTOMATION.md',
'docs/THREAT_MODEL.md',
'SECURITY.md'
)) {
if ($readme -notmatch [regex]::Escape($requiredLink)) {
$failures.Add("README.md must link to $requiredLink.")
}
}
}
$modelCardPath = Resolve-PublicPath 'docs/MODEL_CARD.md'
if ((Test-Path -LiteralPath $modelCardPath -PathType Leaf) -and $null -ne $manifest) {
$modelCard = Get-Content -Raw -LiteralPath $modelCardPath -Encoding UTF8
foreach ($asset in @($manifest.assets)) {
if ([bool]$asset.packaged_in_default_app) {
if ($modelCard -notmatch [regex]::Escape([string]$asset.path) -or
$modelCard -notmatch [regex]::Escape([string]$asset.sha256)) {
$failures.Add("Default App asset is not identity-bound in docs/MODEL_CARD.md: $($asset.path)")
}
}
}
}
$androidWorkflowPath = Resolve-PublicPath '.github/workflows/android.yml'
if (Test-Path -LiteralPath $androidWorkflowPath -PathType Leaf) {
$androidWorkflow = Get-Content -Raw -LiteralPath $androidWorkflowPath -Encoding UTF8
if ($androidWorkflow -notmatch 'check_open_source_readiness\.ps1') {
$failures.Add('Android CI must run scripts/check_open_source_readiness.ps1.')
}
}
$releaseWorkflowPath = Resolve-PublicPath '.github/workflows/release.yml'
if (Test-Path -LiteralPath $releaseWorkflowPath -PathType Leaf) {
$releaseWorkflow = Get-Content -Raw -LiteralPath $releaseWorkflowPath -Encoding UTF8
foreach ($requiredReleaseStep in @('verify_release_apk.ps1', 'generate_release_manifest.ps1')) {
if ($releaseWorkflow -notmatch [regex]::Escape($requiredReleaseStep)) {
$failures.Add("Release workflow must run $requiredReleaseStep.")
}
}
}
$codeqlWorkflowPath = Resolve-PublicPath '.github/workflows/codeql.yml'
if (Test-Path -LiteralPath $codeqlWorkflowPath -PathType Leaf) {
$codeqlWorkflow = Get-Content -Raw -LiteralPath $codeqlWorkflowPath -Encoding UTF8
$codeqlActionReferences = [regex]::Matches(
$codeqlWorkflow,
'uses:\s*github/codeql-action/[^@\s]+@([^\s#]+)'
)
if ($codeqlActionReferences.Count -lt 2) {
$failures.Add('CodeQL workflow must initialize and analyze the repository.')
}
foreach ($reference in $codeqlActionReferences) {
if ($reference.Groups[1].Value -notmatch '^[0-9a-f]{40}$') {
$failures.Add("CodeQL action must be pinned to a full commit SHA: $($reference.Value)")
}
}
if ($codeqlWorkflow -notmatch 'build-mode:\s*manual') {
$failures.Add('CodeQL must use a manual build for Java and Kotlin sources.')
}
if ($codeqlWorkflow -notmatch '(?m)^\s*assembleDebug\s*$') {
$failures.Add('CodeQL manual analysis must compile Android debug sources with assembleDebug.')
}
}
if ($failures.Count -gt 0) {
throw "Open-source readiness failed:`n- $($failures -join "`n- ")"
}
[pscustomobject][ordered]@{
status = 'PASS'
schema = 'blindassist_open_source_readiness_v1'
requiredFiles = $requiredFiles.Count
verifiedAssets = $verifiedAssets
} | ConvertTo-Json -Depth 5