(text)
| 66 | } |
| 67 | |
| 68 | function parseSteps(text) { |
| 69 | const lines = text.split(/\r?\n/); |
| 70 | const start = lines.findIndex((line) => /^ steps:\s*$/.test(line)); |
| 71 | assert.ok(start >= 0, "action.yml must define composite steps"); |
| 72 | const steps = []; |
| 73 | let current; |
| 74 | |
| 75 | function finish() { |
| 76 | if (!current) return; |
| 77 | const rawLines = current.lines; |
| 78 | const runDeclarations = rawLines |
| 79 | .map((line, index) => (/^\s*run:\s*/.test(line) ? { line, index } : undefined)) |
| 80 | .filter(Boolean); |
| 81 | assert.ok(runDeclarations.length <= 1, `step ${current.name} must not define multiple run blocks`); |
| 82 | let run; |
| 83 | if (runDeclarations.length === 1) { |
| 84 | const { line, index: runMarker } = runDeclarations[0]; |
| 85 | assert.match(line, /^ run:\s*\|\s*$/, `step ${current.name} uses an unsupported run scalar`); |
| 86 | const body = []; |
| 87 | for (let index = runMarker + 1; index < rawLines.length; index += 1) { |
| 88 | const line = rawLines[index]; |
| 89 | if (line.trim() === "") { |
| 90 | body.push(""); |
| 91 | } else if (/^ /.test(line)) { |
| 92 | body.push(line.slice(8)); |
| 93 | } else { |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | run = body.join("\n"); |
| 98 | } |
| 99 | |
| 100 | const env = {}; |
| 101 | const envDeclarations = rawLines |
| 102 | .map((line, index) => (/^\s*env:\s*$/.test(line) ? { line, index } : undefined)) |
| 103 | .filter(Boolean); |
| 104 | assert.ok(envDeclarations.length <= 1, `step ${current.name} must not define multiple env blocks`); |
| 105 | const envMarker = envDeclarations.length === 1 ? envDeclarations[0].index : -1; |
| 106 | if (envMarker >= 0) { |
| 107 | assert.match( |
| 108 | envDeclarations[0].line, |
| 109 | /^ env:\s*$/, |
| 110 | `step ${current.name} uses unsupported env indentation` |
| 111 | ); |
| 112 | for (let index = envMarker + 1; index < rawLines.length; index += 1) { |
| 113 | const line = rawLines[index]; |
| 114 | if (line.trim() === "") continue; |
| 115 | // A `#` comment is legal YAML inside a mapping block, and the env |
| 116 | // blocks use them to record why a value is wired the way it is. |
| 117 | if (/^\s*#/.test(line)) continue; |
| 118 | if (/^ [A-Za-z_][A-Za-z0-9_-]*:\s*/.test(line)) break; |
| 119 | const match = /^ ([A-Za-z_][A-Za-z0-9_]*):\s*(.*)$/.exec(line); |
| 120 | assert.ok(match, `step ${current.name} contains an unsupported env value or indentation`); |
| 121 | assert.doesNotMatch( |
| 122 | match[2], |
| 123 | /^(?:\||>|\|-|>-|\|\+|>\+)$/, |
| 124 | `step ${current.name} contains an unsupported multiline env value` |
| 125 | ); |
no test coverage detected