Repository navigation
debug: upload probe output before the tmate door; cap tmate at 6 min #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Debug MATLAB batch licensing | |
| # Scratch workflow, branch debug/matlab-batch-ssh only. Reproduces the CI MATLAB | |
| # path, probes whether a shared engine licensed by matlab-batch is reachable from | |
| # Python, then opens a tmate SSH session restricted to the dispatching user's keys. | |
| on: | |
| push: | |
| branches: [debug/matlab-batch-ssh] | |
| workflow_dispatch: | |
| inputs: | |
| ssh: | |
| description: "Open a tmate SSH door at the end" | |
| type: boolean | |
| default: true | |
| ssh_minutes: | |
| description: "Minutes to keep the SSH door open" | |
| type: number | |
| default: 45 | |
| env: | |
| MLM_LICENSE_TOKEN: ${{ secrets.MATLAB_BATCH_TOKEN }} | |
| jobs: | |
| debug: | |
| name: Probe matlab-batch + engine | |
| runs-on: ubuntu-22.04 | |
| timeout-minutes: 120 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "uv.lock" | |
| - name: Install Python 3.12 and dependencies | |
| run: | | |
| uv python install 3.12 | |
| uv sync --python 3.12 --all-extras --group dev | |
| - name: Set up MATLAB | |
| uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: R2024b | |
| products: MATLAB | |
| - name: Locate MATLAB root and install the Python engine | |
| shell: bash | |
| run: | | |
| MATLAB_ROOT=$(ls -d "$RUNNER_TOOL_CACHE"/MATLAB/*/x64 | tail -n1) | |
| echo "MATLAB_ROOT=$MATLAB_ROOT" >> "$GITHUB_ENV" | |
| echo "$MATLAB_ROOT/bin" >> "$GITHUB_PATH" | |
| uv pip install "$MATLAB_ROOT/extern/engines/python" | |
| echo "token set: $([[ -n "$MLM_LICENSE_TOKEN" ]] && echo yes || echo NO)" | |
| echo "token length: ${#MLM_LICENSE_TOKEN}" | |
| which matlab matlab-batch || true | |
| matlab-batch -version || true | |
| - name: "Probe 1: matlab-batch alone (expected to work)" | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: "disp(version); disp(license)" | |
| - name: "Probe 2: plain matlab launcher with the batch token (expected to fail, current CI path)" | |
| shell: bash | |
| continue-on-error: true | |
| run: | | |
| mkdir -p /tmp/debug-out | |
| (timeout 300 matlab -batch "disp(version)" || echo "plain matlab exit=$?") 2>&1 | tee /tmp/debug-out/probe2_plain_matlab.log | |
| - name: "Probe 3: matlab.engine.start_matlab() (expected to fail, current CI path)" | |
| shell: bash | |
| continue-on-error: true | |
| run: | | |
| (timeout 300 uv run --no-sync python - <<'PY' || echo "start_matlab exit=$?") 2>&1 | tee /tmp/debug-out/probe3_start_matlab.log | |
| import matlab.engine | |
| eng = matlab.engine.start_matlab() | |
| print(eng.version()) | |
| eng.quit() | |
| PY | |
| - name: "Probe 4: shared engine from a matlab-batch session, Python connects" | |
| uses: matlab-actions/run-command@v2 | |
| continue-on-error: true | |
| env: | |
| EEGPREP_MATLAB_SESSION: eegprep_ci | |
| with: | |
| command: | | |
| rm -f /tmp/probe.done /tmp/probe.log | |
| diary('/tmp/debug-out/probe4_matlab_diary.log'); diary on; | |
| matlab.engine.shareEngine('eegprep_ci'); | |
| fprintf('shared as %s, isEngineShared=%d\n', matlab.engine.engineName, matlab.engine.isEngineShared); | |
| [s, out] = system('nohup uv run --no-sync python .github/debug/connect_probe.py > /tmp/probe.log 2>&1 &'); | |
| if s ~= 0, error('could not launch probe: %s', out); end | |
| t0 = tic; | |
| while ~isfile('/tmp/probe.done') && toc(t0) < 600 | |
| pause(1); % pause() services incoming engine requests | |
| end | |
| fprintf('waited %.0fs\n', toc(t0)); | |
| type('/tmp/probe.log'); | |
| copyfile('/tmp/probe.log', '/tmp/debug-out/probe4_python.log'); | |
| if ~contains(fileread('/tmp/probe.log'), 'PROBE_OK') | |
| error('Python could not use the shared matlab-batch session'); | |
| end | |
| - name: Upload probe output | |
| if: ${{ always() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: probe-out | |
| path: /tmp/debug-out | |
| if-no-files-found: warn | |
| - name: Open SSH door (tmate, actor keys only, detached) | |
| if: ${{ always() && (github.event_name == 'push' || inputs.ssh) }} | |
| uses: mxschmitt/action-tmate@v3 | |
| timeout-minutes: 6 | |
| continue-on-error: true | |
| with: | |
| limit-access-to-actor: true | |
| detached: true | |
| - name: Record SSH address and probe results | |
| if: ${{ always() }} | |
| shell: bash | |
| run: | | |
| mkdir -p /tmp/debug-out | |
| for i in $(seq 1 30); do | |
| if tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}' > /tmp/debug-out/tmate_ssh.txt 2>/dev/null && [[ -s /tmp/debug-out/tmate_ssh.txt ]]; then break; fi | |
| sleep 2 | |
| done | |
| cat /tmp/debug-out/tmate_ssh.txt || echo "no tmate address" | |
| ls -la /tmp/debug-out | |
| - name: Upload SSH address | |
| if: ${{ always() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ssh-out | |
| path: /tmp/debug-out/tmate_ssh.txt | |
| if-no-files-found: warn | |
| - name: Keep the door open (touch /continue to end) | |
| if: ${{ always() && (github.event_name == 'push' || inputs.ssh) }} | |
| shell: bash | |
| run: | | |
| end=$((SECONDS + 60*60)) | |
| while [[ ! -f /continue && ! -f "$GITHUB_WORKSPACE/continue" && $SECONDS -lt $end ]]; do sleep 10; done | |
| echo "door closed" |