Skip to content

Commit 28ecf7b

Browse files
committed
test: fix broken unused-media test
Signed-off-by: David Karlsson <[email protected]>
1 parent c7511a2 commit 28ecf7b

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ RUN htmltest
110110
FROM alpine:${ALPINE_VERSION} AS unused-media
111111
RUN apk add --no-cache fd ripgrep
112112
WORKDIR /test
113-
RUN --mount=type=bind,target=. <<"EOT"
114-
set -ex
115-
./hack/test/unused_media
116-
EOT
113+
RUN --mount=type=bind,target=. ./hack/test/unused_media
117114

118115
# path-warnings checks for duplicate target paths
119116
FROM build-base AS path-warnings

hack/test/unused_media

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
#!/usr/bin/env sh
22

3-
# Find all media files {svg,png,webp,mp4,jpg,jpeg} in {content,static}
4-
MEDIA=$(fd . -e "svg" -e "png" -e "webp" -e "mp4" -e "jpg" -e "jpeg" ./content ./static)
5-
TEMPFILE=$(mktemp)
3+
echo "checking for unused media files..."
4+
FORMATS="svg png webp mp4 jpg jpeg"
5+
DIRECTORIES="content static"
6+
7+
FORMAT_FLAGS=""
8+
for format in $FORMATS; do
9+
FORMAT_FLAGS="$FORMAT_FLAGS -e $format"
10+
done
11+
12+
echo "Searching for media with formats: $FORMATS"
13+
echo "Searching in directories: $DIRECTORIES"
14+
15+
MEDIA=$(fd . $FORMAT_FLAGS $DIRECTORIES)
16+
17+
UNUSED_COUNT=0
618

719
for file in $MEDIA; do
8-
rg -q "$(basename $file)"
20+
rg -q "$(basename $file)" .
921
if [ $? -ne 0 ]; then
10-
echo "$file" >> "$TEMPFILE"
22+
echo "$file"
23+
UNUSED_COUNT=$((UNUSED_COUNT + 1))
1124
fi
1225
done
1326

14-
UNUSED_FILES=$(< $TEMPFILE)
15-
rm $TEMPFILE
16-
17-
if [ -z "$UNUSED_FILES" ]; then
27+
if [ $UNUSED_COUNT -eq 0 ]; then
28+
echo "No unused media files."
1829
exit 0
1930
else
20-
echo "$(echo "$UNUSED_FILES" | wc -l) unused media files. Please remove them."
21-
printf "%s\n" ${UNUSED_FILES[@]}
31+
echo "$UNUSED_COUNT unused media files found. Please remove them."
2232
exit 1
2333
fi

0 commit comments

Comments
 (0)