From ba713a211955639ee05fbea1a3c2381d0365ab18 Mon Sep 17 00:00:00 2001 From: Gaurav Nelson Date: Wed, 9 Oct 2019 10:53:02 +1000 Subject: [PATCH] Added support for markdown-link-check config file --- README.md | 6 ++++++ entrypoint.sh | 23 ++++++++++++++++++++--- mlc_config.json | 7 +++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 mlc_config.json diff --git a/README.md b/README.md index 5c2086c..ebbdce3 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,15 @@ This GitHub action checks all Markdown files in your repository for broken links fetch-depth: 1 - uses: gaurav-nelson/github-action-markdown-link-check@0.2.0 ``` +1. To use a [custom configuration](https://github.com/tcort/markdown-link-check#config-file-format) + for markdown-link-check, create a JSON configuration file and save it in the + root filder as `mlc_config.json`. ## Test links www.google.com [This is a broken link](www.exampleexample.cox) + +[This is another broken link](http://ignored-domain.com) but its ignored using a +configuration file. diff --git a/entrypoint.sh b/entrypoint.sh index 23f827f..1ba7d7a 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,16 +2,33 @@ set -eu +NC='\033[0m' # No Color +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' + npm i -g markdown-link-check -echo "=========================> MARKDOWN LINK CHECK <=========================" +CONFIG_FILE=mlc_config.json -find . -name \*.md -not -path "./node_modules/*" -exec markdown-link-check {} \; 2> error.txt +echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}" -echo "=========================================================================" +if [ -f "$CONFIG_FILE" ]; then + echo -e "${BLUE}Using markdown-link-check configuration file: ${YELLOW}$CONFIG_FILE${NC}" + find . -name \*.md -not -path "./node_modules/*" -exec markdown-link-check {} --config "$CONFIG_FILE" \; 2> error.txt +else + echo -e "${BLUE}Cannot find ${YELLOW}$CONFIG_FILE${NC}" + echo -e "${YELLOW}NOTE: See https://github.com/tcort/markdown-link-check#config-file-format to know more about" + echo -e "customizing markdown-link-check by using a configuration file.${NC}" + find . -name \*.md -not -path "./node_modules/*" -exec markdown-link-check {} \; 2> error.txt +fi + +echo -e "${YELLOW}=========================================================================${NC}" if [ -e error.txt ] ; then if grep -q "ERROR:" error.txt; then exit 113 fi +else + echo -e "${GREEN}All good!${NC}" fi diff --git a/mlc_config.json b/mlc_config.json new file mode 100644 index 0000000..32c722a --- /dev/null +++ b/mlc_config.json @@ -0,0 +1,7 @@ +{ + "ignorePatterns": [ + { + "pattern": "^http://ignored-domain.com" + } + ] +} \ No newline at end of file