Skip to content

Commit

Permalink
Exclude file
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-nelson committed Apr 21, 2021
1 parent 6b8ce7c commit 4459b86
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand All @@ -58,3 +62,4 @@ runs:
- ${{ inputs.base-branch }}
- ${{ inputs.file-extension }}
- ${{ inputs.file-path }}
- ${{ inputs.exclude }}
30 changes: 24 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ RED='\033[0;31m'
npm i -g [email protected]

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"
Expand All @@ -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}"
Expand All @@ -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}"
Expand All @@ -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 () {

Expand All @@ -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]}")
Expand All @@ -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
Expand All @@ -83,6 +89,16 @@ handle_files () {

}

handle_excluded () {

if [ -n "${10}" ]; then
EXCLUDED_FILES_DIRS=$(echo $EXCLUDE | sed -r 's/[,]+/ -E/g')
else
EXCLUDED_FILES_DIRS=".git"
fi

}

check_errors () {

if [ -e error.txt ] ; then
Expand Down Expand Up @@ -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
Expand All @@ -142,6 +158,8 @@ check_additional_files () {

}

handle_excluded

if [ -z "$8" ]; then
FOLDERS="."
else
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion md/dir3/dir3level2/level-2a.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ 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

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).
Expand Down

0 comments on commit 4459b86

Please sign in to comment.