|
| 1 | +import pathUtil from 'node:path'; |
| 2 | +import ts from 'typescript'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @fileoverview |
| 6 | + * tsc command output will be parsed by GitHub Actions as errors. |
| 7 | + * We want them to be just warnings. |
| 8 | + */ |
| 9 | + |
| 10 | +const check = () => { |
| 11 | + const rootDir = pathUtil.join(import.meta.dirname, '..'); |
| 12 | + |
| 13 | + const tsconfigPath = pathUtil.join(rootDir, 'tsconfig.json'); |
| 14 | + const commandLine = ts.getParsedCommandLineOfConfigFile(tsconfigPath, {}, ts.sys); |
| 15 | + |
| 16 | + const program = ts.createProgram({ |
| 17 | + rootNames: commandLine.fileNames, |
| 18 | + options: commandLine.options |
| 19 | + }); |
| 20 | + const emitted = program.emit(); |
| 21 | + |
| 22 | + const diagnostics = [ |
| 23 | + ...ts.getPreEmitDiagnostics(program), |
| 24 | + ...emitted.diagnostics |
| 25 | + ]; |
| 26 | + |
| 27 | + for (const diagnostic of diagnostics) { |
| 28 | + // https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands |
| 29 | + let output = ''; |
| 30 | + const relativeFileName = pathUtil.relative(rootDir, diagnostic.file.fileName); |
| 31 | + output += `::warning file=${relativeFileName}`; |
| 32 | + |
| 33 | + const startPosition = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); |
| 34 | + output += `,line=${startPosition.line + 1},col=${startPosition.character + 1}`; |
| 35 | + |
| 36 | + const endPosition = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); |
| 37 | + output += `,endLine=${endPosition.line + 1},endCol=${endPosition.character + 1}`; |
| 38 | + |
| 39 | + output += ",title=Type warning - may indicate a bug. No action required if no bug."; |
| 40 | + output += `::${diagnostic.messageText}`; |
| 41 | + |
| 42 | + console.log(output); |
| 43 | + } |
| 44 | + |
| 45 | + console.log(`${diagnostics.length} warnings.`); |
| 46 | +}; |
| 47 | + |
| 48 | +check(); |
0 commit comments