Skip to content

Commit d413669

Browse files
codedproclaude
andcommitted
ci: make MT5 install robust (wait for Trade.mqh; guarded terminal fallback)
The installer writes files in stages, so waiting only for MetaEditor64.exe raced ahead of terminal64.exe and the "unpack" step crashed with file-not- found. Merge install+unpack into one step that waits for the header the compile actually needs (Include\Trade\Trade.mqh), and only launches the terminal as a guarded fallback if the installer didn't lay it down. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f082a56 commit d413669

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

‎.github/workflows/compile-ea.yml‎

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,46 @@ jobs:
2929
Invoke-WebRequest -Uri $url -OutFile "$env:RUNNER_TEMP\mt5setup.exe"
3030
Write-Host "Downloaded installer ($((Get-Item "$env:RUNNER_TEMP\mt5setup.exe").Length) bytes)"
3131
32-
- name: Install MetaTrader 5 (silent)
32+
- name: Install MetaTrader 5 + standard library
3333
shell: pwsh
3434
run: |
35+
$ErrorActionPreference = "Stop"
36+
$mt5 = "C:\Program Files\MetaTrader 5"
37+
$me = "$mt5\MetaEditor64.exe"
38+
$inc = "$mt5\MQL5\Include\Trade\Trade.mqh"
39+
40+
function Wait-ForPath($p, $minutes) {
41+
$deadline = (Get-Date).AddMinutes($minutes)
42+
while (-not (Test-Path -LiteralPath $p) -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 }
43+
return (Test-Path -LiteralPath $p)
44+
}
45+
3546
Start-Process -FilePath "$env:RUNNER_TEMP\mt5setup.exe" -ArgumentList "/auto" | Out-Null
36-
$me = "C:\Program Files\MetaTrader 5\MetaEditor64.exe"
37-
$deadline = (Get-Date).AddMinutes(8)
38-
while (-not (Test-Path $me) -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 }
39-
if (-not (Test-Path $me)) { throw "MetaEditor not found - install did not complete" }
40-
Write-Host "Installed: $me"
4147
42-
- name: Unpack MQL5 standard library
43-
shell: pwsh
44-
run: |
45-
$mt5 = "C:\Program Files\MetaTrader 5"
46-
# Launch the terminal once (portable) so the standard library
47-
# (Include\Trade\Trade.mqh, etc.) is unpacked next to the binary.
48-
$proc = Start-Process -FilePath "$mt5\terminal64.exe" -ArgumentList "/portable" -PassThru
49-
$inc = "$mt5\MQL5\Include\Trade\Trade.mqh"
50-
$deadline = (Get-Date).AddMinutes(3)
51-
while (-not (Test-Path $inc) -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 }
52-
try { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } catch {}
53-
if (-not (Test-Path $inc)) { throw "MQL5 standard library was not unpacked" }
48+
# Wait for the compiler itself.
49+
if (-not (Wait-ForPath $me 8)) { throw "MetaEditor not found - install did not complete" }
50+
Write-Host "MetaEditor installed: $me"
51+
52+
# The installer normally lays down the MQL5 standard library too, but it
53+
# writes files in stages - wait for the header the compile actually needs.
54+
if (-not (Wait-ForPath $inc 4)) {
55+
# Fallback: unpack it by launching the terminal once (guard on the exe
56+
# existing first, so we never race on a not-yet-written terminal64.exe).
57+
$term = "$mt5\terminal64.exe"
58+
if (Wait-ForPath $term 4) {
59+
Write-Host "Standard library missing; launching terminal to unpack it..."
60+
$p = Start-Process -FilePath $term -ArgumentList "/portable" -WorkingDirectory $mt5 -PassThru
61+
Wait-ForPath $inc 3 | Out-Null
62+
try { Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue } catch {}
63+
}
64+
}
65+
66+
if (-not (Test-Path -LiteralPath $inc)) { throw "MQL5 standard library not found at $inc" }
5467
Write-Host "Standard library ready: $inc"
5568
69+
# Ensure no terminal process is holding files open before we compile.
70+
Get-Process terminal64 -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
71+
5672
- name: Compile
5773
shell: pwsh
5874
run: |

0 commit comments

Comments
 (0)