diff --git a/README.md b/README.md index 2e49344..27dfa14 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Inputs The following configuration options are available: -+ `version` The version of PHPUnit to use e.g. `9` or `9.5.0` (default: latest) ++ `version` The version of PHPUnit to use e.g. `latest`, `9` or `9.5.0` (default: `composer` - use the version specified in composer.json) + `php_version` The version of PHP to use e.g. `7.4` (default: latest) + `php_extensions` Space-separated list of extensions using [php-build][php-build] e.g. `xdebug mbstring` (default: N/A) + `vendored_phpunit_path` The path to a phar file already present on the runner (default: N/A) @@ -95,7 +95,7 @@ PHP and PHPUnit versions It's possible to run any version of PHPUnit under any version of PHP, with any PHP extensions you require. This is configured with the following inputs: -+ `version` - the version number of PHPUnit to run e.g. `9` or `9.5.0` (default: latest) ++ `version` - the version number of PHPUnit to run e.g. `latest`, `9` or `9.5.0` (default: `composer`). Using the default value, `composer` will install the version specified in `composer.json` + `php_version` - the version number of PHP to use e.g. `7.4` (default: latest) + `php_extensions` - a space-separated list of extensions to install using [php-build][php-build] e.g. `xdebug mbstring` (default: N/A) diff --git a/action.yml b/action.yml index 4f492fb..671afea 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ description: Run your PHPUnit tests in your Github Actions. inputs: version: description: What version of PHPUnit to use - default: latest + default: composer required: false php_version: diff --git a/phpunit-action.bash b/phpunit-action.bash index 26ce162..a626f35 100755 --- a/phpunit-action.bash +++ b/phpunit-action.bash @@ -5,9 +5,28 @@ docker_tag=$(cat ./docker_tag) echo "Docker tag: $docker_tag" >> output.log 2>&1 +function get_version_from_composer() { + version_string="*" + + if [ -f composer.lock ] + then + version_string=$(jq -r 'first(.["packages-dev"][]?, .packages[]? | select(.name == "phpunit/phpunit") | .version)' composer.lock) + else + version_string=$(jq '.["require-dev"]["phpunit/phpunit"] // .["require"]["phpunit/phpunit"]' composer.json) + version_string=$(echo "$version_string" | sed -E 's/^[^0-9]*//') + fi + + echo $version_string +} + if [ -z "$ACTION_PHPUNIT_PATH" ] then phar_url="https://phar.phpunit.de/phpunit" + if [ "$ACTION_VERSION" == "composer" ] + then + ACTION_VERSION=$(get_version_from_composer) + fi + if [ "$ACTION_VERSION" != "latest" ] then phar_url="${phar_url}-${ACTION_VERSION}" @@ -135,6 +154,11 @@ fi echo "Command: ${command_string[@]}" >> output.log 2>&1 +me=$(whoami) +echo "Current user: $me" + +ls -la + docker run --rm \ --volume "${phar_path}":/usr/local/bin/phpunit \ --volume "${GITHUB_WORKSPACE}":/app \