From f49ccf54fbc43e4059d74245f0c1cc18566ea086 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Mon, 18 Sep 2023 13:05:30 +0100 Subject: [PATCH 1/3] wip: lookup version from composer --- README.md | 4 ++-- action.yml | 2 +- phpunit-action.bash | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 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..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..f65b525 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}" From 8642f56c7697eec9dd56b615df0e5d575ec35ed0 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Mon, 18 Sep 2023 16:59:18 +0100 Subject: [PATCH 2/3] wip: check current user --- phpunit-action.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpunit-action.bash b/phpunit-action.bash index f65b525..a626f35 100755 --- a/phpunit-action.bash +++ b/phpunit-action.bash @@ -154,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 773f7e26c61d597f310c16a52d3e027685ac9da7 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Mon, 18 Sep 2023 17:42:00 +0100 Subject: [PATCH 3/3] wip: update php-build --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 671afea..d57a6bb 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/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