diff --git a/Dockerfile b/Dockerfile index 270c8ff..158c62f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM node:alpine +RUN apk add --no-cache bash ADD entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 7e51c0f..8f30842 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,27 @@ This GitHub action checks all Markdown files in your repository for broken links for markdown-link-check, create a JSON configuration file and save it in the root folder as `mlc_config.json`. -## Test links +## Test internal and external links www.google.com -[This is a broken link](www.exampleexample.cox) +[This is a broken link](https://www.exampleexample.cox) [This is another broken link](http://ignored-domain.com) but its ignored using a configuration file. + +### Alpha + +This [exists](#alpha). +This [one does not](#does-not). +References and definitions are [checked][alpha] [too][charlie]. + +### Bravo + +Headings in `readme.md` are [not checked](readme.md#bravo). +But [missing files are reported](missing-example.js). + +[alpha]: #alpha +[charlie]: #charlie + +External file: [Charlie](./README2.md/#charlie) \ No newline at end of file diff --git a/README2.md b/README2.md new file mode 100644 index 0000000..3c107b7 --- /dev/null +++ b/README2.md @@ -0,0 +1,10 @@ +# Checking more links + +## Bravo + +This [doesn't exists](#alpha). +This [one does](#bravo). + +## Charlie + +This is linked from README file. \ No newline at end of file diff --git a/action.yml b/action.yml index cf1bded..8641179 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,25 @@ author: 'Gaurav Nelson' branding: icon: 'link' color: 'green' +inputs: + use-quite-mode: + description: 'Use yes to enable markdown-link-check quite mode which only + list errors.' + required: true + default: 'no' + use-verbose-mode: + description: 'Use yes to enable markdown-link-check verbose mode which lists + additional details.' + required: true + default: 'no' + config-file: + description: 'Specify path to a markdown-link-check JSON configuration file.' + required: true + default: 'mlc_config.json' runs: using: 'docker' image: 'Dockerfile' + args: + - ${{ inputs.use-quite-mode }} + - ${{ inputs.use-verbose-mode }} + - ${{ inputs.config-file }} diff --git a/entrypoint.sh b/entrypoint.sh index 1ba7d7a..598a696 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,24 +9,77 @@ BLUE='\033[0;34m' npm i -g markdown-link-check -CONFIG_FILE=mlc_config.json +USE_QUITE_MODE="$1" +USE_VERBOSE_MODE="$2" +CONFIG_FILE="$3" -echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}" +echo "USE_QUITE_MODE: $1" +echo "USE_VERBOSE_MODE: $2" + +if [ "$USE_QUITE_MODE" = "yes" ]; then + + if [ "$USE_VERBOSE_MODE" = "yes" ]; then + + if [ -f "$CONFIG_FILE" ]; then + echo -e "${BLUE}I found config file ${NC}" + 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" -vq \; &>> 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 {} -vq \; &>> error.txt + fi + + else + + 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" -q \; &>> 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 {} -q \; &>> error.txt + fi + + fi + +else + + if [ "$USE_VERBOSE_MODE" = "yes" ]; then + + 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" -v \; &>> 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 {} -v \; &>> error.txt + fi + + else + + 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" \; &>> 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 {} \; &>> error.txt + fi + + fi -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 + echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}" + less error.txt + echo -e "${YELLOW}=========================================================================${NC}" exit 113 fi else