Repository navigation
194 lines (178 loc) · 9.33 KB
/
Copy pathci.yml
File metadata and controls
194 lines (178 loc) · 9.33 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
name: CI
on:
push:
branches: [ main, improve-and-package ]
pull_request:
branches: [ main ]
jobs:
test:
name: Pester (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@v7
- name: Validate POSIX runner contract
if: runner.os != 'Windows'
shell: bash
run: ./tests/test-runner-contract.sh
- name: Validate module manifest
shell: pwsh
run: Test-ModuleManifest ./NetDiagram-PS/NetDiagram-PS.psd1
- name: Install Pester
shell: pwsh
run: Install-Module -Name Pester -MinimumVersion 5.0.0 -Force -Scope CurrentUser -SkipPublisherCheck
- name: Record PowerShell version
shell: pwsh
run: $PSVersionTable | Format-Table -AutoSize; $PSVersionTable.PSVersion.ToString()
- name: Run Pester tests
shell: pwsh
run: ./tests/run-tests.ps1
smoke:
name: Packaged smoke (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@v7
- name: Record PowerShell version
shell: pwsh
run: $PSVersionTable | Format-Table -AutoSize
- name: Stage candidate package in isolation
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$manifest = Join-Path $PWD 'NetDiagram-PS' 'NetDiagram-PS.psd1'
Test-ModuleManifest $manifest | Out-String | Write-Host
$stage = Join-Path ([System.IO.Path]::GetTempPath()) ("NetDiagram-PS-smoke-" + [Guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $stage -Force | Out-Null
Copy-Item -Recurse -Force (Join-Path $PWD 'NetDiagram-PS') (Join-Path $stage 'NetDiagram-PS')
# keep staged path for next steps
"STAGE=$stage" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
Write-Host "Staged to $stage"
Get-ChildItem $stage -Recurse | Format-Table -AutoSize | Out-String | Write-Host
- name: Install and import from staged path
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$stageModule = Join-Path $env:STAGE 'NetDiagram-PS' 'NetDiagram-PS.psd1'
Test-ModuleManifest $stageModule | Out-String | Write-Host
Import-Module $stageModule -Force
$cmds = Get-Command -Module NetDiagram-PS | Select-Object -ExpandProperty Name | Sort-Object
Write-Host "Exported commands: $($cmds -join ', ')"
$manifestData = Import-PowerShellDataFile $stageModule
$expected = @($manifestData.FunctionsToExport)
if ($expected.Count -eq 0) { throw 'Manifest FunctionsToExport is empty or missing' }
foreach ($e in $expected) { if ($cmds -notcontains $e) { throw "Missing exported command: $e" } }
Write-Host "All $($expected.Count) FunctionsToExport commands present."
- name: Offline inventory-to-diagram smoke (no network)
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$stageModule = Join-Path $env:STAGE 'NetDiagram-PS' 'NetDiagram-PS.psd1'
Import-Module $stageModule -Force
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("psnetmap-smoke-" + [Guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $tmp -Force | Out-Null
try {
$inv = @{
knownDevices = @(
@{ ip='10.0.0.1'; hostname='gw'; role='core-router'; vendor='Cisco' }
@{ ip='10.0.0.10'; hostname='sw1'; role='switch'; vendor='Cisco' }
)
subnets = @(@{ cidr='10.0.0.0/24'; label='SmokeNet'; vlan=1 })
}
$invPath = Join-Path $tmp 'inventory.json'
$inv | ConvertTo-Json -Depth 10 | Out-File -FilePath $invPath -Encoding utf8
$topo = Import-Inventory -Path $invPath
if ($topo.Nodes.Count -ne 2) { throw "Expected 2 nodes, got $($topo.Nodes.Count)" }
$drawio = Join-Path $tmp 'smoke.drawio'
$topo | Export-DrawIO -OutFile $drawio
if (-not (Test-Path $drawio)) { throw "Export-DrawIO did not create file" }
$xml = Get-Content $drawio -Raw
if ($xml -notmatch '10\.0\.0\.1' -or $xml -notmatch '10\.0\.0\.10') { throw "Export-DrawIO missing expected IPs" }
Write-Host "Export-DrawIO OK: $drawio ($((Get-Item $drawio).Length) bytes)"
$meta = Join-Path $tmp 'smoke-meta.json'
$topo | Export-Metadata -OutFile $meta -CredSetsUsed @('SmokeCred')
if (-not (Test-Path $meta)) { throw "Export-Metadata did not create file" }
$baselineMeta = $meta
$baselineTopo = Join-Path $tmp 'smoke-topo.json'
$topo | ConvertTo-Json -Depth 10 | Out-File -FilePath $baselineTopo -Encoding utf8
# second scan with one extra node
$inv2 = @{
knownDevices = @(
@{ ip='10.0.0.1'; hostname='gw'; role='core-router'; vendor='Cisco' }
@{ ip='10.0.0.10'; hostname='sw1'; role='switch'; vendor='Cisco' }
@{ ip='10.0.0.11'; hostname='srv1'; role='server'; vendor='Dell' }
)
subnets = @(@{ cidr='10.0.0.0/24'; label='SmokeNet'; vlan=1 })
}
$inv2Path = Join-Path $tmp 'inventory2.json'
$inv2 | ConvertTo-Json -Depth 10 | Out-File -FilePath $inv2Path -Encoding utf8
$topo2 = Import-Inventory -Path $inv2Path
$currMeta = Join-Path $tmp 'smoke-meta2.json'
$currTopo = Join-Path $tmp 'smoke-topo2.json'
$topo2 | Export-Metadata -OutFile $currMeta -CredSetsUsed @('SmokeCred')
$topo2 | ConvertTo-Json -Depth 10 | Out-File -FilePath $currTopo -Encoding utf8
$diff = Compare-NetworkScans -BaselineMetadata $baselineMeta -BaselineTopology $baselineTopo -CurrentMetadata $currMeta -CurrentTopology $currTopo
Write-Host "Compare-NetworkScans OK: $($diff | ConvertTo-Json -Depth 5)"
# Dual-stack DrawIO via Import-Inventory (v4 + v6 node/subnet; no hand-built topology).
$dualInv = @{
knownDevices = @(
@{ ip='10.0.0.1'; hostname='gw'; role='core-router'; vendor='Cisco' }
@{ ip='2001:db8::10'; hostname='v6-node'; role='switch'; vendor='Cisco' }
)
subnets = @(
@{ cidr='10.0.0.0/24'; label='SmokeNet'; vlan=1 }
@{ cidr='2001:db8::/32'; label='SmokeV6'; vlan=100 }
)
}
$dualPath = Join-Path $tmp 'inventory-dual.json'
$dualInv | ConvertTo-Json -Depth 10 | Out-File -FilePath $dualPath -Encoding utf8
$dualTopo = Import-Inventory -Path $dualPath
$dualIps = @($dualTopo.Nodes.IP)
if ($dualIps -notcontains '10.0.0.1' -or $dualIps -notcontains '2001:db8::10') {
throw "Import-Inventory missing dual-stack node IPs: $($dualIps -join ', ')"
}
$dualDrawio = Join-Path $tmp 'smoke-dual.drawio'
$dualTopo | Export-DrawIO -OutFile $dualDrawio
if (-not (Test-Path $dualDrawio)) { throw 'Export-DrawIO did not create dual-stack file' }
$dualXmlRaw = Get-Content $dualDrawio -Raw
if ($dualXmlRaw -notmatch [regex]::Escape('10.0.0.1')) { throw 'Export-DrawIO missing IPv4 address' }
if ($dualXmlRaw -notmatch [regex]::Escape('2001:db8::10')) { throw 'Export-DrawIO missing IPv6 address' }
$dualXml = [xml]$dualXmlRaw
$v4node = $dualXml.SelectSingleNode("//UserObject[@ip='10.0.0.1']")
$v6node = $dualXml.SelectSingleNode("//UserObject[@ip='2001:db8::10']")
if ($null -eq $v4node) { throw 'Export-DrawIO missing UserObject for IPv4 node' }
if ($null -eq $v6node) { throw 'Export-DrawIO missing UserObject for IPv6 node' }
$v6parent = $v6node.mxCell.parent
if ([string]::IsNullOrWhiteSpace($v6parent) -or $v6parent -eq '1') {
throw "IPv6 node was not parented into a subnet container (parent='$v6parent')"
}
Write-Host "Export-DrawIO dual-stack Import-Inventory OK: $dualDrawio (v6 parent=$v6parent)"
# record candidate evidence
$manifest = Import-PowerShellDataFile $stageModule
Write-Host "Candidate commit: $env:GITHUB_SHA"
Write-Host "Package version: $($manifest.ModuleVersion)"
Write-Host "Package hash (staged folder): $((Get-FileHash $stageModule -Algorithm SHA256).Hash)"
} finally {
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force $env:STAGE -ErrorAction SilentlyContinue
}
lint:
name: PSScriptAnalyzer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install PSScriptAnalyzer
shell: pwsh
run: Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
- name: Run analyzer (fail on errors)
shell: pwsh
run: |
$results = Invoke-ScriptAnalyzer -Path ./NetDiagram-PS -Recurse -Severity Error
$results | Format-Table -AutoSize
if ($results) { throw "PSScriptAnalyzer reported $($results.Count) error(s)" }