Skip to content

Commit b6ea623

Browse files
authored
Add gmatpy smoke check via stock GMAT sample (#23)
- New src/smoke.ts exporting smoke(gmatRoot, pythonVersion?). Resolves python via @actions/io's which('python', true) — a missing binary throws a typed error pointing at actions/setup-python@v5. - Runs python -c "..." that bootstraps gmatpy from ${gmatRoot}/bin, calls gmat.Setup against api_startup_file.txt, loads samples/Ex_HighFidelitySRP.script, and asserts gmat.RunScript returns 1 (GMAT's success code). - @actions/exec.exec streams stdout/stderr live to the workflow log and throws on non-zero exit. Failures are wrapped with the sample path and GMAT_ROOT for the action's failure summary. - Sample choice: Ex_HighFidelitySRP.script — smallest stock sample with Propagate, no Subscribers, header reports Released: R2014a so it ships in every supported version. - Not yet wired into install.ts. Closes #8
1 parent 10c199e commit b6ea623

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

src/smoke.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as path from 'node:path';
2+
import * as core from '@actions/core';
3+
import * as exec from '@actions/exec';
4+
import * as io from '@actions/io';
5+
6+
const SMOKE_SAMPLE = path.posix.join('samples', 'Ex_HighFidelitySRP.script');
7+
8+
const SMOKE_PYTHON_SRC = `
9+
import os, sys
10+
gmat_root = os.environ['GMAT_ROOT']
11+
sys.path.insert(0, os.path.join(gmat_root, 'bin'))
12+
import gmatpy as gmat
13+
gmat.Setup(os.path.join(gmat_root, 'bin', 'api_startup_file.txt'))
14+
script = os.path.join(gmat_root, ${JSON.stringify(SMOKE_SAMPLE)})
15+
if not gmat.LoadScript(script):
16+
sys.exit(f'gmat.LoadScript failed for {script}')
17+
rc = gmat.RunScript()
18+
if rc != 1:
19+
sys.exit(f'gmat.RunScript returned {rc} for {script} (expected 1)')
20+
print('setup-gmat smoke ok')
21+
`;
22+
23+
export async function smoke(gmatRoot: string, pythonVersion?: string): Promise<void> {
24+
const pythonPath = await resolvePython();
25+
const sample = path.join(gmatRoot, SMOKE_SAMPLE);
26+
if (pythonVersion !== undefined) {
27+
core.info(
28+
`Smoke-testing GMAT install at ${gmatRoot} with ${pythonPath} (requested python-version=${pythonVersion})`,
29+
);
30+
} else {
31+
core.info(`Smoke-testing GMAT install at ${gmatRoot} with ${pythonPath}`);
32+
}
33+
try {
34+
await exec.exec(pythonPath, ['-c', SMOKE_PYTHON_SRC], {
35+
cwd: gmatRoot,
36+
env: { ...process.env, GMAT_ROOT: gmatRoot } as { [key: string]: string },
37+
});
38+
} catch (err) {
39+
const reason = err instanceof Error ? err.message : String(err);
40+
throw new Error(
41+
`Smoke check failed: ${reason}. ` +
42+
`Sample: ${sample}. GMAT_ROOT: ${gmatRoot}. ` +
43+
`See the workflow log above for gmatpy's stderr.`,
44+
);
45+
}
46+
}
47+
48+
async function resolvePython(): Promise<string> {
49+
try {
50+
return await io.which('python', true);
51+
} catch (err) {
52+
const reason = err instanceof Error ? err.message : String(err);
53+
throw new Error(
54+
`python is not on PATH (${reason}). ` +
55+
`Add a 'uses: actions/setup-python@v5' step before setup-gmat.`,
56+
);
57+
}
58+
}

0 commit comments

Comments
 (0)