Skip to content

Commit 54d895a

Browse files
committed
more separation of concerns
1 parent decedb2 commit 54d895a

9 files changed

Lines changed: 292 additions & 138 deletions

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"Bash(gh run view:*)",
66
"Bash(Select-String -Pattern \"WATCHDOG|ZWave|Controller|started|error\")",
77
"Bash(Select-Object -First 50)",
8-
"Bash(cat:*)"
8+
"Bash(cat:*)",
9+
"Bash(git log:*)"
910
],
1011
"deny": [],
1112
"ask": []

.github/workflows/run-zwave-wsl.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ jobs:
1515
- name: Checkout repository
1616
uses: actions/checkout@v4
1717

18-
- name: Setup Node.js
19-
uses: actions/setup-node@v4
20-
with:
21-
node-version: '24'
22-
23-
- name: Install dependencies
24-
run: npm ci
25-
18+
## Set up operating system
2619
- name: Setup WSL with Ubuntu
2720
uses: Vampire/setup-wsl@v6
2821
with:
@@ -35,20 +28,35 @@ jobs:
3528
sudo apt-get update
3629
sudo apt-get install -y libc6:i386 libstdc++6:i386
3730
31+
## Set up repo scripts etc.
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '24'
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
40+
## Set up CTT
41+
- name: Extract CTT setup files
42+
shell: powershell
43+
run: .\setup\unpack-ctt-archive.ps1
44+
45+
## Set up Z-Wave stack
3846
- name: Download Z-Wave stack binaries
47+
shell: powershell
3948
env:
4049
GH_TOKEN: ${{ secrets.ZW_STACK_TOKEN }}
41-
run: npm run setup
50+
run: .\setup\download-zwave-stack.ps1
4251

4352
- name: Make Z-Wave binaries executable
4453
shell: wsl-bash {0}
4554
run: chmod +x zwave_stack/bin/*.elf
4655

47-
- name: Extract CTT setup files
56+
## Restore network state for CTT project
57+
- name: Extract network state
4858
shell: powershell
49-
run: |
50-
Write-Host "Extracting CTT setup archive..."
51-
.\setup\extract-setup-archive.ps1
59+
run: .\setup\unpack-network-state-archive.ps1
5260

5361
- name: Copy Z-Wave storage to WSL native filesystem
5462
shell: wsl-bash {0}
@@ -75,6 +83,7 @@ jobs:
7583
echo "Storage symlinks created:"
7684
ls -la ./zwave_stack/storage/
7785
86+
## Do the testing stuff
7887
- name: Run CTT tests
7988
run: npm start -- --group=Automatic
8089
env:

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"start": "node --experimental-transform-types src/start.ts",
10-
"devices": "node --experimental-transform-types src/start.ts --devices-only",
11-
"create-setup-archive": "powershell -ExecutionPolicy Bypass -File setup/create-setup-archive.ps1",
12-
"setup": "powershell -ExecutionPolicy Bypass -File setup/download-zwave-stack.ps1"
10+
"devices": "node --experimental-transform-types src/start.ts --devices-only"
1311
},
1412
"keywords": [],
1513
"author": "",
Binary file not shown.

setup/network-state.zip

62.8 KB
Binary file not shown.

setup/pack-ctt-archive.ps1

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<#
2+
.SYNOPSIS
3+
Creates an archive containing CTT installation files for CI.
4+
5+
.DESCRIPTION
6+
This script packages the following into setup/ctt-setup.zip:
7+
- CTT AppData folder -> appdata/
8+
- CTT Keys file (homeId-specific) -> keys/
9+
- CTT binaries (from CTT_PATH or default location) -> ctt-bin/
10+
11+
.EXAMPLE
12+
.\pack-ctt-archive.ps1
13+
14+
.NOTES
15+
Set CTT_PATH environment variable to override the default CTT installation path.
16+
Default: C:\Program Files (x86)\Z-Wave Alliance\Z-Wave CTT 3
17+
#>
18+
19+
$ErrorActionPreference = "Stop"
20+
21+
$repoRoot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
22+
$tempDir = Join-Path $env:TEMP "ctt-archive-staging"
23+
$outputFile = Join-Path $repoRoot "setup\ctt-setup.zip"
24+
25+
# Helper function to parse JSON with comments (JSON5-style)
26+
function ConvertFrom-Json5 {
27+
param(
28+
[Parameter(ValueFromPipeline=$true)]
29+
[string]$Content
30+
)
31+
# Remove single-line comments (// ...)
32+
$Content = $Content -replace '(?m)^\s*//.*$', ''
33+
$Content = $Content -replace '//[^"]*$', ''
34+
# Remove multi-line comments (/* ... */)
35+
$Content = $Content -replace '/\*[\s\S]*?\*/', ''
36+
# Remove trailing commas before } or ]
37+
$Content = $Content -replace ',(\s*[}\]])', '$1'
38+
return $Content | ConvertFrom-Json
39+
}
40+
41+
# Load config.json for homeId (supports comments)
42+
$configPath = Join-Path $repoRoot "config.json"
43+
$config = Get-Content $configPath -Raw | ConvertFrom-Json5
44+
45+
# DUT configuration (for homeId-specific keys)
46+
$homeId = $config.dut.homeId
47+
$homeIdUpper = $homeId.ToUpper()
48+
49+
# Source paths
50+
$cttAppData = "C:\Users\$env:USERNAME\AppData\Roaming\Z-Wave Alliance\Z-Wave CTT 3"
51+
$cttKeys = "C:\Users\$env:USERNAME\Documents\Z-Wave Alliance\Z-Wave CTT 3\Keys"
52+
$cttPath = if ($env:CTT_PATH) { $env:CTT_PATH } else { "C:\Program Files (x86)\Z-Wave Alliance\Z-Wave CTT 3" }
53+
54+
Write-Host "Creating CTT setup archive..." -ForegroundColor Cyan
55+
56+
# Clean up any existing temp directory
57+
if (Test-Path $tempDir) {
58+
Remove-Item -Recurse -Force $tempDir
59+
}
60+
61+
# Create staging directory
62+
New-Item -ItemType Directory -Path $tempDir | Out-Null
63+
64+
# Copy CTT AppData
65+
if (Test-Path $cttAppData) {
66+
Write-Host " Copying CTT AppData..." -ForegroundColor Green
67+
Copy-Item -Recurse $cttAppData (Join-Path $tempDir "appdata")
68+
} else {
69+
Write-Host " WARNING: CTT AppData not found at $cttAppData" -ForegroundColor Yellow
70+
}
71+
72+
# Copy CTT Keys - only the homeId-specific key file
73+
$keysStagingDir = Join-Path $tempDir "keys"
74+
New-Item -ItemType Directory -Path $keysStagingDir | Out-Null
75+
76+
if (Test-Path $cttKeys) {
77+
$keyFile = Join-Path $cttKeys "$homeIdUpper.txt"
78+
if (Test-Path $keyFile) {
79+
Write-Host " Copying CTT Keys ($homeIdUpper.txt)..." -ForegroundColor Green
80+
Copy-Item $keyFile $keysStagingDir
81+
} else {
82+
Write-Host " WARNING: Key file not found at $keyFile" -ForegroundColor Yellow
83+
}
84+
} else {
85+
Write-Host " WARNING: CTT Keys directory not found at $cttKeys" -ForegroundColor Yellow
86+
}
87+
88+
# Copy CTT binaries
89+
if (Test-Path $cttPath) {
90+
Write-Host " Copying CTT binaries from $cttPath..." -ForegroundColor Green
91+
Copy-Item -Recurse $cttPath (Join-Path $tempDir "ctt-bin")
92+
} else {
93+
Write-Host " WARNING: CTT installation not found at $cttPath" -ForegroundColor Yellow
94+
}
95+
96+
# Remove old archive if it exists
97+
if (Test-Path $outputFile) {
98+
Remove-Item $outputFile
99+
}
100+
101+
# Create the zip archive using tar.exe (much faster than Compress-Archive)
102+
Write-Host " Compressing archive..." -ForegroundColor Green
103+
& "$env:SystemRoot\System32\tar.exe" -a -cf $outputFile -C $tempDir *
104+
105+
# Clean up temp directory
106+
Remove-Item -Recurse -Force $tempDir
107+
108+
Write-Host ""
109+
Write-Host "Created $outputFile" -ForegroundColor Green
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
<#
22
.SYNOPSIS
3-
Creates a setup archive containing all files needed for CTT tests on CI.
3+
Creates an archive containing Z-Wave network state for CI.
44
55
.DESCRIPTION
6-
This script packages the following into setup/setup.zip:
6+
This script packages the following into setup/network-state.zip:
77
- zwave_stack/storage/ -> storage/
88
- DUT storage files (from config.json glob patterns) -> dut-storage/
9-
- CTT AppData folder -> appdata/
10-
- CTT Keys file (homeId-specific) -> keys/
11-
- CTT binaries (from CTT_PATH or default location) -> ctt-bin/
129
1310
.EXAMPLE
14-
.\create-setup-archive.ps1
15-
16-
.NOTES
17-
Set CTT_PATH environment variable to override the default CTT installation path.
18-
Default: C:\Program Files (x86)\Z-Wave Alliance\Z-Wave CTT 3
11+
.\pack-network-state-archive.ps1
1912
#>
2013

2114
$ErrorActionPreference = "Stop"
2215

2316
$repoRoot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
24-
$tempDir = Join-Path $env:TEMP "ctt-setup-staging"
25-
$outputFile = Join-Path $repoRoot "setup\setup.zip"
17+
$tempDir = Join-Path $env:TEMP "network-state-staging"
18+
$outputFile = Join-Path $repoRoot "setup\network-state.zip"
2619

2720
# Helper function to parse JSON with comments (JSON5-style)
2821
function ConvertFrom-Json5 {
@@ -53,11 +46,8 @@ $dutStorageArchiveName = "dut-storage"
5346

5447
# Source paths
5548
$zwaveStorage = Join-Path $repoRoot "zwave_stack\storage"
56-
$cttAppData = "C:\Users\$env:USERNAME\AppData\Roaming\Z-Wave Alliance\Z-Wave CTT 3"
57-
$cttKeys = "C:\Users\$env:USERNAME\Documents\Z-Wave Alliance\Z-Wave CTT 3\Keys"
58-
$cttPath = if ($env:CTT_PATH) { $env:CTT_PATH } else { "C:\Program Files (x86)\Z-Wave Alliance\Z-Wave CTT 3" }
5949

60-
Write-Host "Creating setup archive..." -ForegroundColor Cyan
50+
Write-Host "Creating network state archive..." -ForegroundColor Cyan
6151

6252
# Clean up any existing temp directory
6353
if (Test-Path $tempDir) {
@@ -69,14 +59,18 @@ New-Item -ItemType Directory -Path $tempDir | Out-Null
6959

7060
# Copy zwave_stack/storage
7161
if (Test-Path $zwaveStorage) {
62+
Write-Host " Copying zwave_stack/storage..." -ForegroundColor Green
7263
Copy-Item -Recurse $zwaveStorage (Join-Path $tempDir "storage")
64+
} else {
65+
Write-Host " WARNING: zwave_stack/storage not found at $zwaveStorage" -ForegroundColor Yellow
7366
}
7467

7568
# Copy DUT storage files using glob patterns from config
7669
$dutStagingDir = Join-Path $tempDir $dutStorageArchiveName
7770
New-Item -ItemType Directory -Path $dutStagingDir | Out-Null
7871

7972
if (Test-Path $dutStorageDir) {
73+
Write-Host " Copying DUT storage files..." -ForegroundColor Green
8074
foreach ($pattern in $config.dut.storageFileFilter) {
8175
# Replace placeholders
8276
$resolvedPattern = $pattern -replace '%HOME_ID_LOWER%', $homeIdLower
@@ -86,30 +80,12 @@ if (Test-Path $dutStorageDir) {
8680
$matchedFiles = Get-Item -Path $fullPattern -ErrorAction SilentlyContinue
8781

8882
foreach ($file in $matchedFiles) {
83+
Write-Host " $($file.Name)" -ForegroundColor Gray
8984
Copy-Item $file.FullName $dutStagingDir
9085
}
9186
}
92-
}
93-
94-
# Copy CTT AppData
95-
if (Test-Path $cttAppData) {
96-
Copy-Item -Recurse $cttAppData (Join-Path $tempDir "appdata")
97-
}
98-
99-
# Copy CTT Keys - only the homeId-specific key file
100-
$keysStagingDir = Join-Path $tempDir "keys"
101-
New-Item -ItemType Directory -Path $keysStagingDir | Out-Null
102-
103-
if (Test-Path $cttKeys) {
104-
$keyFile = Join-Path $cttKeys "$homeIdUpper.txt"
105-
if (Test-Path $keyFile) {
106-
Copy-Item $keyFile $keysStagingDir
107-
}
108-
}
109-
110-
# Copy CTT binaries
111-
if (Test-Path $cttPath) {
112-
Copy-Item -Recurse $cttPath (Join-Path $tempDir "ctt-bin")
87+
} else {
88+
Write-Host " WARNING: DUT storage directory not found at $dutStorageDir" -ForegroundColor Yellow
11389
}
11490

11591
# Remove old archive if it exists
@@ -118,9 +94,11 @@ if (Test-Path $outputFile) {
11894
}
11995

12096
# Create the zip archive using tar.exe (much faster than Compress-Archive)
97+
Write-Host " Compressing archive..." -ForegroundColor Green
12198
& "$env:SystemRoot\System32\tar.exe" -a -cf $outputFile -C $tempDir *
12299

123100
# Clean up temp directory
124101
Remove-Item -Recurse -Force $tempDir
125102

103+
Write-Host ""
126104
Write-Host "Created $outputFile" -ForegroundColor Green

0 commit comments

Comments
 (0)