Skip to content

Commit

Permalink
fix: clear message when clover file is not found (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu authored Nov 2, 2022
1 parent ef0717e commit 12a1181
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ jobs:
- name: Checkout code
uses: actions/checkout@master

- name: clover file not found
uses: ./.
continue-on-error: true
with:
dir-prefix: /var/www/html
file: not.found.xml
base-file: not.found.too.xml
signature: "file not found"

- name: clover file to comment (clover.example.xml)
uses: ./.
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- action was "panicking" when the `file` with the coverage was not found, a clearer message is shown now.

## [0.7.0] - 2022-10-21

### Changed
Expand Down
10 changes: 7 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89630,6 +89630,7 @@ function checkThreshold(c, o) {
}
});
}
var notFoundMessage = "was not found, please check if the path is valid, or if it exists.";
var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
var commit, cStats, _a, oldStats, _b, _c, msgs, body, _d, _e, commentId, comments, i, c, e_1;
var _g, _h, _j;
Expand All @@ -89645,12 +89646,15 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
if (!context.payload.pull_request)
return [2 /*return*/];
commit = (_g = context.payload.pull_request) === null || _g === void 0 ? void 0 : _g.head.sha.substring(0, 7);
if (!require$$0$1.existsSync(file)) {
throw "file \"".concat(file, "\" ").concat(notFoundMessage);
}
_a = fromString;
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(file)];
case 1:
cStats = _a.apply(void 0, [(_k.sent()).toString()]);
if (baseFile && !require$$0$1.existsSync(baseFile)) {
coreExports.error("file ".concat(baseFile, " was not found"));
coreExports.error("base file \"".concat(baseFile, "\" ").concat(notFoundMessage));
baseFile = undefined;
}
_b = baseFile;
Expand Down Expand Up @@ -89686,7 +89690,7 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
return [3 /*break*/, 8];
case 7:
e_1 = _k.sent();
console.error(e_1);
coreExports.error(e_1);
return [3 /*break*/, 8];
case 8:
if (!commentId) return [3 /*break*/, 12];
Expand All @@ -89707,5 +89711,5 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
}
});
}); };
run();
run()["catch"](coreExports.setFailed);
//# sourceMappingURL=index.js.map
2 changes: 1 addition & 1 deletion bin/index.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ function* checkThreshold(c: Stats, o?: Stats) {
}
}

const notFoundMessage =
"was not found, please check if the path is valid, or if it exists.";

const run = async () => {
if (!["lines", "methods", "branchs"].includes(tableWithTypeLimit)) {
error(`there is no coverage type ${tableWithTypeLimit}`);
Expand All @@ -134,10 +137,14 @@ const run = async () => {

const commit = context.payload.pull_request?.head.sha.substring(0, 7);

if (!existsSync(file)) {
throw `file "${file}" ${notFoundMessage}`;
}

const cStats = fromString((await promisify(readFile)(file)).toString());

if (baseFile && !existsSync(baseFile)) {
error(`file ${baseFile} was not found`);
error(`base file "${baseFile}" ${notFoundMessage}`);
baseFile = undefined;
}

Expand Down Expand Up @@ -174,7 +181,7 @@ ${signature}`;
commentId = c.id;
}
} catch (e) {
console.error(e);
error(e);
}

if (commentId) {
Expand All @@ -195,4 +202,4 @@ ${signature}`;
});
};

run();
run().catch(setFailed);

0 comments on commit 12a1181

Please sign in to comment.