From 4df86c4d3fc3027bd28e09ad918fc7ea5213c93d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 18 Jul 2025 15:18:37 +0100 Subject: [PATCH] Add options to use playwright screenshot script for other things In this case, storybook screenshots, but this keeps it so this script doesnt know about storybook itself (we can move the actual storybook specific code to here if we standardise on it more). --- .../playwright-screenshots.sh | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/packages/element-web-playwright-common/playwright-screenshots.sh b/packages/element-web-playwright-common/playwright-screenshots.sh index a212fc9a94..b75bdc5325 100755 --- a/packages/element-web-playwright-common/playwright-screenshots.sh +++ b/packages/element-web-playwright-common/playwright-screenshots.sh @@ -1,25 +1,29 @@ #!/bin/bash +set -x # Handle symlinks here as we tend to be executed as an npm binary SCRIPT_PATH=$(readlink -f "$0") SCRIPT_DIR=$(dirname "$SCRIPT_PATH") IMAGE_NAME="element-web-playwright-common" -echo "Building $IMAGE_NAME image in $SCRIPT_DIR" -# Build image -PW_VERSION=$( - yarn list \ - --pattern @playwright/test \ - --depth=0 \ - --json \ - --non-interactive \ - --no-progress | \ - jq -r '.data.trees[].name | split("@")[2]' \ - ) -echo "with Playwright version $PW_VERSION" +build_image() { + echo "Building $IMAGE_NAME image in $SCRIPT_DIR" -docker build -t "$IMAGE_NAME" --build-arg "PLAYWRIGHT_VERSION=$PW_VERSION" "$SCRIPT_DIR" + # Build image + PW_VERSION=$( + yarn list \ + --pattern @playwright/test \ + --depth=0 \ + --json \ + --non-interactive \ + --no-progress | \ + jq -r '.data.trees[].name | split("@")[2]' \ + ) + echo "with Playwright version $PW_VERSION" + + docker build -t "$IMAGE_NAME" --build-arg "PLAYWRIGHT_VERSION=$PW_VERSION" "$SCRIPT_DIR" +} RUN_ARGS=( --rm @@ -36,6 +40,35 @@ RUN_ARGS=( -it ) +DEFAULT_ARGS=(--grep @screenshot) + +# Some arguments to customise behaviour so the same script / image can be +# re-used for other screenshot generation. +while [[ $# -gt 0 ]]; do + case "$1" in + # Mounts a separate node_modules directory from a docker volume in the container. + # Must be used if executing something that requires native node modules + # It's a volume rather than a directory because otherwise things tend to start picking up + # files from it in the native environment and break. + --with-node-modules) + RUN_ARGS+=(--mount "type=volume,src=ew-docker-node-modules,dst=/work/node_modules,volume-nocopy") + shift + ;; + # Sets a different entrypoint (in which case the default arguments to the script will be ignored) + --entrypoint) + shift + RUN_ARGS+=(--entrypoint "$1") + DEFAULT_ARGS=() + shift + ;; + *) + break + ;; + esac +done + +build_image + # Ensure we pass all symlinked node_modules to the container pushd node_modules || exit > /dev/null SYMLINKS=$(find . -maxdepth 2 -type l -not -path "./.bin/*") @@ -48,6 +81,4 @@ for LINK in $SYMLINKS; do fi done -DEFAULT_ARGS=(--grep @screenshot) - -docker run "${RUN_ARGS[@]}" "$IMAGE_NAME" "${DEFAULT_ARGS[@]}" "$@" \ No newline at end of file +docker run "${RUN_ARGS[@]}" "$IMAGE_NAME" "${DEFAULT_ARGS[@]}" "$@"