Skip to content

Commit 00b7681

Browse files
umbrella (#87)
1 parent 09b08cf commit 00b7681

File tree

3 files changed

+94
-15
lines changed

3 files changed

+94
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
https://github.com/Consensys/github-actions acts as a single source of truth (sot) for actions that we use
44

5+
# TODO
6+
- Add lint checks on this repo

docs-link-check/action.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ inputs:
88
description: 'default config file.'
99
required: false
1010
default: .github-actions/docs-link-check/config/.linkspector.yml
11-
FAIL_LEVEL:
12-
description: 'exit code for reviewdog when errors are found with severity greater than or equal to this level'
13-
required: false
14-
default: 'any'
15-
FILTER_MODE:
16-
description: 'filtering mode for reviewdog command'
17-
required: false
18-
default: 'nofilter'
1911
runs:
2012
using: "composite"
2113
steps:
@@ -25,11 +17,34 @@ runs:
2517
repository: Consensys/github-actions
2618
path: .github-actions
2719

28-
# also needs reviewdog/action-setup@v1
29-
# reviewdog/action-setup@d8edfce3dd5e1ec6978745e801f9c50b5ef80252
30-
- name: Test links
31-
uses: umbrelladocs/action-linkspector@652f85bc57bb1e7d4327260decc10aa68f7694c3
20+
- name: Use Node.js
21+
- uses: actions/setup-node@v4
3222
with:
33-
config_file: ${{ inputs.CONFIG_FILE }}
34-
fail_level: ${{ inputs.FAIL_LEVEL }}
35-
filter_mode: ${{ inputs.FILTER_MODE }}
23+
node-version: 20
24+
25+
# Fix Chrome sandbox issues on Ubuntu 24.04
26+
- name: Setup Chrome Linux Sandbox
27+
shell: bash
28+
run: |
29+
# Based on https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
30+
if [ "$(lsb_release -rs)" = "24.04" ]; then
31+
echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
32+
echo 'Done'
33+
else
34+
echo "Not running on Ubuntu 24.04 — skipping sandbox fix"
35+
fi
36+
37+
- name: Install linkspector
38+
shell: bash
39+
run: |
40+
npm install -g @umbrelladocs/[email protected]
41+
42+
# Run linkspector and fail if there are broken links
43+
- name: Run linkspector
44+
shell: bash
45+
run: |
46+
set -eo pipefail
47+
linkspector --version
48+
echo "🔍 Checking for broken links..."
49+
linkspector check -c ${{ inputs.CONFIG_FILE }}
50+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Wrapper for @umbrelladocs/linkspector
4+
* Fixes CommonJS import of @umbrelladocs/rdformat-validator for Node 20+.
5+
* Works when dependencies are installed in the caller repository.
6+
*/
7+
8+
import { fileURLToPath } from "url";
9+
import { dirname, resolve } from "path";
10+
import { createRequire } from "module";
11+
12+
const __dirname = dirname(fileURLToPath(import.meta.url));
13+
14+
async function importValidator() {
15+
try {
16+
// Try local import first
17+
return await import("@umbrelladocs/rdformat-validator");
18+
} catch {
19+
console.warn("⚠️ validator not found locally; resolving from caller repo...");
20+
try {
21+
// Dynamically resolve from the parent repository
22+
const require = createRequire(import.meta.url);
23+
const path = require.resolve("@umbrelladocs/rdformat-validator", {
24+
paths: [resolve(process.cwd(), "node_modules")],
25+
});
26+
return await import(`file://${path}`);
27+
} catch (err) {
28+
console.error("❌ Could not resolve @umbrelladocs/rdformat-validator", err);
29+
process.exit(1);
30+
}
31+
}
32+
}
33+
34+
async function main() {
35+
// Import linkspector CLI
36+
let linkspector;
37+
try {
38+
linkspector = await import("@umbrelladocs/linkspector/lib/cli.js");
39+
} catch (err) {
40+
console.error("❌ Could not import @umbrelladocs/linkspector CLI:", err);
41+
process.exit(1);
42+
}
43+
44+
// Import validator safely
45+
const validatorPkg = await importValidator();
46+
const { validateAndFix } = validatorPkg;
47+
globalThis.validateAndFix = validateAndFix;
48+
49+
// Run linkspector’s CLI
50+
const cli = linkspector.default || linkspector.run;
51+
if (typeof cli === "function") {
52+
await cli();
53+
} else {
54+
console.error("⚠️ No valid entry point found in linkspector.");
55+
process.exit(1);
56+
}
57+
}
58+
59+
main().catch((err) => {
60+
console.error("❌ linkspector wrapper failed:", err);
61+
process.exit(1);
62+
});

0 commit comments

Comments
 (0)