From abd997d531c5fb223ddc63289cde212b8b3f6cf0 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Tue, 5 Mar 2024 15:29:31 +0000 Subject: [PATCH 1/2] Use composer version of PHPUnit by default if availble (#61) * wip: lookup version from composer * wip: check current user * wip: update php-build --- README.md | 4 ++-- action.yml | 4 ++-- phpunit-action.bash | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) 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..d57a6bb 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: @@ -138,7 +138,7 @@ runs: id: phpunit_run run: | set -e - bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a62bbb7b8eade18e3c56b/php-build.bash) phpunit + bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/8e7b8be8ce6c9bc342fc698b9a35de69e7b855b7/php-build.bash) phpunit ${{ github.action_path }}/phpunit-action.bash shell: bash 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 \ From 2210910f78bf238c30ac54ecb12403efe48d3d43 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 7 Mar 2024 16:23:32 +0000 Subject: [PATCH 2/2] downgrade phpbuild --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index d57a6bb..671afea 100644 --- a/action.yml +++ b/action.yml @@ -138,7 +138,7 @@ runs: id: phpunit_run run: | set -e - bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/8e7b8be8ce6c9bc342fc698b9a35de69e7b855b7/php-build.bash) phpunit + bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a62bbb7b8eade18e3c56b/php-build.bash) phpunit ${{ github.action_path }}/phpunit-action.bash shell: bash