Skip to content

Commit

Permalink
Add a "link checker"
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Jan 7, 2016
1 parent 30af6f9 commit 8dd94e6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -25,7 +25,7 @@ define mkTags
@find . -name \*.\*hs | xargs fast-tags
endef

.PHONY: all install test sdist clean docs gold stamp hlint tags
.PHONY: all install test sdist clean docs gold stamp hlint tags checkLinks

all: install

Expand Down Expand Up @@ -65,7 +65,7 @@ clean:
docs:
@(set -o pipefail; $(CABAL) haddock --haddock-option=--no-warnings --hyperlink-source 2>&1 | $(SIMPLIFY))

release: clean install sdist hlint docs test
release: clean install sdist hlint docs test checkLinks
@echo "*** SBV is ready for release!"

# use this as follows: make gold TGTS="cgUSB5"
Expand All @@ -79,5 +79,8 @@ hlint:
@echo "Running HLint.."
@hlint Data SBVUnitTest -q -rhlintReport.html -i "Use otherwise" -i "Parse error" -i "Use fewer imports"

checkLinks:
@buildUtils/checkLinks

tags:
$(call mkTags)
46 changes: 46 additions & 0 deletions buildUtils/checkLinks
@@ -0,0 +1,46 @@
#! /bin/zsh

badLinkCount=0

clearLine () {
blank=" "
echo -n "\r" $blank
}

check () {
clearLine
echo -n "\rChecking:" "$3"
/usr/local/bin/wget -q --spider --tries=1 --timeout=5 "$3"
ans=$?
if [ ! $ans -eq 0 ]; then
clearLine
echo "\rBAD: $1:$2 $3"
badLinkCount=$(( $badLinkCount+1 ))
return $ans
else
echo -n ". GOOD"
return $ans
fi
}

lines=("${(f)$(grep -Eoin '(http|https)://[^>]+' **/*.hs **/*.md)}")

for i in $lines; do
sep=$(echo $i | awk -F: '{printf("%s %s %s:", $1, $2, $3); for (i = 4; i <= NF; ++i) printf ("%s", $i)}')
args=(${=sep})
check $args[1] $args[2] $args[3]
final=$?
done

if [ $final -eq 0 ]; then
clearLine
echo -n "\r"
fi

if [ $badLinkCount -eq 0 ]; then
echo "All links are good."
exit 0
else
echo "Found $badLinkCount bad links!"
exit 1
fi

0 comments on commit 8dd94e6

Please sign in to comment.