From 75778c72e163849d03a598bb34ee168e65a159cb Mon Sep 17 00:00:00 2001 From: Mikhail Golbakh Date: Tue, 26 Dec 2023 15:50:47 +0300 Subject: [PATCH] chore: improve playwright:docker commands (#1225) --- package.json | 5 +++-- playwright/README.md | 1 + scripts/playwright-docker.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 scripts/playwright-docker.sh diff --git a/package.json b/package.json index a7ea21c9e6..16b5082f20 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/playwright/README.md b/playwright/README.md index 92ff78b6c3..6e76a76854 100644 --- a/playwright/README.md +++ b/playwright/README.md @@ -120,3 +120,4 @@ - `npm run playwright:update` - update screenshots - `npm run playwright:docker` - run tests using docker - `npm run playwright:docker:update` - update screenshots using docker +- `npm run playwright:docker:clear-cache` - clear node_modules cache for docker container 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"