From fa527e288ff86e41f48b44d731d81aee27f93f01 Mon Sep 17 00:00:00 2001 From: Mikhail Golbakh Date: Tue, 26 Dec 2023 14:34:13 +0300 Subject: [PATCH] chore: improve playwright:docker commands --- package.json | 5 +++-- scripts/playwright-docker.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100755 scripts/playwright-docker.sh diff --git a/package.json b/package.json index bd58240697..1f47161a44 100644 --- a/package.json +++ b/package.json @@ -76,8 +76,9 @@ "playwright:install": "playwright install --with-deps", "playwright": "playwright test --config=playwright/playwright.config.ts", "playwright:update": "npm run playwright -- -u", - "playwright:docker": "docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright'", - "playwright:docker:update": " docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright:update'" + "playwright:docker": "./scripts/playwright-docker.sh 'npm run playwright'", + "playwright:docker:update": "./scripts/playwright-docker.sh 'npm run playwright:update'", + "playwright:docker:clear-cache": "./scripts/playwright-docker.sh clear-cache" }, "dependencies": { "@bem-react/classname": "^1.6.0", diff --git a/scripts/playwright-docker.sh b/scripts/playwright-docker.sh new file mode 100755 index 0000000000..d7fd7df22c --- /dev/null +++ b/scripts/playwright-docker.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euo pipefail + +IMAGE_NAME="mcr.microsoft.com/playwright" +IMAGE_TAG="v1.38.1-jammy" # This version have to be synchronized with playwright version from package.json + +NODE_MODULES_CACHE_DIR="$HOME/.cache/uikit-playwright-docker-node-modules" + +run_command() { + docker run --rm --network host -it -w /work \ + -v $(pwd):/work \ + -v "$NODE_MODULES_CACHE_DIR:/work/node_modules" \ + "$IMAGE_NAME:$IMAGE_TAG" \ + /bin/bash -c "$1" +} + +if [[ "$1" = "clear-cache" ]]; then + rm -rf "$NODE_MODULES_CACHE_DIR" + exit 0 +fi + +if [[ ! -d "$NODE_MODULES_CACHE_DIR" ]]; then + run_command 'npm ci' +fi + +run_command "$1"