* Read and parse the GH_AW_SAMPLES env var. Returns an empty array (with a * warning) when unset or empty so the workflow can still complete cleanly. * @returns {SampleEntry[]}
()
| 55 | * @returns {SampleEntry[]} |
| 56 | */ |
| 57 | function loadSamples() { |
| 58 | const raw = process.env.GH_AW_SAMPLES; |
| 59 | if (!raw || !raw.trim()) { |
| 60 | core.warning("apply_samples: GH_AW_SAMPLES is empty — no samples to replay."); |
| 61 | return []; |
| 62 | } |
| 63 | let parsed; |
| 64 | try { |
| 65 | parsed = JSON.parse(raw); |
| 66 | } catch (err) { |
| 67 | throw new Error(`${ERR_PARSE}: apply_samples: failed to parse GH_AW_SAMPLES as JSON: ${getErrorMessage(err)}`); |
| 68 | } |
| 69 | // Tolerate a literal JSON `null` payload (older compiler emitted it for |
| 70 | // workflows with --use-samples but no `samples:` entries). Treat as empty. |
| 71 | if (parsed === null) { |
| 72 | core.warning("apply_samples: GH_AW_SAMPLES is null — treating as no samples to replay."); |
| 73 | return []; |
| 74 | } |
| 75 | if (!Array.isArray(parsed)) { |
| 76 | throw new Error(`${ERR_VALIDATION}: apply_samples: GH_AW_SAMPLES must be a JSON array`); |
| 77 | } |
| 78 | for (const [i, entry] of parsed.entries()) { |
| 79 | if (!entry || typeof entry !== "object" || typeof entry.tool !== "string") { |
| 80 | throw new Error(`${ERR_VALIDATION}: apply_samples: entry ${i} is missing a string "tool" field`); |
| 81 | } |
| 82 | if (!entry.arguments || typeof entry.arguments !== "object") { |
| 83 | throw new Error(`${ERR_VALIDATION}: apply_samples: entry ${i} (tool=${entry.tool}) is missing an "arguments" object`); |
| 84 | } |
| 85 | } |
| 86 | return parsed; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Run a git subcommand synchronously and return stdout. Throws on non-zero exit. |
no test coverage detected