diff --git a/changelog.md b/changelog.md index c70da38..1a3053a 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [1.7.1] - 2024-08-30 +* Fixed - Run the `playwright install` command as root, allow running Playwright tests as the `slic` user. +* Change - The `playwright install` command will now install only the Chromium browser and its dependencies. + # [1.7.0] - 2024-06-06 * Fixed - Properly read changes and restart stack after using the `slic php-version set` command. * Added - PHP 8.3 docker images. diff --git a/slic-stack.yml b/slic-stack.yml index edeb249..191486c 100644 --- a/slic-stack.yml +++ b/slic-stack.yml @@ -180,6 +180,8 @@ services: COLUMNS: "${COLUMNS:-80}" # Explicitly set the env var that will define the Function Mocker cache path: it will be picked up by the config file. FUNCTION_MOCKER_CACHE_PATH: "/cache" + # Explicitly set the path to the Playwright browsers cache to make sure it will be the same for all users. + PLAYWRIGHT_BROWSERS_PATH: "/home/slic/.cache/ms-playwright" volumes: # Paths are relative to the directory that contains this file, NOT the current working directory. # Share the WordPress core installation files in the `_wordpress` directory. diff --git a/slic.php b/slic.php index 27ed35d..69829a6 100644 --- a/slic.php +++ b/slic.php @@ -34,7 +34,7 @@ ] ); $cli_name = 'slic'; -const CLI_VERSION = '1.7.0'; +const CLI_VERSION = '1.7.1'; // If the run-time option `-q`, for "quiet", is specified, then do not print the header. if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) { diff --git a/src/commands/playwright.php b/src/commands/playwright.php index 111da13..3fc9734 100644 --- a/src/commands/playwright.php +++ b/src/commands/playwright.php @@ -44,20 +44,40 @@ setup_id(); $playwright_args = $args( '...' ); -$status = slic_realtime()( - array_merge( - [ - 'exec', - '--user', - sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ), - '--workdir', - escapeshellarg( get_project_container_path() ), - 'slic', - 'node_modules/.bin/playwright', - ], - $playwright_args - ) -); +$is_install_command = $playwright_args[0] === 'install'; + +if ( $is_install_command ) { + // Install commands will need to run as root. + $user = '0:0'; +} else { + // Other commands will run as the current user. + $user = sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ); +} + +if ( $playwright_args === ['install'] ) { + // It's exactly the `playwright install` command and nothing more. + $command = [ + 'exec', + '--user', + '0:0', + '--workdir', + escapeshellarg( get_project_container_path() ), + 'slic', + 'node_modules/.bin/playwright install chromium --with-deps', + ]; +} else { + $command = array_merge( [ + 'exec', + '--user', + $user, + '--workdir', + escapeshellarg( get_project_container_path() ), + 'slic', + 'node_modules/.bin/playwright', + ], $playwright_args ); +} + +$status = slic_realtime()( $command ); // If there is a status other than 0, we have an error. Bail. if ( $status ) {