mirror of https://github.com/docker/docs.git
test: fix broken unused-media test
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
parent
c7511a228f
commit
28ecf7b67d
|
@ -110,10 +110,7 @@ RUN htmltest
|
|||
FROM alpine:${ALPINE_VERSION} AS unused-media
|
||||
RUN apk add --no-cache fd ripgrep
|
||||
WORKDIR /test
|
||||
RUN --mount=type=bind,target=. <<"EOT"
|
||||
set -ex
|
||||
./hack/test/unused_media
|
||||
EOT
|
||||
RUN --mount=type=bind,target=. ./hack/test/unused_media
|
||||
|
||||
# path-warnings checks for duplicate target paths
|
||||
FROM build-base AS path-warnings
|
||||
|
|
|
@ -1,23 +1,33 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Find all media files {svg,png,webp,mp4,jpg,jpeg} in {content,static}
|
||||
MEDIA=$(fd . -e "svg" -e "png" -e "webp" -e "mp4" -e "jpg" -e "jpeg" ./content ./static)
|
||||
TEMPFILE=$(mktemp)
|
||||
echo "checking for unused media files..."
|
||||
FORMATS="svg png webp mp4 jpg jpeg"
|
||||
DIRECTORIES="content static"
|
||||
|
||||
FORMAT_FLAGS=""
|
||||
for format in $FORMATS; do
|
||||
FORMAT_FLAGS="$FORMAT_FLAGS -e $format"
|
||||
done
|
||||
|
||||
echo "Searching for media with formats: $FORMATS"
|
||||
echo "Searching in directories: $DIRECTORIES"
|
||||
|
||||
MEDIA=$(fd . $FORMAT_FLAGS $DIRECTORIES)
|
||||
|
||||
UNUSED_COUNT=0
|
||||
|
||||
for file in $MEDIA; do
|
||||
rg -q "$(basename $file)"
|
||||
rg -q "$(basename $file)" .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$file" >> "$TEMPFILE"
|
||||
echo "$file"
|
||||
UNUSED_COUNT=$((UNUSED_COUNT + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
UNUSED_FILES=$(< $TEMPFILE)
|
||||
rm $TEMPFILE
|
||||
|
||||
if [ -z "$UNUSED_FILES" ]; then
|
||||
if [ $UNUSED_COUNT -eq 0 ]; then
|
||||
echo "No unused media files."
|
||||
exit 0
|
||||
else
|
||||
echo "$(echo "$UNUSED_FILES" | wc -l) unused media files. Please remove them."
|
||||
printf "%s\n" ${UNUSED_FILES[@]}
|
||||
echo "$UNUSED_COUNT unused media files found. Please remove them."
|
||||
exit 1
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue