Skip to content
Snippets Groups Projects
Commit e3c87073 authored by Jan Frenzel's avatar Jan Frenzel
Browse files

Added more options in check-links.sh and the config file

link-check-config.json. This closes #183.
parent e9dfacd5
No related branches found
No related tags found
3 merge requests!446docs: Add Jupyter Teaching Example,!434Automated merge from preview to main,!432Add exception to link checker
...@@ -8,57 +8,96 @@ ...@@ -8,57 +8,96 @@
## ##
## Author: Martin.Schroschk@tu-dresden.de ## Author: Martin.Schroschk@tu-dresden.de
set -euo pipefail set -eo pipefail
scriptpath=${BASH_SOURCE[0]}
basedir=`dirname "$scriptpath"`
basedir=`dirname "$basedir"`
usage() { usage() {
echo "Usage: bash $0" cat <<-EOF
usage: $0 [file | -a]
If file is given, checks whether all links in it are reachable.
If parameter -a (or --all) is given instead of the file, checks all markdown files.
Otherwise, checks whether any changed file contains broken links.
EOF
} }
# Any arguments?
if [ $# -gt 0 ]; then
usage
exit 1
fi
mlc=markdown-link-check mlc=markdown-link-check
if ! command -v $mlc &> /dev/null; then if ! command -v $mlc &> /dev/null; then
echo "INFO: $mlc not found in PATH (global module)" echo "INFO: $mlc not found in PATH (global module)"
mlc=./node_modules/markdown-link-check/$mlc mlc=./node_modules/markdown-link-check/$mlc
if ! command -v $mlc &> /dev/null; then if ! command -v $mlc &> /dev/null; then
echo "INFO: $mlc not found (local module)" echo "INFO: $mlc not found (local module)"
echo "INFO: See CONTRIBUTE.md for information."
echo "INFO: Abort."
exit 1 exit 1
fi fi
fi fi
echo "mlc: $mlc" echo "mlc: $mlc"
LINK_CHECK_CONFIG="$basedir/util/link-check-config.json"
if [ ! -f "$LINK_CHECK_CONFIG" ]; then
echo $LINK_CHECK_CONFIG does not exist
exit 1
fi
branch="preview" branch="preview"
if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then
branch="origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" branch="origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
fi fi
any_fails=false function checkSingleFile(){
theFile="$1"
if [ -e "$theFile" ]; then
echo "Checking links in $theFile"
if ! $mlc -q -c "$LINK_CHECK_CONFIG" -p "$theFile"; then
return 1
fi
fi
return 0
}
files=$(git diff --name-only "$(git merge-base HEAD "$branch")") function checkFiles(){
any_fails=false
echo "Check files:" echo "Check files:"
echo "$files" echo "$files"
echo "" echo ""
for f in $files; do for f in $files; do
if [ "${f: -3}" == ".md" ]; then if checkSingleFile "$f"; then
# do not check links for deleted files any_fails=true
if [ "$f" != "doc.zih.tu-dresden.de/README.md" ]; then
if [ -e $f ]; then
echo "Checking links for $f"
if ! $mlc -q -p "$f"; then
any_fails=true
fi
fi
fi
fi fi
done done
if [ "$any_fails" == true ]; then if [ "$any_fails" == true ]; then
exit 1 exit 1
fi fi
}
function checkAllFiles(){
files=$(git ls-tree --full-tree -r --name-only HEAD $basedir/ | grep '.md$' || true)
checkFiles
}
function checkChangedFiles(){
files=$(git diff --name-only "$(git merge-base HEAD "$branch")" | grep '.md$' || true)
checkFiles
}
if [ $# -eq 1 ]; then
case $1 in
help | -help | --help)
usage
exit
;;
-a | --all)
checkAllFiles
;;
*)
checkSingleFile "$1"
;;
esac
elif [ $# -eq 0 ]; then
checkChangedFiles
else
usage
fi
{
"ignorePatterns": [
{
"pattern": "^https://gitlab.hrz.tu-chemnitz.de/zih/hpcsupport/hpc-compendium/-/merge_requests/new$"
}
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment