Skip to content

Commit 3aabe37

Browse files
committed
Allow to debug all errors, set exit code 0 on tsc errors
1 parent 0c389df commit 3aabe37

File tree

9 files changed

+165
-47
lines changed

9 files changed

+165
-47
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ jobs:
3333
files-added: ${{steps.files.outputs.files_created}}
3434
files-deleted: ${{steps.files.outputs.files_deleted}}
3535
line-numbers: ${{steps.diff.outputs.lineNumbers}}
36+
debug: true

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ inputs:
2828
check-fail-mode:
2929
description: "Allowed values : added, errors_in_pr, errors_in_code"
3030
required: true
31+
debug:
32+
description: "Set true to log ts errors in base branch and pr branc"
33+
default: false
3134
runs:
3235
using: 'node12'
3336
main: 'dist/index.js'

dist/index.js

Lines changed: 122 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ const core_1 = __nccwpck_require__(2186);
168168
function getAndValidateArgs() {
169169
var _a, _b, _c, _d;
170170
const args = {
171-
repoToken: core_1.getInput('repo-token', { required: true }),
172-
directory: core_1.getInput('directory'),
173-
tsConfigPath: core_1.getInput('ts-config-path'),
171+
repoToken: core_1.getInput('repo-token', { required: true, trimWhitespace: true }),
172+
directory: core_1.getInput('directory', { trimWhitespace: true }),
173+
tsConfigPath: core_1.getInput('ts-config-path', { trimWhitespace: true, required: true }),
174174
filesChanged: ((_a = core_1.getInput('files-changed')) !== null && _a !== void 0 ? _a : "").split(" "),
175175
filesAdded: ((_b = core_1.getInput('files-added')) !== null && _b !== void 0 ? _b : "").split(" "),
176176
filesDeleted: ((_c = core_1.getInput('files-deleted')) !== null && _c !== void 0 ? _c : "").split(" "),
177177
lineNumbers: (_d = JSON.parse(core_1.getInput('line-numbers'))) !== null && _d !== void 0 ? _d : [],
178-
useCheck: core_1.getInput('use-check').trim() === 'true' ? true : false,
179-
checkFailMode: core_1.getInput('check-fail-mode')
178+
useCheck: core_1.getBooleanInput('use-check'),
179+
checkFailMode: core_1.getInput('check-fail-mode'),
180+
debug: core_1.getBooleanInput('debug')
180181
};
181182
if (![
182183
"added" /* ON_ERRORS_ADDED_IN_PR */,
@@ -240,6 +241,7 @@ function getBodyComment({ errorsInProjectBefore, errorsInProjectAfter, errorsInM
240241
s += BLANK_LINE;
241242
}
242243
if (newErrorsInModifiedFiles.length > 0) {
244+
s += BLANK_LINE;
243245
s += `**${newErrorsInModifiedFiles.length} new errors added** \n`;
244246
s += `*Note : in some cases, new errors can be just same errors but with different locations*`;
245247
s += BLANK_LINE;
@@ -252,7 +254,7 @@ function getBodyComment({ errorsInProjectBefore, errorsInProjectAfter, errorsInM
252254
return s;
253255
}
254256
exports.getBodyComment = getBodyComment;
255-
function getListOfErrors(title, errors, thresholdCollapse = 10) {
257+
function getListOfErrors(title, errors, thresholdCollapse = 5) {
256258
const shouldUseCollapsible = errors.length > thresholdCollapse;
257259
let s = ``;
258260
if (shouldUseCollapsible) {
@@ -274,7 +276,7 @@ function getListOfErrors(title, errors, thresholdCollapse = 10) {
274276
}
275277
return s;
276278
}
277-
function getNbOfErrorsByFile(title, errors, thresholdCollapse = 10) {
279+
function getNbOfErrorsByFile(title, errors, thresholdCollapse = 5) {
278280
const errorsByFile = [];
279281
errors.forEach(err => {
280282
const errByFileFound = errorsByFile.find(o => o.fileName === err.fileName);
@@ -299,7 +301,6 @@ function getNbOfErrorsByFile(title, errors, thresholdCollapse = 10) {
299301
s += BLANK_LINE;
300302
}
301303
else {
302-
s += BLANK_LINE;
303304
s += `${title} \n`;
304305
s += BLANK_LINE;
305306
}
@@ -312,9 +313,6 @@ function getNbOfErrorsByFile(title, errors, thresholdCollapse = 10) {
312313
s += BLANK_LINE;
313314
s += `</details> \n`;
314315
}
315-
else {
316-
s += BLANK_LINE;
317-
}
318316
return s;
319317
}
320318

@@ -405,11 +403,14 @@ async function run() {
405403
tsconfigPath
406404
});
407405
const errorsPr = parseOutputTsc_1.parseOutputTsc(tscOutputCurrent);
408-
if (errorsPr.length) {
409-
core_1.info(`[current branch] ts errors : 10 first:\n ${JSON.stringify(errorsPr.slice(0, 10))}`);
410-
}
411-
else {
412-
core_1.info(`[current branch] : no error detected`);
406+
core_1.info(`[current branch] : ${errorsPr.length} error(s) detected`);
407+
const ansiColorsCode = {
408+
magenta: '\u001b[35m',
409+
cyan: '\u001b[38;5;6m',
410+
red: '\u001b[38;2;255;0;0m'
411+
};
412+
if (args.debug) {
413+
core_1.info(`${ansiColorsCode.cyan}[current branch] all errors: \n${JSON.stringify(errorsPr)}`);
413414
}
414415
core_1.endGroup();
415416
// ***********************************************************************************************
@@ -426,7 +427,10 @@ async function run() {
426427
tsconfigPath
427428
});
428429
const errorsBaseBranch = parseOutputTsc_1.parseOutputTsc(tscOutputBase);
429-
core_1.info(`[base branch] ts errors : 10 first : \n ${JSON.stringify(errorsBaseBranch.slice(0, 10))}`);
430+
core_1.info(`[base branch] : ${errorsBaseBranch.length} error(s) detected`);
431+
if (args.debug) {
432+
core_1.info(`${ansiColorsCode.cyan}[base branch] all errors: \n${JSON.stringify(errorsBaseBranch)}`);
433+
}
430434
core_1.endGroup();
431435
core_1.startGroup(`Comparing errors`);
432436
const resultCompareErrors = compareErrors_1.compareErrors({
@@ -437,13 +441,17 @@ async function run() {
437441
filesDeleted: args.filesDeleted,
438442
lineNumbers: args.lineNumbers
439443
});
440-
core_1.info(`Contenu de resultCompareErrors : ${JSON.stringify(resultCompareErrors)}`);
444+
if (args.debug) {
445+
core_1.info(`${ansiColorsCode.cyan}Contenu de resultCompareErrors : ${JSON.stringify(resultCompareErrors)}`);
446+
}
441447
const errorsInModifiedFiles = errorsPr.filter(err => {
442448
return args.filesChanged.concat(args.filesAdded).includes(err.fileName);
443449
});
450+
core_1.info(`${errorsInModifiedFiles.length} errors in modified files`);
444451
const newErrorsInModifiedFiles = resultCompareErrors.errorsAdded.filter(err => {
445452
return args.filesChanged.concat(args.filesAdded).includes(err.fileName);
446453
});
454+
core_1.info(`${newErrorsInModifiedFiles.length} added errors in modified files`);
447455
core_1.endGroup();
448456
core_1.startGroup(`Creating comment`);
449457
const commentInfo = {
@@ -740,6 +748,7 @@ async function runTscCli({ workingDir, tsconfigPath, files }) {
740748
catch (error) {
741749
core_1.setFailed(error.message);
742750
}
751+
process.exitCode = 0;
743752
return {
744753
output: myOutput,
745754
error: myError
@@ -755,14 +764,27 @@ exports.runTscCli = runTscCli;
755764

756765
"use strict";
757766

767+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
768+
if (k2 === undefined) k2 = k;
769+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
770+
}) : (function(o, m, k, k2) {
771+
if (k2 === undefined) k2 = k;
772+
o[k2] = m[k];
773+
}));
774+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
775+
Object.defineProperty(o, "default", { enumerable: true, value: v });
776+
}) : function(o, v) {
777+
o["default"] = v;
778+
});
758779
var __importStar = (this && this.__importStar) || function (mod) {
759780
if (mod && mod.__esModule) return mod;
760781
var result = {};
761-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
762-
result["default"] = mod;
782+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
783+
__setModuleDefault(result, mod);
763784
return result;
764785
};
765786
Object.defineProperty(exports, "__esModule", ({ value: true }));
787+
exports.issue = exports.issueCommand = void 0;
766788
const os = __importStar(__nccwpck_require__(2087));
767789
const utils_1 = __nccwpck_require__(5278);
768790
/**
@@ -841,6 +863,25 @@ function escapeProperty(s) {
841863

842864
"use strict";
843865

866+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
867+
if (k2 === undefined) k2 = k;
868+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
869+
}) : (function(o, m, k, k2) {
870+
if (k2 === undefined) k2 = k;
871+
o[k2] = m[k];
872+
}));
873+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
874+
Object.defineProperty(o, "default", { enumerable: true, value: v });
875+
}) : function(o, v) {
876+
o["default"] = v;
877+
});
878+
var __importStar = (this && this.__importStar) || function (mod) {
879+
if (mod && mod.__esModule) return mod;
880+
var result = {};
881+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
882+
__setModuleDefault(result, mod);
883+
return result;
884+
};
844885
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
845886
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
846887
return new (P || (P = Promise))(function (resolve, reject) {
@@ -850,14 +891,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
850891
step((generator = generator.apply(thisArg, _arguments || [])).next());
851892
});
852893
};
853-
var __importStar = (this && this.__importStar) || function (mod) {
854-
if (mod && mod.__esModule) return mod;
855-
var result = {};
856-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
857-
result["default"] = mod;
858-
return result;
859-
};
860894
Object.defineProperty(exports, "__esModule", ({ value: true }));
895+
exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
861896
const command_1 = __nccwpck_require__(7351);
862897
const file_command_1 = __nccwpck_require__(717);
863898
const utils_1 = __nccwpck_require__(5278);
@@ -924,7 +959,9 @@ function addPath(inputPath) {
924959
}
925960
exports.addPath = addPath;
926961
/**
927-
* Gets the value of an input. The value is also trimmed.
962+
* Gets the value of an input.
963+
* Unless trimWhitespace is set to false in InputOptions, the value is also trimmed.
964+
* Returns an empty string if the value is not defined.
928965
*
929966
* @param name name of the input to get
930967
* @param options optional. See InputOptions.
@@ -935,9 +972,49 @@ function getInput(name, options) {
935972
if (options && options.required && !val) {
936973
throw new Error(`Input required and not supplied: ${name}`);
937974
}
975+
if (options && options.trimWhitespace === false) {
976+
return val;
977+
}
938978
return val.trim();
939979
}
940980
exports.getInput = getInput;
981+
/**
982+
* Gets the values of an multiline input. Each value is also trimmed.
983+
*
984+
* @param name name of the input to get
985+
* @param options optional. See InputOptions.
986+
* @returns string[]
987+
*
988+
*/
989+
function getMultilineInput(name, options) {
990+
const inputs = getInput(name, options)
991+
.split('\n')
992+
.filter(x => x !== '');
993+
return inputs;
994+
}
995+
exports.getMultilineInput = getMultilineInput;
996+
/**
997+
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
998+
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .
999+
* The return value is also in boolean type.
1000+
* ref: https://yaml.org/spec/1.2/spec.html#id2804923
1001+
*
1002+
* @param name name of the input to get
1003+
* @param options optional. See InputOptions.
1004+
* @returns boolean
1005+
*/
1006+
function getBooleanInput(name, options) {
1007+
const trueValue = ['true', 'True', 'TRUE'];
1008+
const falseValue = ['false', 'False', 'FALSE'];
1009+
const val = getInput(name, options);
1010+
if (trueValue.includes(val))
1011+
return true;
1012+
if (falseValue.includes(val))
1013+
return false;
1014+
throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
1015+
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
1016+
}
1017+
exports.getBooleanInput = getBooleanInput;
9411018
/**
9421019
* Sets the value of an output.
9431020
*
@@ -946,6 +1023,7 @@ exports.getInput = getInput;
9461023
*/
9471024
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9481025
function setOutput(name, value) {
1026+
process.stdout.write(os.EOL);
9491027
command_1.issueCommand('set-output', { name }, value);
9501028
}
9511029
exports.setOutput = setOutput;
@@ -1087,14 +1165,27 @@ exports.getState = getState;
10871165
"use strict";
10881166

10891167
// For internal use, subject to change.
1168+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1169+
if (k2 === undefined) k2 = k;
1170+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1171+
}) : (function(o, m, k, k2) {
1172+
if (k2 === undefined) k2 = k;
1173+
o[k2] = m[k];
1174+
}));
1175+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1176+
Object.defineProperty(o, "default", { enumerable: true, value: v });
1177+
}) : function(o, v) {
1178+
o["default"] = v;
1179+
});
10901180
var __importStar = (this && this.__importStar) || function (mod) {
10911181
if (mod && mod.__esModule) return mod;
10921182
var result = {};
1093-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1094-
result["default"] = mod;
1183+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1184+
__setModuleDefault(result, mod);
10951185
return result;
10961186
};
10971187
Object.defineProperty(exports, "__esModule", ({ value: true }));
1188+
exports.issueCommand = void 0;
10981189
// We use any as a valid input type
10991190
/* eslint-disable @typescript-eslint/no-explicit-any */
11001191
const fs = __importStar(__nccwpck_require__(5747));
@@ -1125,6 +1216,7 @@ exports.issueCommand = issueCommand;
11251216
// We use any as a valid input type
11261217
/* eslint-disable @typescript-eslint/no-explicit-any */
11271218
Object.defineProperty(exports, "__esModule", ({ value: true }));
1219+
exports.toCommandValue = void 0;
11281220
/**
11291221
* Sanitizes an input into a string so it can be passed into issueCommand safely
11301222
* @param input input to sanitize into a string

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/typescript/lib/tsserverlibrary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158811,7 +158811,7 @@ var ts;
158811158811
function getDefaultLibFilePath(options) {
158812158812
// Check __dirname is defined and that we are on a node.js system.
158813158813
if (typeof __dirname !== "undefined") {
158814-
return __nccwpck_require__.ab + "typescript3/lib" + ts.directorySeparator + '' + ts.getDefaultLibFileName(options);
158814+
return __nccwpck_require__.ab + "typescript2/lib" + ts.directorySeparator + '' + ts.getDefaultLibFileName(options);
158815158815
}
158816158816
throw new Error("getDefaultLibFilePath is only supported when consumed as a node module. ");
158817158817
}

dist/typescript/lib/typescriptServices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158811,7 +158811,7 @@ var ts;
158811158811
function getDefaultLibFilePath(options) {
158812158812
// Check __dirname is defined and that we are on a node.js system.
158813158813
if (typeof __dirname !== "undefined") {
158814-
return __nccwpck_require__.ab + "typescript2/lib" + ts.directorySeparator + '' + ts.getDefaultLibFileName(options);
158814+
return __nccwpck_require__.ab + "typescript3/lib" + ts.directorySeparator + '' + ts.getDefaultLibFileName(options);
158815158815
}
158816158816
throw new Error("getDefaultLibFilePath is only supported when consumed as a node module. ");
158817158817
}

src/getAndValidateArgs.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInput } from '@actions/core'
1+
import { getBooleanInput, getInput } from '@actions/core'
22

33
export const enum CHECK_FAIL_MODE {
44
ON_ERRORS_ADDED_IN_PR = 'added',
@@ -38,20 +38,22 @@ type Args = {
3838
*/
3939
lineNumbers: { path: string, added: number[], removed: number[] }[]
4040
useCheck: boolean
41-
checkFailMode: CHECK_FAIL_MODE
41+
checkFailMode: CHECK_FAIL_MODE,
42+
debug: boolean
4243
}
4344

4445
export function getAndValidateArgs(): Args {
4546
const args = {
46-
repoToken: getInput('repo-token', { required: true }),
47-
directory: getInput('directory'),
48-
tsConfigPath: getInput('ts-config-path'),
47+
repoToken: getInput('repo-token', { required: true, trimWhitespace: true }),
48+
directory: getInput('directory', { trimWhitespace: true }),
49+
tsConfigPath: getInput('ts-config-path', { trimWhitespace: true, required: true }),
4950
filesChanged: (getInput('files-changed') ?? "").split(" "),
5051
filesAdded: (getInput('files-added') ?? "").split(" "),
5152
filesDeleted: (getInput('files-deleted') ?? "").split(" "),
5253
lineNumbers: JSON.parse(getInput('line-numbers')) ?? [],
53-
useCheck: getInput('use-check').trim() === 'true' ? true : false,
54-
checkFailMode: getInput('check-fail-mode') as CHECK_FAIL_MODE
54+
useCheck: getBooleanInput('use-check'),
55+
checkFailMode: getInput('check-fail-mode') as CHECK_FAIL_MODE,
56+
debug: getBooleanInput('debug')
5557
}
5658

5759
if (![

0 commit comments

Comments
 (0)