diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..00f29e84aeb650cedbdac21fecdd8691e12834aa --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,11 @@ +check-links: + stage: test + tags: + - docker + image: "node:14" + before_script: + - npm install -g markdown-link-check + script: + - cd scripts + - ./link-checker.sh + diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8507d04478ddcba4537331f591283de454ba4577 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,8 @@ +# Scripts + +## Link Checker + +Files: + +- [link-checker.sh](./link-checker.sh): Main script to check each markdown file for broken external links and relative links. Uses [markdown-link-check](https://www.npmjs.com/package/markdown-link-check). +- [link-checker-config.json](./link-checker-config.json): Configuration file for [markdown-link-check](https://www.npmjs.com/package/markdown-link-check). Used to exclude certain links so that they are not checked. This could be done for example links or links to websites that are sometimes down or timeout. \ No newline at end of file diff --git a/scripts/link-checker-config.json b/scripts/link-checker-config.json new file mode 100644 index 0000000000000000000000000000000000000000..461e321cda88efec19b98cdcbc51fb7db5dd0e11 --- /dev/null +++ b/scripts/link-checker-config.json @@ -0,0 +1,7 @@ +{ + "ignorePatterns": [ + { + "pattern": "interop.it.wisc.edu" + } + ] +} diff --git a/scripts/link-checker.sh b/scripts/link-checker.sh new file mode 100755 index 0000000000000000000000000000000000000000..3c2a0da7249800e213b61a8d255c499ba07fbb65 --- /dev/null +++ b/scripts/link-checker.sh @@ -0,0 +1,20 @@ +exit_code=0 + +# Find all markdown files +markdown_files=$(find ../ -name \*.md) + +for markdown_file in $markdown_files; do + # For each markdown file, check the links. link-checker-config.json excludes certain links (like example.com) + # If broken links are found, output them along with the file path. + if markdown-link-check -q -c link-checker-config.json $markdown_file > links.log; then + # Do nothing if the file doesn't have any broken links. + : + else + # If broken links are found, output them along with the file path. + cat links.log + exit_code=1 + fi + rm links.log +done + +exit $exit_code