forked from ElTheLedge/Audio-Over-IP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_prod_bundle_with_licenses.ps1
More file actions
228 lines (181 loc) · 6.46 KB
/
create_prod_bundle_with_licenses.ps1
File metadata and controls
228 lines (181 loc) · 6.46 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# build_release.ps1
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$ProjectRoot = (Get-Location).Path
$GoPackage = "AuOvIP"
$FrontendDir = Join-Path $ProjectRoot "frontend"
$OutputDir = Join-Path $ProjectRoot "THIRD_PARTY_LICENSES"
$ZipName = "build/bin/AudioOverIP_release-Windows_x64.zip"
$BinaryPath = Join-Path $ProjectRoot "build/bin/AudioOverIP.exe"
Write-Host "Cleaning old output..."
if (Test-Path $OutputDir) { Remove-Item $OutputDir -Recurse -Force }
if (Test-Path $ZipName) { Remove-Item $ZipName -Force }
New-Item -ItemType Directory -Path $OutputDir | Out-Null
##############################################
# Helper: Download GitHub license for exact tag
##############################################
function Get-GitHubVersionedLicense {
param(
[string]$Url,
[string]$OutFile
)
# Match: github.com/<owner>/<repo>/blob/<tag>/<path>
$regex = "github\.com/([^/]+)/([^/]+)/blob/([^/]+)/(.*)$"
$match = [regex]::Match($Url, $regex)
if (-not $match.Success) {
return $false
}
$Owner = $match.Groups[1].Value
$RepoName = $match.Groups[2].Value
$Tag = $match.Groups[3].Value
$FilePath = $match.Groups[4].Value
$RawUrl = "https://raw.githubusercontent.com/$Owner/$RepoName/refs/tags/$Tag/$FilePath"
try {
Invoke-WebRequest -Uri $RawUrl -OutFile $OutFile -UseBasicParsing
if ((Get-Content $OutFile -Raw).Length -gt 0) {
return $true
}
}
catch {
return $false
}
return $false
}
##############################################
# 1. Collect Go dependency licenses
##############################################
Write-Host "Collecting Go dependency licenses..."
$GoLicenses = go-licenses report $GoPackage
foreach ($line in $GoLicenses) {
$parts = $line -split ","
$PkgName = $parts[0]
$LicenseUrl = $parts[1]
$LicenseType = $parts[2]
$SafeName = $PkgName -replace "[/@:]", "__"
$OutFile = Join-Path $OutputDir ("go_" + $SafeName + ".txt")
Write-Host "Processing Go package: $PkgName"
# Skip cs.opensource.google (no raw download available)
if ($LicenseUrl -like "https://cs.opensource.google*") {
Set-Content $OutFile @(
"Package: $PkgName"
"License: $LicenseType"
"Source: $LicenseUrl"
""
"This license is hosted on cs.opensource.google, which does not provide raw file downloads."
"Please visit the URL manually to view the license."
)
continue
}
# Regex to match any version number like v2.11.0
$pattern = 'https:\/\/github\.com\/wailsapp\/wails\/blob\/v\d+\.\d+\.\d+\/v2\/LICENSE'
if ($LicenseUrl -match $pattern) {
# Remove the "v2/" part after the version
$LicenseUrl = $LicenseUrl -replace '/v2/', '/'
}
$Downloaded = $false
# Prefer exact versioned GitHub license
if ($LicenseUrl -like "https://github.com/*/blob/*") {
$Downloaded = Get-GitHubVersionedLicense -Url $LicenseUrl -OutFile $OutFile
}
# Fallback: direct download
if (-not $Downloaded) {
try {
Invoke-WebRequest -Uri $LicenseUrl -OutFile $OutFile -UseBasicParsing
$Downloaded = $true
}
catch {
Write-Warning "Failed to download license for $PkgName"
continue
}
}
$Header = "Package: $PkgName`nLicense: $LicenseType`nSource: $LicenseUrl`n`n"
$Content = Get-Content $OutFile -Raw
Set-Content -Path $OutFile -Value ($Header + $Content)
}
##############################################
# 2. Collect npm dependency licenses
##############################################
Write-Host "Collecting npm dependency licenses..."
Push-Location $FrontendDir
$NpmLicenses = npx license-checker-rseidelsohn --production --csv
Pop-Location
# Skip header
$NpmLicenses = $NpmLicenses | Select-Object -Skip 1
foreach ($line in $NpmLicenses) {
# Parse CSV safely
$parts = $line -split ",(?=(?:[^""]*""[^""]*"")*[^""]*$)"
$Module = $parts[0].Trim('"')
$License = $parts[1].Trim('"')
$Repo = $parts[2].Trim('"')
# Skip internal package
if ($Module -eq "@deejayy/audio-over-ip_frontend@0.0.0") {
Write-Host "Skipping internal package: $Module"
continue
}
$SafeName = $Module -replace "[/@:]", "__"
$OutFile = Join-Path $OutputDir ("npm_" + $SafeName + ".txt")
Write-Host "Processing npm module: $Module"
$Downloaded = $false
# If GitHub repo → download LICENSE from repo root (HEAD)
if ($Repo -like "https://github.com/*") {
$OwnerRepo = $Repo -replace "https://github.com/", ""
$Owner, $RepoName = $OwnerRepo -split "/"
$RawUrl = "https://raw.githubusercontent.com/$Owner/$RepoName/HEAD/LICENSE"
try {
Invoke-WebRequest -Uri $RawUrl -OutFile $OutFile -UseBasicParsing
if ((Get-Content $OutFile -Raw).Length -gt 0) {
$Downloaded = $true
}
}
catch {
# fallback below
}
}
# Fallback: metadata only
if (-not $Downloaded) {
Set-Content $OutFile @(
"Module: $Module"
"License: $License"
"Repository: $Repo"
""
"License text could not be automatically retrieved."
)
}
else {
$Header = "Module: $Module`nLicense: $License`nRepository: $Repo`n`n"
$Content = Get-Content $OutFile -Raw
Set-Content -Path $OutFile -Value ($Header + $Content)
}
}
##############################################
# 3. Create ZIP archive
##############################################
Write-Host "Creating release ZIP..."
Compress-Archive -Path @(
$BinaryPath
(Join-Path $ProjectRoot "LICENSE")
$OutputDir
) -DestinationPath $ZipName -Force
##############################################
# 4. Print license summary
##############################################
Write-Host ""
Write-Host "========== LICENSE SUMMARY =========="
$LicenseCounts = @{}
Get-ChildItem $OutputDir -File | ForEach-Object {
$content = Get-Content $_.FullName -Raw
if ($content -match "License:\s*([A-Za-z0-9\.\-_]+)") {
$lic = $Matches[1]
if ($LicenseCounts.ContainsKey($lic)) {
$LicenseCounts[$lic]++
}
else {
$LicenseCounts[$lic] = 1
}
}
}
foreach ($key in $LicenseCounts.Keys) {
Write-Host "$key : $($LicenseCounts[$key])"
}
Write-Host "====================================="
Write-Host "Done! Created: $ZipName"