diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 450e78f..61980f1 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -17,8 +17,9 @@ jobs: uses: ./ with: # Add a test to restrict the test to just dir4 and dir5. - folder-path: './md/dir4, ./md/dir5' + #folder-path: './md/dir4, ./md/dir5, ./md/dir3' file-path: './md/AdditionalFileTest1.md, ./md/AdditionalFileTest2.md' + exclude: 'md/dir3/dir3level2, md/dir4, md/dir5' shellcheck: runs-on: [ubuntu-latest] steps: diff --git a/action.yml b/action.yml index ee0f4b7..4911ae9 100644 --- a/action.yml +++ b/action.yml @@ -2,7 +2,7 @@ name: 'markdown-link-check' description: 'Check if all links are valid in markdown files.' author: 'Gaurav Nelson' branding: - icon: 'link' + icon: 'link' color: 'green' inputs: use-quiet-mode: @@ -44,6 +44,10 @@ inputs: description: 'Specify additional files you want to check' required: true default: '' + exclude: + description: 'Specify directories and files you want to skip.' + required: true + default: '' runs: using: 'docker' @@ -58,3 +62,4 @@ runs: - ${{ inputs.base-branch }} - ${{ inputs.file-extension }} - ${{ inputs.file-path }} + - ${{ inputs.exclude }} diff --git a/entrypoint.sh b/entrypoint.sh index 1109137..43230ed 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,8 +11,9 @@ RED='\033[0;31m' npm i -g markdown-link-check@3.8.6 declare -a FIND_CALL -declare -a COMMAND_DIRS COMMAND_FILES +declare -a COMMAND_DIRS declare -a COMMAND_FILES +declare -a COMMAND_EXCLUDE USE_QUIET_MODE="$1" USE_VERBOSE_MODE="$2" @@ -27,6 +28,7 @@ else FILE_EXTENSION="$8" fi FILE_PATH="$9" +EXCLUDE=$(echo ${10}) if [ -f "$CONFIG_FILE" ]; then echo -e "${BLUE}Using markdown-link-check configuration file: ${YELLOW}$CONFIG_FILE${NC}" @@ -38,6 +40,7 @@ fi FOLDERS="" FILES="" +EXCLUDED_FILES_DIRS="" echo -e "${BLUE}USE_QUIET_MODE: $1${NC}" echo -e "${BLUE}USE_VERBOSE_MODE: $2${NC}" @@ -46,6 +49,7 @@ echo -e "${BLUE}MAX_DEPTH: $5${NC}" echo -e "${BLUE}CHECK_MODIFIED_FILES: $6${NC}" echo -e "${BLUE}FILE_EXTENSION: $8${NC}" echo -e "${BLUE}FILE_PATH: $9${NC}" +echo -e "${BLUE}EXCLUDE: ${10}${NC}" handle_dirs () { @@ -55,6 +59,7 @@ handle_dirs () { do if [ ! -d "${DIRLIST[index]}" ]; then echo -e "${RED}ERROR [✖] Can't find the directory: ${YELLOW}${DIRLIST[index]}${NC}" + echo -e "${RED}Check folder-path variable!" exit 2 fi COMMAND_DIRS+=("${DIRLIST[index]}") @@ -71,6 +76,7 @@ handle_files () { do if [ ! -f "${FILELIST[index]}" ]; then echo -e "${RED}ERROR [✖] Can't find the file: ${YELLOW}${FILELIST[index]}${NC}" + echo -e "${RED}Check file-path variable!" exit 2 fi if [ $index == 0 ]; then @@ -83,6 +89,16 @@ handle_files () { } +handle_excluded () { + + if [ -n "${EXCLUDE}" ]; then + EXCLUDED_FILES_DIRS=$(echo $EXCLUDE | sed -r 's/[,]+/ -E/g') + else + EXCLUDED_FILES_DIRS=".git" + fi + +} + check_errors () { if [ -e error.txt ] ; then @@ -125,9 +141,9 @@ check_additional_files () { if [ -n "$FILES" ]; then if [ "$MAX_DEPTH" -ne -1 ]; then - FIND_CALL=('fd' '--type' 'f' '-p' '('"${FILES// /}"')' '--max-depth' "${MAX_DEPTH}" '.' '--exec' 'markdown-link-check') + FIND_CALL=('fd' '--type' 'f' '-p' '('"${FILES// /}"')' '--max-depth' "${MAX_DEPTH}" '.' '-E' "${EXCLUDED_FILES_DIRS}" '--exec' 'markdown-link-check') else - FIND_CALL=('fd' '--type' 'f' '-p' '('"${FILES// /}"')' '.' '--exec' 'markdown-link-check') + FIND_CALL=('fd' '--type' 'f' '-p' '('"${FILES// /}"')' '.' '-E' "${EXCLUDED_FILES_DIRS}" '--exec' 'markdown-link-check') fi add_options @@ -142,6 +158,8 @@ check_additional_files () { } +handle_excluded + if [ -z "$8" ]; then FOLDERS="." else @@ -176,15 +194,15 @@ if [ "$CHECK_MODIFIED_FILES" = "yes" ]; then done check_additional_files - + check_errors else if [ "$5" -ne -1 ]; then - FIND_CALL=('fd' '.' ${FOLDERS} '-e' "${FILE_EXTENSION}" '--max-depth' "${MAX_DEPTH}" '--exec' 'markdown-link-check') + FIND_CALL=('fd' '.' ${FOLDERS} '-e' "${FILE_EXTENSION}" '--max-depth' "${MAX_DEPTH}" '-E' ${EXCLUDED_FILES_DIRS} '--exec' 'markdown-link-check') else - FIND_CALL=('fd' '.' ${FOLDERS} '-e' "${FILE_EXTENSION}" '--exec' 'markdown-link-check') + FIND_CALL=('fd' '.' ${FOLDERS} '-e' "${FILE_EXTENSION}" '-E' ${EXCLUDED_FILES_DIRS} '--exec' 'markdown-link-check') fi add_options diff --git a/md/dir3/dir3level2/level-2a.md b/md/dir3/dir3level2/level-2a.md index 1930c4d..60a679c 100644 --- a/md/dir3/dir3level2/level-2a.md +++ b/md/dir3/dir3level2/level-2a.md @@ -6,7 +6,7 @@ www.google.com [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. +configuration file. ### Alpha @@ -14,6 +14,8 @@ This [exists](#alpha). This [one does not](#does-not). References and definitions are [checked][alpha] [too][charlie]. +[fail](https://www.nodsfhdksjhfshdkdhskajfsa.cox) + ### Bravo Headings in `readme.md` are [not checked](file1.md#bravo).