mirror of
https://github.com/gaurav-nelson/github-action-markdown-link-check.git
synced 2024-11-29 09:12:26 +03:00
Find more files
This commit is contained in:
parent
02e1702486
commit
4a2489a1fc
3
.github/workflows/push.yml
vendored
3
.github/workflows/push.yml
vendored
@ -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, ./md/file4.markdown'
|
||||
shellcheck:
|
||||
runs-on: [ubuntu-latest]
|
||||
steps:
|
||||
|
20
README.md
20
README.md
@ -35,11 +35,12 @@ You customize the action by using the following variables:
|
||||
|`use-quiet-mode`| Specify `yes` to only show errors in output.| `no`|
|
||||
|`use-verbose-mode`|Specify `yes` to show detailed HTTP status for checked links. |`no` |
|
||||
|`config-file`|Specify a [custom configuration file](https://github.com/tcort/markdown-link-check#config-file-format) for markdown-link-check. You can use it to remove false-positives by specifying replacement patterns and ignore patterns.|`mlc_config.json`|
|
||||
|`folder-path` |By default the `github-action-markdown-link-check` action checks for all markdown files in your repository. Use this option to limit checks to only specific folders. |`.` |
|
||||
|`folder-path` |By default the `github-action-markdown-link-check` action checks for all markdown files in your repository. Use this option to limit checks to only specific folders. Use comma separated values for checking multiple folders. |`.` |
|
||||
|`max-depth` |Specify how many levels deep you want to check in the directory structure. The default value is `-1` which means check all levels.|`-1` |
|
||||
|`check-modified-files-only` |Use this variable to only check modified markdown files instead of checking all markdown files. The action uses `git` to find modified markdown files. Only use this variable when you run the action to check pull requests.|`no`|
|
||||
|`base-branch`|Use this variable to specify the branch to compare when finding modified markdown files. |`master`|
|
||||
|`file-extension`|By default the `github-action-markdown-link-check` action checks files in your repository with the `.md` extension. Use this option to specify a different file extension such as `.markdown` or `.mdx`.|`.md`|
|
||||
|`file-path` | Specify additional files (with complete path and extension) you want to check. Use comma separated values for checking multiple files. | - |
|
||||
|
||||
#### Sample workflow with variables
|
||||
|
||||
@ -142,6 +143,23 @@ jobs:
|
||||
|
||||
```
|
||||
|
||||
### Check multiple directories and files
|
||||
|
||||
```yml
|
||||
on: [pull_request]
|
||||
name: Check links for modified files
|
||||
jobs:
|
||||
markdown-link-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: gaurav-nelson/github-action-markdown-link-check@v1
|
||||
with:
|
||||
use-quiet-mode: 'yes'
|
||||
folder-path: 'md/dir1, md/dir2'
|
||||
file-path: './README.md, ./LICENSE, ./md/file4.markdown'
|
||||
```
|
||||
|
||||
## Versioning
|
||||
GitHub Action - Markdown link check follows the [GitHub recommended versioning strategy](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md).
|
||||
|
||||
|
@ -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'
|
||||
@ -53,3 +57,4 @@ runs:
|
||||
- ${{ inputs.check-modified-files-only }}
|
||||
- ${{ inputs.base-branch }}
|
||||
- ${{ inputs.file-extension }}
|
||||
- ${{ inputs.file-path }}
|
||||
|
165
entrypoint.sh
165
entrypoint.sh
@ -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"
|
||||
@ -23,6 +25,18 @@ if [ -z "$8" ]; then
|
||||
else
|
||||
FILE_EXTENSION="$8"
|
||||
fi
|
||||
FILE_PATH="$9"
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo -e "${BLUE}Using markdown-link-check configuration file: ${YELLOW}$CONFIG_FILE${NC}"
|
||||
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}"
|
||||
fi
|
||||
|
||||
FOLDERS=""
|
||||
FILES=""
|
||||
|
||||
echo -e "${BLUE}USE_QUIET_MODE: $1${NC}"
|
||||
echo -e "${BLUE}USE_VERBOSE_MODE: $2${NC}"
|
||||
@ -30,27 +44,105 @@ 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
|
||||
if grep -q "ERROR:" error.txt; then
|
||||
echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}"
|
||||
cat error.txt
|
||||
printf "\n"
|
||||
echo -e "${YELLOW}=========================================================================${NC}"
|
||||
exit 113
|
||||
|
||||
if [ -e error.txt ] ; then
|
||||
if grep -q "ERROR:" error.txt; then
|
||||
echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}"
|
||||
cat error.txt
|
||||
printf "\n"
|
||||
echo -e "${YELLOW}=========================================================================${NC}"
|
||||
exit 113
|
||||
else
|
||||
echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}"
|
||||
printf "\n"
|
||||
echo -e "${GREEN}[✔] All links are good!${NC}"
|
||||
printf "\n"
|
||||
echo -e "${YELLOW}=========================================================================${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK <=========================${NC}"
|
||||
printf "\n"
|
||||
echo -e "${GREEN}[✔] All links are good!${NC}"
|
||||
printf "\n"
|
||||
echo -e "${YELLOW}=========================================================================${NC}"
|
||||
echo -e "${GREEN}All good!${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${GREEN}All good!${NC}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
add_options () {
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
FIND_CALL+=('--config' "${CONFIG_FILE}")
|
||||
fi
|
||||
|
||||
if [ "$USE_QUIET_MODE" = "yes" ]; then
|
||||
FIND_CALL+=('-q')
|
||||
fi
|
||||
|
||||
if [ "$USE_VERBOSE_MODE" = "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}"
|
||||
@ -60,22 +152,7 @@ if [ "$CHECK_MODIFIED_FILES" = "yes" ]; then
|
||||
|
||||
FIND_CALL=('markdown-link-check')
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo -e "${BLUE}Using markdown-link-check configuration file: ${YELLOW}$CONFIG_FILE${NC}"
|
||||
FIND_CALL+=('--config' "${CONFIG_FILE}")
|
||||
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}"
|
||||
fi
|
||||
|
||||
if [ "$USE_QUIET_MODE" = "yes" ]; then
|
||||
FIND_CALL+=('-q')
|
||||
fi
|
||||
|
||||
if [ "$USE_VERBOSE_MODE" = "yes" ]; then
|
||||
FIND_CALL+=('-v')
|
||||
fi
|
||||
add_options
|
||||
|
||||
mapfile -t FILE_ARRAY < <( git diff --name-only "$MASTER_HASH" )
|
||||
|
||||
@ -88,39 +165,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' '{}')
|
||||
FIND_CALL=('find' ${FOLDERS} '-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' '{}')
|
||||
FIND_CALL=('find' ${FOLDERS} '-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}")
|
||||
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}"
|
||||
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
|
||||
|
25
md/dir2/dir2level2/level-2a.md
Normal file
25
md/dir2/dir2level2/level-2a.md
Normal file
@ -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
md/dir2/dir2level2/level-2b.md
Normal file
10
md/dir2/dir2level2/level-2b.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Checking more links
|
||||
|
||||
## Bravo
|
||||
|
||||
This [doesn't exists](#alpha).
|
||||
This [one does](#bravo).
|
||||
|
||||
## Charlie
|
||||
|
||||
This is linked from file1.
|
25
md/dir2/level-1a.md
Normal file
25
md/dir2/level-1a.md
Normal file
@ -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
md/dir2/level-1b.md
Normal file
10
md/dir2/level-1b.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Checking more links
|
||||
|
||||
## Bravo
|
||||
|
||||
This [doesn't exists](#alpha).
|
||||
This [one does](#bravo).
|
||||
|
||||
## Charlie
|
||||
|
||||
This is linked from file1.
|
25
md/dir3/dir3level2/level-2a.md
Normal file
25
md/dir3/dir3level2/level-2a.md
Normal file
@ -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
md/dir3/dir3level2/level-2b.md
Normal file
10
md/dir3/dir3level2/level-2b.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Checking more links
|
||||
|
||||
## Bravo
|
||||
|
||||
This [doesn't exists](#alpha).
|
||||
This [one does](#bravo).
|
||||
|
||||
## Charlie
|
||||
|
||||
This is linked from file1.
|
25
md/dir3/level-1a.md
Normal file
25
md/dir3/level-1a.md
Normal file
@ -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
md/dir3/level-1b.md
Normal file
10
md/dir3/level-1b.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Checking more links
|
||||
|
||||
## Bravo
|
||||
|
||||
This [doesn't exists](#alpha).
|
||||
This [one does](#bravo).
|
||||
|
||||
## Charlie
|
||||
|
||||
This is linked from file1.
|
Loading…
Reference in New Issue
Block a user