-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathentrypoint.sh
executable file
·77 lines (53 loc) · 1.96 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
set -Eeuo pipefail
# Config file for markdown-link-check
export CONFIG_FILE=${INPUT_CONFIG_FILE:-}
# Debug variable - enable by setting non-empty value
export DEBUG=${INPUT_DEBUG:-}
# Exclude files or directories which should not be checked
export EXCLUDE=${INPUT_EXCLUDE:-}
# Command line parameters for fd ("exclude" and "search_paths" parameters are ignored if this is set)
export FD_CMD_PARAMS="${INPUT_FD_CMD_PARAMS:- . -0 --extension md --type f --hidden --no-ignore}"
# Debug variable - enable by setting non-empty value
export QUIET=${INPUT_QUIET:-}
# Files or paths which will be checked
export SEARCH_PATHS=${INPUT_SEARCH_PATHS:-}
# Debug variable - enable by setting non-empty value
export VERBOSE=${INPUT_VERBOSE:-}
print_error() {
echo -e "\e[31m*** ERROR: ${1}\e[m"
}
print_info() {
echo -e "\e[36m*** ${1}\e[m"
}
error_trap() {
print_error "Something went wrong - see the errors above..."
exit 1
}
################
# Main
################
trap error_trap ERR
[ -n "${DEBUG}" ] && set -x
declare -a MARKDOWN_LINK_CHECK_CMD_PARAMS
if [ -n "${CONFIG_FILE}" ]; then
MARKDOWN_LINK_CHECK_CMD_PARAMS+=("--config" "${CONFIG_FILE}")
elif [ -s .mlc_config.json ]; then
MARKDOWN_LINK_CHECK_CMD_PARAMS+=("--config" ".mlc_config.json")
fi
if [ -n "${QUIET}" ]; then
MARKDOWN_LINK_CHECK_CMD_PARAMS+=("--quiet")
fi
if [ -n "${VERBOSE}" ] || [ -n "${DEBUG}" ]; then
MARKDOWN_LINK_CHECK_CMD_PARAMS+=("--verbose")
fi
print_info "Start checking..."
if [ -n "${EXCLUDE}" ]; then
print_info "Files/dirs which will be excluded:\n${EXCLUDE}"
fi
echo "${EXCLUDE}" > /tmp/fd_exclude_file
# shellcheck disable=SC2086
mapfile -d '' MARKDOWN_FILE_ARRAY < <(fd ${FD_CMD_PARAMS} --ignore-file /tmp/fd_exclude_file ${SEARCH_PATHS})
print_info "Running: markdown-link-check ${MARKDOWN_LINK_CHECK_CMD_PARAMS[*]} ${MARKDOWN_FILE_ARRAY[*]}"
markdown-link-check "${MARKDOWN_LINK_CHECK_CMD_PARAMS[@]}" "${MARKDOWN_FILE_ARRAY[@]}"
print_info "Checks completed..."