-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-OpenStackRepos.ps1
More file actions
443 lines (364 loc) Β· 17.8 KB
/
Copy pathGet-OpenStackRepos.ps1
File metadata and controls
443 lines (364 loc) Β· 17.8 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<#
.SYNOPSIS
Clona todos os repositΓ³rios do OpenStack e faz checkout na ΓΊltima tag estΓ‘vel de uma release.
.DESCRIPTION
Consulta os metadados de release do OpenStack (via GitHub mirror do repo openstack/releases),
identifica a ΓΊltima versΓ£o estΓ‘vel de cada projeto, clona os repositΓ³rios a partir do
servidor oficial (opendev.org) e faz checkout na tag correspondente.
O script lida com:
- 200+ projetos em paralelo
- Retomada: repositΓ³rios jΓ‘ clonados sΓ£o pulados automaticamente
- VersΓ΅es de prΓ©-release (RC, alpha, beta) sΓ£o ignoradas
- MΓΊltiplos repositΓ³rios por deliverable
- GeraΓ§Γ£o de relatΓ³rio CSV ao final
.PARAMETER Release
Codinome da release OpenStack (minΓΊsculas). Exemplos:
gazpacho β 2026.1 (padrΓ£o β ΓΊltima estΓ‘vel mantida, lanΓ§ada 2026-04-01)
flamingo β 2025.2
epoxy β 2025.1
dalmatian β 2024.2
Lista completa: https://releases.openstack.org/
.PARAMETER OutputDir
DiretΓ³rio raiz onde os repositΓ³rios serΓ£o clonados.
Estrutura criada: <OutputDir>/<namespace>/<repo>
PadrΓ£o: ".\openstack-repos"
.PARAMETER ThrottleLimit
NΓΊmero de operaΓ§Γ΅es de clone simultΓ’neas (PowerShell 7 ForEach-Object -Parallel).
Valores muito altos podem saturar a rede ou o servidor. PadrΓ£o: 4.
.PARAMETER Shallow
$true β clone superficial (--depth 1 --branch <tag>). Muito mais rΓ‘pido,
ocupa menos disco. Ideal para build, leitura de cΓ³digo. (padrΓ£o)
$false β clone completo com histΓ³rico inteiro.
.PARAMETER CloneServer
Servidor base para git clone.
opendev β https://opendev.org (oficial, padrΓ£o)
github β https://github.com (mirror β use se opendev.org estiver lento)
.PARAMETER Filter
Regex para filtrar repositΓ³rios pelo nome completo (ex: "openstack/nova",
"nova|cinder|neutron"). Se omitido, clona tudo.
.PARAMETER GitHubToken
Personal Access Token do GitHub para aumentar o rate limit da API
(60 req/h sem token β 5000 req/h com token).
O token Γ© usado apenas para a chamada de listagem, nΓ£o para git clone.
.EXAMPLE
# Clonar tudo na release padrΓ£o (epoxy / 2025.1), clone superficial
.\Get-OpenStackRepos.ps1
.EXAMPLE
# Release anterior, clone completo, outro diretΓ³rio
.\Get-OpenStackRepos.ps1 -Release dalmatian -Shallow $false -OutputDir D:\openstack
.EXAMPLE
# Apenas projetos de compute e rede
.\Get-OpenStackRepos.ps1 -Filter "nova|neutron|cinder|keystone|glance|swift"
.EXAMPLE
# Via GitHub mirror, com token para evitar rate limit
.\Get-OpenStackRepos.ps1 -CloneServer github -GitHubToken "ghp_xxxx"
.NOTES
Requer: git no PATH, PowerShell 7+, acesso Γ internet
RelatΓ³rio CSV salvo em: <OutputDir>\_summary.csv
#>
[CmdletBinding()]
param(
[string] $Release = "gazpacho",
[string] $OutputDir = ".\repos\openstack",
[int] $ThrottleLimit = 4,
[bool] $Shallow = $true,
[ValidateSet("opendev", "github")]
[string] $CloneServer = "opendev",
[string] $Filter = "",
[string] $GitHubToken = ""
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Constantes
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$GITHUB_API = "https://api.github.com/repos/openstack/releases/contents/deliverables"
$GITHUB_RAW = "https://raw.githubusercontent.com/openstack/releases/master/deliverables"
$CLONE_SERVERS = @{
opendev = "https://opendev.org"
github = "https://github.com"
}
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# FunΓ§Γ΅es
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function Write-Status {
param([string]$Msg, [string]$Color = "Cyan")
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $Msg" -ForegroundColor $Color
}
function Get-GithubHeaders {
param([string]$Token)
$h = @{ "User-Agent" = "OpenStack-Clone-Script/1.0"; "Accept" = "application/vnd.github.v3+json" }
if ($Token) { $h["Authorization"] = "token $Token" }
return $h
}
function Get-DeliverableList {
param([string]$ReleaseName, [string]$Token)
$url = "$GITHUB_API/$ReleaseName"
$headers = Get-GithubHeaders -Token $Token
try {
$resp = Invoke-RestMethod -Uri $url -Headers $headers -TimeoutSec 60
return $resp | Where-Object { $_.name -like "*.yaml" -and $_.type -eq "file" }
}
catch {
$status = $_.Exception.Response?.StatusCode
if ($status -eq 404) {
Write-Error "Release '$ReleaseName' nΓ£o encontrada no repositΓ³rio de releases."
Write-Error "Verifique o codinome em: https://releases.openstack.org/"
}
elseif ($status -eq 403) {
Write-Error "Rate limit da API do GitHub atingido. Use -GitHubToken <token> para aumentar o limite."
}
else {
Write-Error "Falha ao acessar GitHub API: $_"
}
exit 1
}
}
function ConvertFrom-DeliverableYaml {
<#
Extrai repositΓ³rios e ΓΊltima versΓ£o estΓ‘vel de um YAML de deliverable do OpenStack.
Retorna: [PSCustomObject]@{ Repo; Version } (um por repositΓ³rio)
#>
param([string]$Yaml, [string]$Filename)
# VersΓ΅es estΓ‘veis (excluir RC, alpha, beta)
# Exemplos de prΓ©-release: 31.0.0.0rc1 1.2.3a1 1.0.0b3 2.0.0.0b1
$allVersions = [regex]::Matches($Yaml, '(?m)^\s*-\s+version:\s+(\S+)') |
ForEach-Object { $_.Groups[1].Value.Trim() }
$stableVersions = @($allVersions |
Where-Object { $_ -notmatch 'rc\d*' -and $_ -notmatch '\d[ab]\d' })
if ($stableVersions.Count -eq 0) {
Write-Verbose "Sem versΓ£o estΓ‘vel em: $Filename"
return @()
}
$latestVersion = $stableVersions[-1]
# RepositΓ³rios referenciados nas releases
# Formato YAML: " - repo: openstack/nova"
$repos = @([regex]::Matches($Yaml, '(?m)^\s+-?\s*repo:\s+(\S+)') |
ForEach-Object { $_.Groups[1].Value.Trim() } |
Sort-Object -Unique)
if ($repos.Count -eq 0) {
# Fallback: repository-settings section
# Formato: " openstack/nova: {}"
$repos = @([regex]::Matches($Yaml, '(?m)^ ([a-z][a-z0-9_-]+/[a-z][a-z0-9._-]+):') |
ForEach-Object { $_.Groups[1].Value.Trim() } |
Sort-Object -Unique)
}
if ($repos.Count -eq 0) {
Write-Verbose "Nenhum repositΓ³rio encontrado em: $Filename"
return @()
}
return $repos | ForEach-Object {
[PSCustomObject]@{
Repo = $_
Version = $latestVersion
}
}
}
function Invoke-GitClone {
<#
Clona um repositΓ³rio e faz checkout na tag especificada.
Retorna: PSCustomObject com Status (cloned | skipped | error)
#>
param(
[string]$Repo,
[string]$Tag,
[string]$DestDir,
[string]$CloneBaseUrl,
[bool] $UseShallow
)
$result = [PSCustomObject]@{
Repo = $Repo
Tag = $Tag
Dest = $DestDir
Status = "pending"
Error = ""
}
# JΓ‘ clonado β pular
if (Test-Path (Join-Path $DestDir ".git")) {
$result.Status = "skipped"
return $result
}
$cloneUrl = "$CloneBaseUrl/$Repo"
New-Item -ItemType Directory -Path $DestDir -Force | Out-Null
# Usar & (call operator) + splatting β lida corretamente com paths com espaΓ§os
$gitArgs = [System.Collections.Generic.List[string]]@("clone", "--quiet")
if ($UseShallow) { $gitArgs.Add("--depth"); $gitArgs.Add("1") }
$gitArgs.Add("--branch"); $gitArgs.Add($Tag)
$gitArgs.Add($cloneUrl); $gitArgs.Add($DestDir)
$output = & git @gitArgs 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
$errMsg = ($output | Out-String).Trim() -replace "`n", " "
if ((Get-ChildItem $DestDir -Force -ErrorAction SilentlyContinue |
Measure-Object).Count -eq 0) {
Remove-Item $DestDir -Recurse -Force -ErrorAction SilentlyContinue
}
$result.Status = "error"
$result.Error = if ($errMsg) { $errMsg } else { "Exit code $exitCode" }
}
else {
$result.Status = "cloned"
}
return $result
}
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# InΓcio
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$banner = @"
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β OpenStack Repository Cloner β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β Release : $($Release.PadRight(33))β
β Destino : $($OutputDir.PadRight(33))β
β Modo clone : $($(if ($Shallow) { 'shallow (--depth 1 + --branch <tag>)' } else { 'completo (histΓ³rico inteiro) ' }).PadRight(33))β
β Servidor git : $($CloneServer.PadRight(33))β
β Paralelismo : $("$ThrottleLimit workers".PadRight(33))β
"@
if ($Filter) {
$banner += "`n β Filtro : $($Filter.PadRight(33))β"
}
$banner += "`n βββββββββββββββββββββββββββββββββββββββββββββββββββββ`n"
Write-Host $banner -ForegroundColor Cyan
# 1. Verificar dependΓͺncias
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Error "git nΓ£o encontrado no PATH. Instale o Git For Windows e tente novamente."
exit 1
}
# 2. Criar diretΓ³rio de saΓda
$resolvedOut = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputDir)
New-Item -ItemType Directory -Path $resolvedOut -Force | Out-Null
# 3. Listar deliverables via GitHub API
Write-Status "Buscando deliverables da release '$Release' via GitHub API..."
$yamlFiles = Get-DeliverableList -ReleaseName $Release -Token $GitHubToken
Write-Status "Encontrados $($yamlFiles.Count) arquivos de deliverable." "Green"
# 4. Baixar e parsear cada YAML (sequencial β sΓ£o chamadas rΓ‘pidas a raw.githubusercontent.com)
Write-Status "Analisando deliverables..."
$allItems = [System.Collections.Generic.List[PSCustomObject]]::new()
$parseErros = 0
$i = 0
foreach ($file in $yamlFiles) {
$i++
Write-Progress -Activity "Analisando deliverables ($i/$($yamlFiles.Count))" `
-Status $file.name `
-PercentComplete ([int](($i / $yamlFiles.Count) * 100))
$rawUrl = "$GITHUB_RAW/$Release/$($file.name)"
try {
$yaml = (Invoke-WebRequest -Uri $rawUrl -UseBasicParsing -TimeoutSec 30).Content
}
catch {
Write-Warning "Falha ao baixar $($file.name): $_"
$parseErros++
continue
}
$entries = ConvertFrom-DeliverableYaml -Yaml $yaml -Filename $file.name
foreach ($e in $entries) {
if ($Filter -and $e.Repo -notmatch $Filter) { continue }
$allItems.Add($e)
}
}
Write-Progress -Activity "Analisando deliverables" -Completed
# Eliminar duplicatas (mesmo repo em mΓΊltiplos deliverables β pouco comum mas acontece)
$allItems = [System.Collections.Generic.List[PSCustomObject]](
$allItems | Sort-Object Repo -Unique
)
Write-Status "RepositΓ³rios identificados: $($allItems.Count) (falhas de parsing: $parseErros)" "Green"
if ($allItems.Count -eq 0) {
Write-Warning "Nenhum repositΓ³rio encontrado. Verifique o release e o filtro."
exit 0
}
# 5. Clonar em paralelo
Write-Host ""
Write-Status "Iniciando clones (ThrottleLimit=$ThrottleLimit)..." "Yellow"
Write-Host ""
$cloneBase = $CLONE_SERVERS[$CloneServer]
$useShallow = $Shallow
$cloneResults = $allItems | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel {
# Capturar variΓ‘veis do escopo externo
$item = $_
$baseDir = $using:resolvedOut
$shallow = $using:useShallow
$cloneBase = $using:cloneBase
# ββ FunΓ§Γ΅es internas (ForEach-Object -Parallel nΓ£o herda funΓ§Γ΅es) ββββββ
function Clone-Repo {
param($Repo, $Tag, $DestDir, $CloneBaseUrl, $UseShallow)
$result = [PSCustomObject]@{
Repo = $Repo
Tag = $Tag
Dest = $DestDir
Status = "pending"
Error = ""
}
if (Test-Path (Join-Path $DestDir ".git")) {
$result.Status = "skipped"; return $result
}
$cloneUrl = "$CloneBaseUrl/$Repo"
New-Item -ItemType Directory -Path $DestDir -Force | Out-Null
$gitArgs = [System.Collections.Generic.List[string]]@("clone", "--quiet")
if ($UseShallow) { $gitArgs.Add("--depth"); $gitArgs.Add("1") }
$gitArgs.Add("--branch"); $gitArgs.Add($Tag)
$gitArgs.Add($cloneUrl); $gitArgs.Add($DestDir)
$output = & git @gitArgs 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
$errMsg = ($output | Out-String).Trim() -replace "`n", " "
if ((Get-ChildItem $DestDir -Force -ErrorAction SilentlyContinue | Measure-Object).Count -eq 0) {
Remove-Item $DestDir -Recurse -Force -ErrorAction SilentlyContinue
}
$result.Status = "error"
$result.Error = if ($errMsg) { $errMsg } else { "Exit $exitCode" }
}
else {
$result.Status = "cloned"
}
return $result
}
# ββ Calcular caminho de destino ββββββββββββββββββββββββββββββββββββββ
# Ex: openstack/nova β <OutputDir>\openstack\nova
$parts = $item.Repo -split '/', 2
$ns = $parts[0]
$repoName = if ($parts.Count -gt 1) { $parts[1] } else { $parts[0] }
$destDir = Join-Path $baseDir (Join-Path $ns $repoName)
$r = Clone-Repo -Repo $item.Repo -Tag $item.Version -DestDir $destDir `
-CloneBaseUrl $cloneBase -UseShallow $shallow
# Exibir linha de progresso (thread-safe com Write-Host)
$icon = switch ($r.Status) { "cloned" { "+" } "skipped" { "~" } "error" { "!" } default { "?" } }
$color = switch ($r.Status) { "cloned" { "Green" } "skipped" { "Yellow" } "error" { "Red" } default { "Gray" } }
Write-Host " [$icon] $($r.Repo) @$($r.Tag)" -ForegroundColor $color
if ($r.Status -eq "error") {
Write-Host " ERR: $($r.Error)" -ForegroundColor DarkRed
}
$r # retornar resultado para coleΓ§Γ£o
}
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# RelatΓ³rio final
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$cloned = @($cloneResults | Where-Object Status -eq "cloned")
$skipped = @($cloneResults | Where-Object Status -eq "skipped")
$errors = @($cloneResults | Where-Object Status -eq "error")
Write-Host ""
Write-Host " βββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Cyan
Write-Host " β Resumo Final β" -ForegroundColor Cyan
Write-Host " β ββββββββββββββββββββββββββββββββββββββββββββββββββββ£" -ForegroundColor Cyan
Write-Host " β Clonados : $("$($cloned.Count)".PadRight(37))β" -ForegroundColor Green
Write-Host " β Pulados : $("$($skipped.Count) (jΓ‘ existiam)".PadRight(37))β" -ForegroundColor Yellow
Write-Host " β Erros : $("$($errors.Count)".PadRight(37))β" -ForegroundColor $(if ($errors.Count -gt 0) { "Red" } else { "Green" })
Write-Host " βββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Cyan
if ($errors.Count -gt 0) {
Write-Host ""
Write-Host " RepositΓ³rios com falha:" -ForegroundColor Red
$errors | ForEach-Object {
Write-Host " $($_.Repo) @$($_.Tag)" -ForegroundColor DarkRed
Write-Host " $($_.Error)" -ForegroundColor DarkRed
}
Write-Host ""
Write-Host " Dica: execute o script novamente β repositΓ³rios jΓ‘ clonados serΓ£o pulados." -ForegroundColor Yellow
}
# Salvar relatΓ³rio CSV
$csvPath = Join-Path $resolvedOut "_summary.csv"
$cloneResults |
Select-Object Repo, Tag, Status, Dest, Error |
Export-Csv -Path $csvPath -NoTypeInformation -Encoding UTF8
Write-Host ""
Write-Status "RelatΓ³rio salvo : $csvPath" "Cyan"
Write-Status "RepositΓ³rios em : $resolvedOut" "Cyan"
Write-Host ""