Validate HTML and CSS in Travis

This commit is contained in:
Pierre Ossman 2019-03-26 09:42:22 +01:00
parent f5d76dd5bb
commit a98a223e13
2 changed files with 50 additions and 0 deletions

View File

@ -36,6 +36,11 @@ jobs:
addons:
before_script:
script: npm run lint
-
env:
addons:
before_script:
script: git ls-tree --name-only -r HEAD | grep -E "[.](html|css)$" | xargs ./utils/validate
- stage: deploy
env:
addons:

45
utils/validate Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
set -e
RET=0
OUT=`mktemp`
for fn in "$@"; do
echo "Validating $fn..."
echo
case $fn in
*.html)
type="text/html"
;;
*.css)
type="text/css"
;;
*)
echo "Unknown format!"
echo
RET=1
continue
;;
esac
curl --silent \
--header "Content-Type: ${type}; charset=utf-8" \
--data-binary @${fn} \
https://validator.w3.org/nu/?out=text > $OUT
cat $OUT
echo
# We don't fail the check for warnings as some warnings are
# not relevant for us, and we don't currently have a way to
# ignore just those
if grep -q -s -E "^Error:" $OUT; then
RET=1
fi
done
rm $OUT
exit $RET