diff --git a/plugins/woocommerce/changelog/tests-manage-k6 b/plugins/woocommerce/changelog/tests-manage-k6 new file mode 100644 index 00000000000..f3ca2dde059 --- /dev/null +++ b/plugins/woocommerce/changelog/tests-manage-k6 @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Manage K6 version diff --git a/plugins/woocommerce/package.json b/plugins/woocommerce/package.json index 28129dc3d7d..a01cd250ffc 100644 --- a/plugins/woocommerce/package.json +++ b/plugins/woocommerce/package.json @@ -30,8 +30,7 @@ "env:start:blocks": "pnpm --filter='@woocommerce/block-library' env:start && pnpm playwright install chromium --with-deps", "env:stop": "pnpm wp-env stop", "env:test": "pnpm env:dev", - "env:perf:install-k6": "curl https://github.com/grafana/k6/releases/download/v0.33.0/k6-v0.33.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1", - "env:perf": "pnpm env:dev && pnpm env:performance-init && pnpm env:perf:install-k6", + "env:perf": "pnpm env:dev && pnpm env:performance-init", "preinstall": "npx only-allow pnpm", "postinstall": "XDEBUG_MODE=off composer install --quiet", "lint": "pnpm --if-present '/^lint:lang:.*$/'", @@ -57,8 +56,10 @@ "test:e2e:install": "pnpm playwright install chromium", "test:e2e:blocks": "pnpm --filter='@woocommerce/block-library' test:e2e", "test:e2e:with-env": "pnpm test:e2e:install && bash ./tests/e2e-pw/run-tests-with-env.sh", - "test:perf": "./k6 run ./tests/performance/tests/gh-action-pr-requests.js", "test:env:start": "pnpm env:test", + "test:perf": "./tests/performance/bin/k6 run ./tests/performance/tests/gh-action-pr-requests.js", + "test:perf:ci-setup": "pnpm test:perf:install-k6 && pnpm env:perf", + "test:perf:install-k6": "bash ./tests/performance/bin/install-k6.sh", "test:php": "./vendor/bin/phpunit -c ./phpunit.xml", "test:php:watch": "./vendor/bin/phpunit-watcher watch", "test:metrics": "USE_WP_ENV=1 pnpm playwright test --config=tests/metrics/playwright.config.js", @@ -474,22 +475,13 @@ "command": "test:perf", "optional": true, "changes": [ - "client/admin/config/*.json", - "composer.json", - "composer.lock", - "includes/**/*.php", - "patterns/**/*.php", - "src/**/*.php", - "templates/**/*.php", - "tests/performance/**", - ".wp-env.json", - "woocommerce.php", - "uninstall.php" + "tests/performance/**" ], "testEnv": { - "start": "env:perf" + "start": "test:perf:ci-setup" }, "events": [ + "pull_request", "push" ] }, diff --git a/plugins/woocommerce/tests/performance/.gitignore b/plugins/woocommerce/tests/performance/.gitignore new file mode 100644 index 00000000000..f1907178cf7 --- /dev/null +++ b/plugins/woocommerce/tests/performance/.gitignore @@ -0,0 +1,3 @@ +k6 +k6-*.tar.gz +k6-*.zip diff --git a/plugins/woocommerce/tests/performance/bin/install-k6.sh b/plugins/woocommerce/tests/performance/bin/install-k6.sh new file mode 100755 index 00000000000..60942993e49 --- /dev/null +++ b/plugins/woocommerce/tests/performance/bin/install-k6.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -eo pipefail + +K6_VERSION="0.53.0" +DOWNLOAD_URL="https://github.com/grafana/k6/releases/download/v$K6_VERSION" +SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" || return; pwd -P) + +download_archive() { + local archive=$1 + local download_url="$DOWNLOAD_URL/$archive" + local download_path="$SCRIPT_PATH/$archive" + + echo "Downloading from $download_url to $download_path" + curl "$download_url" -L -o "$download_path" +} + +arch=$(uname -m) + +if [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then + arch="amd64" + elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then + arch="arm64" + else + echo "Unsupported CPU architecture: $arch. Please check K6 docs and install the right version for your system." + exit 1 +fi + +if [ "$(uname)" == "Darwin" ]; then + archive="k6-v$K6_VERSION-macos-$arch.zip" + download_archive "$archive" + unzip -j -o "$SCRIPT_PATH/$archive" -d "$SCRIPT_PATH" +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + archive="k6-v$K6_VERSION-linux-$arch.tar.gz" + download_archive "$archive" + tar --strip-components=1 -xzf "$SCRIPT_PATH/$archive" -C "$SCRIPT_PATH" +else + echo "Unsupported operating system. Please check K6 docs and install the right version for your system." + exit 1 +fi + +"$SCRIPT_PATH/k6" version