Skip to content

Commit

Permalink
Check additional files
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-nelson committed Aug 9, 2020
1 parent 02e1702 commit e5525bd
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
uses: ./
with:
use-quiet-mode: 'yes'
folder-path: 'md'
folder-path: 'md/dir1, md/dir2'
file-path: './README.md, ./LICENSE'
shellcheck:
runs-on: [ubuntu-latest]
steps:
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ inputs:
description: 'Use this to specify the file extension of Markdown files.'
required: true
default: '.md'
file-path:
description: 'Specify additional files you want to check'
required: true
default: ''

runs:
using: 'docker'
Expand All @@ -53,3 +57,4 @@ runs:
- ${{ inputs.check-modified-files-only }}
- ${{ inputs.base-branch }}
- ${{ inputs.file-extension }}
- ${{ inputs.file-path }}
110 changes: 84 additions & 26 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ BLUE='\033[0;34m'
npm i -g markdown-link-check@3.8.1

declare -a FIND_CALL
declare -a COMMAND_DIRS COMMAND_FILES
declare -a COMMAND_FILES

USE_QUIET_MODE="$1"
USE_VERBOSE_MODE="$2"
Expand All @@ -23,13 +25,43 @@ if [ -z "$8" ]; then
else
FILE_EXTENSION="$8"
fi
FILE_PATH="$9"

FOLDERS=""
FILES=""

echo -e "${BLUE}USE_QUIET_MODE: $1${NC}"
echo -e "${BLUE}USE_VERBOSE_MODE: $2${NC}"
echo -e "${BLUE}FOLDER_PATH: $4${NC}"
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}"

handle_dirs () {
IFS=', ' read -r -a DIRLIST <<< "$FOLDER_PATH"

for index in "${!DIRLIST[@]}"
do
COMMAND_DIRS+=("${DIRLIST[index]}")
done
FOLDERS="${COMMAND_DIRS[*]}"
}

handle_files () {

IFS=', ' read -r -a FILELIST <<< "$FILE_PATH"

for index in "${!FILELIST[@]}"
do
if [ $index == 0 ]; then
COMMAND_FILES+=("-wholename ${FILELIST[index]}")
else
COMMAND_FILES+=("-o -wholename ${FILELIST[index]}")
fi
done
FILES="${COMMAND_FILES[*]}"
}

check_errors () {
if [ -e error.txt ] ; then
Expand All @@ -51,14 +83,7 @@ check_errors () {
fi
}

if [ "$CHECK_MODIFIED_FILES" = "yes" ]; then

echo -e "${BLUE}BASE_BRANCH: $7${NC}"

git fetch origin "${BASE_BRANCH}" --depth=1 > /dev/null
MASTER_HASH=$(git rev-parse origin/"${BASE_BRANCH}")

FIND_CALL=('markdown-link-check')
add_options () {

if [ -f "$CONFIG_FILE" ]; then
echo -e "${BLUE}Using markdown-link-check configuration file: ${YELLOW}$CONFIG_FILE${NC}"
Expand All @@ -77,6 +102,49 @@ if [ "$CHECK_MODIFIED_FILES" = "yes" ]; then
FIND_CALL+=('-v')
fi

}

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' '{}')
else
FIND_CALL=('find' '.' '-type' 'f' '(' ${FILES} ')' '-not' '-path' './node_modules/*' '-exec' 'markdown-link-check' '{}')
fi

add_options

FIND_CALL+=(';')

set -x
"${FIND_CALL[@]}" &>> error.txt
set +x

fi
}

if [ -z "$8" ]; then
FOLDERS="."
else
handle_dirs
fi

if [ -n "$9" ]; then
handle_files
fi

if [ "$CHECK_MODIFIED_FILES" = "yes" ]; then

echo -e "${BLUE}BASE_BRANCH: $7${NC}"

git fetch origin "${BASE_BRANCH}" --depth=1 > /dev/null
MASTER_HASH=$(git rev-parse origin/"${BASE_BRANCH}")

FIND_CALL=('markdown-link-check')

add_options

mapfile -t FILE_ARRAY < <( git diff --name-only "$MASTER_HASH" )

for i in "${FILE_ARRAY[@]}"
Expand All @@ -88,39 +156,29 @@ if [ "$CHECK_MODIFIED_FILES" = "yes" ]; then
unset 'FIND_CALL[${#FIND_CALL[@]}-1]'
fi
done

check_additional_files

check_errors

else

if [ "$5" -ne -1 ]; then
FIND_CALL=('find' "${FOLDER_PATH}" '-name' '*'"${FILE_EXTENSION}" '-not' '-path' './node_modules/*' '-maxdepth' "${MAX_DEPTH}" '-exec' 'markdown-link-check' '{}')
else
FIND_CALL=('find' "${FOLDER_PATH}" '-name' '*'"${FILE_EXTENSION}" '-not' '-path' './node_modules/*' '-exec' 'markdown-link-check' '{}')
fi

if [ -f "$CONFIG_FILE" ]; then
echo -e "${BLUE}Using markdown-link-check configuration file: ${YELLOW}$CONFIG_FILE${NC}"
FIND_CALL+=('--config' "${CONFIG_FILE}")
FIND_CALL=('find' ${FOLDERS} '-name' '*'"${FILE_EXTENSION}" '-not' '-path' './node_modules/*' '-maxdepth' "${MAX_DEPTH}" '-exec' 'markdown-link-check' '{}')
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_CALL=('find' ${FOLDERS} '-name' '*'"${FILE_EXTENSION}" '-not' '-path' './node_modules/*' '-exec' 'markdown-link-check' '{}')
fi

if [ "$USE_QUIET_MODE" = "yes" ]; then
FIND_CALL+=('-q')
fi

if [ "$USE_VERBOSE_MODE" = "yes" ]; then
FIND_CALL+=('-v')
fi
add_options

FIND_CALL+=(';')

set -x
"${FIND_CALL[@]}" &>> error.txt
set +x

check_additional_files

check_errors

fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions md/dir2/dir2level2/level-2a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

## Test internal and external links

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.

### 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](file1.md#bravo).
But [missing files are reported](missing-example.js).

[alpha]: #alpha
[charlie]: #charlie

External file: [Charlie](./file2.md/#charlie)
10 changes: 10 additions & 0 deletions md/dir2/dir2level2/level-2b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Checking more links

## Bravo

This [doesn't exists](#alpha).
This [one does](#bravo).

## Charlie

This is linked from file1.
25 changes: 25 additions & 0 deletions md/dir2/level-1a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

## Test internal and external links

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.

### 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](file1.md#bravo).
But [missing files are reported](missing-example.js).

[alpha]: #alpha
[charlie]: #charlie

External file: [Charlie](./file2.md/#charlie)
10 changes: 10 additions & 0 deletions md/dir2/level-1b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Checking more links

## Bravo

This [doesn't exists](#alpha).
This [one does](#bravo).

## Charlie

This is linked from file1.
25 changes: 25 additions & 0 deletions md/dir3/dir3level2/level-2a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

## Test internal and external links

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.

### 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](file1.md#bravo).
But [missing files are reported](missing-example.js).

[alpha]: #alpha
[charlie]: #charlie

External file: [Charlie](./file2.md/#charlie)
10 changes: 10 additions & 0 deletions md/dir3/dir3level2/level-2b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Checking more links

## Bravo

This [doesn't exists](#alpha).
This [one does](#bravo).

## Charlie

This is linked from file1.
25 changes: 25 additions & 0 deletions md/dir3/level-1a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

## Test internal and external links

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.

### 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](file1.md#bravo).
But [missing files are reported](missing-example.js).

[alpha]: #alpha
[charlie]: #charlie

External file: [Charlie](./file2.md/#charlie)
10 changes: 10 additions & 0 deletions md/dir3/level-1b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Checking more links

## Bravo

This [doesn't exists](#alpha).
This [one does](#bravo).

## Charlie

This is linked from file1.

0 comments on commit e5525bd

Please sign in to comment.