Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fd test #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:alpine
RUN apk add --no-cache bash>5.0.16-r0 git>2.26.0-r0
RUN apk add --no-cache bash>5.0.16-r0 git>2.26.0-r0 fd>8.1.1-r0
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
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 }}
36 changes: 27 additions & 9 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 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"
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,18 +76,29 @@ 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
COMMAND_FILES+=("-wholename ${FILELIST[index]}")
if [ $index == 0 ]; then
COMMAND_FILES+=("${FILELIST[index]}")
else
COMMAND_FILES+=("-o -wholename ${FILELIST[index]}")
COMMAND_FILES+=("|${FILELIST[index]}")
fi
done
FILES="${COMMAND_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
Expand Down Expand Up @@ -125,9 +141,9 @@ check_additional_files () {

if [ -n "$FILES" ]; then
if [ "$MAX_DEPTH" -ne -1 ]; then
FIND_CALL=('find' '.' '-type' 'f' '(' ${FILES} ')' '-not' '-path' './node_modules/*' '-maxdepth' "${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=('find' '.' '-type' 'f' '(' ${FILES} ')' '-not' '-path' './node_modules/*' '-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=('find' ${FOLDERS} '-name' '*'"${FILE_EXTENSION}" '-not' '-path' './node_modules/*' '-maxdepth' "${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=('find' ${FOLDERS} '-name' '*'"${FILE_EXTENSION}" '-not' '-path' './node_modules/*' '-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