Skip to content

Commit 118abd4

Browse files
feat: add verbosity setting (#33)
1 parent 5d8040e commit 118abd4

File tree

8 files changed

+43
-12
lines changed

8 files changed

+43
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v2
1212
- uses: ./
1313
with:
14-
skip: "https://www.github.com/JustinBeckwith/linkinator-action/compare"
14+
skip: "CHANGELOG.md"
1515
- uses: ./
1616
with:
1717
paths: test/fixtures/test.md

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ jobs:
5353
## Outputs
5454
- `results` - An object with the results of the run.
5555

56+
## Debugging
57+
To view skipped links, failure details, and more debugging information [enable step debug logging](https://docs.github.com/en/free-pro-team@latest/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging).
58+
5659
## License
5760
[MIT](LICENSE)

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ inputs:
1616
default: false
1717
linksToSkip:
1818
description: 'List of urls in regexy form to not include in the check.'
19+
skip:
20+
description: 'List of urls in regexy form to not include in the check.'
1921
timeout:
2022
description: 'Request timeout in ms. Defaults to 0 (no timeout).'
2123
default: 0

dist/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32725,7 +32725,7 @@ function wrappy (fn, cb) {
3272532725
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3272632726

3272732727
const core = __webpack_require__(2186);
32728-
const { LinkChecker } = __webpack_require__(356);
32728+
const { LinkChecker, LinkState } = __webpack_require__(356);
3272932729

3273032730
async function main () {
3273132731
try {
@@ -32745,20 +32745,33 @@ async function main () {
3274532745

3274632746
const checker = new LinkChecker()
3274732747
.on('pagestart', url => {
32748-
console.log(`Scanning ${url}`);
32748+
core.info(`Scanning ${url}`);
32749+
})
32750+
.on('link', link => {
32751+
switch (link.state) {
32752+
case LinkState.BROKEN:
32753+
core.error(`[${link.status.toString()}] ${link.url}`);
32754+
break;
32755+
case LinkState.OK:
32756+
core.info(`[${link.status.toString()}] ${link.url}`);
32757+
break;
32758+
case LinkState.SKIPPED:
32759+
core.debug(`[SKP] ${link.url}`);
32760+
break;
32761+
}
3274932762
});
3275032763

3275132764
const result = await checker.check(options);
32765+
core.info(`Scanned total of ${result.links.length} links!`);
3275232766
if (!result.passed) {
3275332767
const brokenLinks = result.links.filter(x => x.state === 'BROKEN');
3275432768
let failureOutput = `Detected ${brokenLinks.length} broken links.`;
3275532769
for (const link of brokenLinks) {
3275632770
failureOutput += `\n [${link.status}] ${link.url}`;
32771+
core.debug(JSON.stringify(link.failureDetails, null, 2));
3275732772
}
3275832773
core.setFailed(failureOutput);
32759-
return;
3276032774
}
32761-
console.log(`Scanned total of ${result.links.length} links!`);
3276232775
core.setOutput('results', result);
3276332776
} catch (err) {
3276432777
core.setFailed(`Linkinator exception: \n${err.message}\n${err.stack}`);

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.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"homepage": "https://github.com/JustinBeckwith/linkinator-action#readme",
2727
"dependencies": {
2828
"@actions/core": "^1.2.6",
29+
"chalk": "^4.1.0",
2930
"linkinator": "2.12.1"
3031
},
3132
"devDependencies": {

src/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const core = require('@actions/core');
2-
const { LinkChecker } = require('linkinator');
2+
const { LinkChecker, LinkState } = require('linkinator');
33

44
async function main () {
55
try {
@@ -19,20 +19,33 @@ async function main () {
1919

2020
const checker = new LinkChecker()
2121
.on('pagestart', url => {
22-
console.log(`Scanning ${url}`);
22+
core.info(`Scanning ${url}`);
23+
})
24+
.on('link', link => {
25+
switch (link.state) {
26+
case LinkState.BROKEN:
27+
core.error(`[${link.status.toString()}] ${link.url}`);
28+
break;
29+
case LinkState.OK:
30+
core.info(`[${link.status.toString()}] ${link.url}`);
31+
break;
32+
case LinkState.SKIPPED:
33+
core.debug(`[SKP] ${link.url}`);
34+
break;
35+
}
2336
});
2437

2538
const result = await checker.check(options);
39+
core.info(`Scanned total of ${result.links.length} links!`);
2640
if (!result.passed) {
2741
const brokenLinks = result.links.filter(x => x.state === 'BROKEN');
2842
let failureOutput = `Detected ${brokenLinks.length} broken links.`;
2943
for (const link of brokenLinks) {
3044
failureOutput += `\n [${link.status}] ${link.url}`;
45+
core.debug(JSON.stringify(link.failureDetails, null, 2));
3146
}
3247
core.setFailed(failureOutput);
33-
return;
3448
}
35-
console.log(`Scanned total of ${result.links.length} links!`);
3649
core.setOutput('results', result);
3750
} catch (err) {
3851
core.setFailed(`Linkinator exception: \n${err.message}\n${err.stack}`);

test/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ describe('linkinator action', () => {
3434
const inputStub = sinon.stub(core, 'getInput');
3535
inputStub.withArgs('paths').returns('test/fixtures/test.md');
3636
inputStub.returns('');
37-
const setOutputStub = sinon.stub(core, 'setOutput');
37+
sinon.stub(core, 'setOutput');
3838
const setFailedStub = sinon.stub(core, 'setFailed');
3939
const scope = nock('http://fake.local')
4040
.head('/').reply(404)
4141
.head('/fake').reply(404);
4242
await action();
4343
assert.ok(inputStub.called);
44-
assert.ok(setOutputStub.notCalled);
4544
assert.ok(setFailedStub.called);
4645
scope.done();
4746
});

0 commit comments

Comments
 (0)