-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.ps1
More file actions
128 lines (107 loc) · 5.73 KB
/
submit.ps1
File metadata and controls
128 lines (107 loc) · 5.73 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
# submit.ps1
$ErrorActionPreference = 'Continue'
try {
Write-Host "[0] Preflight SSH connectivity..." -ForegroundColor Cyan
$testResult = ssh -o ConnectTimeout=10 -o BatchMode=yes dev@runner "echo ping" 2>&1
if ($LASTEXITCODE -ne 0) {
throw "[0] SSH preflight failed (exit $LASTEXITCODE). Output: $testResult"
}
Write-Host "[0] SSH OK" -ForegroundColor Cyan
# 1. Generate job ID
Write-Host "[1] Generating job ID..." -ForegroundColor Cyan
$JID = (Get-Date -Format "yyyyMMddTHHmmss") + "-" + (Get-Random -Maximum 99999)
Write-Host "[1] JID = $JID" -ForegroundColor Cyan
# 2. Use cargo metadata to find exactly what we need
Write-Host "[2] Running cargo metadata..." -ForegroundColor Cyan
$metadataJson = cargo metadata --no-deps --format-version 1 2>&1
if ($LASTEXITCODE -ne 0) {
throw "[2] cargo metadata failed (exit $LASTEXITCODE). Output: $metadataJson"
}
$metadata = $metadataJson | ConvertFrom-Json
# Get the workspace root (where top-level Cargo.toml lives)
$workspaceRoot = $metadata.workspace_root
Write-Host "[2] Workspace root: $workspaceRoot" -ForegroundColor Cyan
# 3. Create remote dir - use same flat structure as tar version
$remoteDir = "/home/dev/inbox/$JID"
Write-Host "[3] Creating remote dir $remoteDir..." -ForegroundColor Cyan
ssh -o ConnectTimeout=10 -o BatchMode=yes dev@runner "mkdir -p $remoteDir" 2>&1 | ForEach-Object {
Write-Host " remote-mkdir: $_"
}
if ($LASTEXITCODE -ne 0) { throw "[3] remote mkdir failed (exit $LASTEXITCODE)" }
# 4. Upload workspace-level files
Write-Host "[4] Uploading workspace files..." -ForegroundColor Cyan
# Cargo.toml (workspace manifest)
$workspaceToml = Join-Path $workspaceRoot "Cargo.toml"
scp -o ConnectTimeout=10 -o BatchMode=yes $workspaceToml "dev@runner:$remoteDir/Cargo.toml" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[4] scp Cargo.toml failed (exit $LASTEXITCODE)" }
# Cargo.lock if exists
$lockFile = Join-Path $workspaceRoot "Cargo.lock"
if (Test-Path $lockFile) {
scp -o ConnectTimeout=10 -o BatchMode=yes $lockFile "dev@runner:$remoteDir/Cargo.lock" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[4] scp Cargo.lock failed (exit $LASTEXITCODE)" }
}
# .cargo config if exists
$cargoConfig = Join-Path $workspaceRoot ".cargo"
if (Test-Path $cargoConfig) {
scp -r -o ConnectTimeout=10 -o BatchMode=yes $cargoConfig "dev@runner:$remoteDir/" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[4] scp .cargo failed (exit $LASTEXITCODE)" }
}
Write-Host "[4] Workspace files uploaded" -ForegroundColor Cyan
# 5. Upload each package's necessary files
Write-Host "[5] Uploading package sources..." -ForegroundColor Cyan
foreach ($pkg in $metadata.packages) {
$pkgManifest = $pkg.manifest_path
$pkgDir = Split-Path $pkgManifest -Parent
# Calculate relative path from workspace root
$relPath = $pkgDir.Substring($workspaceRoot.Length).TrimStart('\', '/')
if ([string]::IsNullOrEmpty($relPath)) {
# Root package - files go directly into remote dir
$targetDir = $remoteDir
}
else {
# Nested package - preserve directory structure
$relPathUnix = $relPath -replace '\\', '/'
$targetDir = "$remoteDir/$relPathUnix"
# Create nested dir on remote
ssh -o ConnectTimeout=10 -o BatchMode=yes dev@runner "mkdir -p $targetDir" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[5] remote mkdir $targetDir failed (exit $LASTEXITCODE)" }
}
Write-Host " Uploading package: $($pkg.name)" -ForegroundColor Cyan
# Upload package Cargo.toml (only if not workspace root)
if (-not [string]::IsNullOrEmpty($relPath)) {
scp -o ConnectTimeout=10 -o BatchMode=yes $pkgManifest "dev@runner:$targetDir/Cargo.toml" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[5] scp package Cargo.toml failed (exit $LASTEXITCODE)" }
}
# Upload src/ if exists
$srcDir = Join-Path $pkgDir "src"
if (Test-Path $srcDir) {
scp -r -o ConnectTimeout=10 -o BatchMode=yes $srcDir "dev@runner:$targetDir/" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[5] scp src failed (exit $LASTEXITCODE)" }
}
# Upload build.rs if exists
$buildRs = Join-Path $pkgDir "build.rs"
if (Test-Path $buildRs) {
scp -o ConnectTimeout=10 -o BatchMode=yes $buildRs "dev@runner:$targetDir/build.rs" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "[5] scp build.rs failed (exit $LASTEXITCODE)" }
}
}
Write-Host "[5] All sources uploaded" -ForegroundColor Cyan
# 6. Start systemd service
Write-Host "[6] Starting rcq@$JID.service..." -ForegroundColor Cyan
$remoteCmd = "bash -lc 'set -Eeuo pipefail; echo START; sudo -n systemctl start --no-block rcq@$JID.service; echo SYSTEMCTL_OK'"
ssh -o ConnectTimeout=10 -o BatchMode=yes dev@runner $remoteCmd 2>&1 | ForEach-Object {
Write-Host " remote: $_"
}
if ($LASTEXITCODE -ne 0) { throw "[6] systemctl failed (exit $LASTEXITCODE)" }
Write-Host "[6] Service started" -ForegroundColor Cyan
Write-Host "Submitted JID: $JID" -ForegroundColor Green
exit 0
}
catch {
Write-Host "ERROR: $_" -ForegroundColor Red
Write-Host "Common causes:" -ForegroundColor Yellow
Write-Host " - SSH/Tailscale auth failed (BatchMode=yes disables prompts)" -ForegroundColor Yellow
Write-Host " - cargo not in PATH or project not valid Cargo workspace" -ForegroundColor Yellow
Write-Host " - sudo on runner not configured for passwordless systemctl" -ForegroundColor Yellow
exit 1
}