mirror of https://github.com/docker/docs.git
test: add check for validating go-redirects
Test ensures that: - Go redirects are unique (this is actually enforced by YAML already because it requires keys to be unique, but just in case someone 'echo >>'es into the file or whatever - Go redirects always resolve to an index.html in the public output dir Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
parent
da4ccc81e6
commit
f58694d9d1
|
@ -53,6 +53,7 @@ jobs:
|
||||||
- lint
|
- lint
|
||||||
- test
|
- test
|
||||||
- unused-media
|
- unused-media
|
||||||
|
- test-go-redirects
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
|
|
|
@ -95,3 +95,12 @@ COPY --from=pagefind /pagefind .
|
||||||
FROM scratch AS release
|
FROM scratch AS release
|
||||||
COPY --from=build /out /
|
COPY --from=build /out /
|
||||||
COPY --from=pagefind /pagefind /pagefind
|
COPY --from=pagefind /pagefind /pagefind
|
||||||
|
|
||||||
|
FROM alpine:${ALPINE_VERSION} AS test-go-redirects
|
||||||
|
WORKDIR /work
|
||||||
|
RUN apk add yq
|
||||||
|
COPY --from=build /out ./public
|
||||||
|
RUN --mount=type=bind,target=. <<"EOT"
|
||||||
|
set -ex
|
||||||
|
./scripts/test_go_redirects.sh
|
||||||
|
EOT
|
||||||
|
|
|
@ -33,7 +33,7 @@ target "release" {
|
||||||
}
|
}
|
||||||
|
|
||||||
group "validate" {
|
group "validate" {
|
||||||
targets = ["lint", "test", "unused-media"]
|
targets = ["lint", "test", "unused-media", "test-go-redirects"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "test" {
|
target "test" {
|
||||||
|
@ -51,6 +51,11 @@ target "unused-media" {
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target "test-go-redirects" {
|
||||||
|
target = "test-go-redirects"
|
||||||
|
output = ["type=cacheonly"]
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# releaser targets are defined in _releaser/Dockerfile
|
# releaser targets are defined in _releaser/Dockerfile
|
||||||
# and are used for Netlify and AWS S3 deployment
|
# and are used for Netlify and AWS S3 deployment
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
echo "Testing redirects in data/redirects.yml..."
|
||||||
|
|
||||||
|
# Get all redirects from data/redirects.yml
|
||||||
|
REDIRECTS=$(yq eval 'keys | .[]' data/redirects.yml)
|
||||||
|
LOCAL_REDIRECTS=$(echo $REDIRECTS | awk 'BEGIN { RS = " " } /^\// { print $1 }')
|
||||||
|
|
||||||
|
echo "Checking for duplicate redirects..."
|
||||||
|
DUPLICATES=$(echo $LOCAL_REDIRECTS | tr ' ' '\n' | sort | uniq -d)
|
||||||
|
if [ -n "$DUPLICATES" ]; then
|
||||||
|
echo "Duplicate redirects found:"
|
||||||
|
echo $DUPLICATES
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Checking for redirects to nonexistent paths..."
|
||||||
|
for file in $(echo REDIRECTS | awk 'BEGIN { RS = " " } /^\// { print $1 }'); do
|
||||||
|
if [ ! -e "./public/${file%/*}/index.html" ]; then
|
||||||
|
echo "Redirect to nonexistent path: $file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "All redirects are valid."
|
Loading…
Reference in New Issue