Skip to content

Commit c27e49b

Browse files
author
Greg Bowler
authored
Use composer version of PHPUnit by default if availble (#61)
* wip: lookup version from composer * wip: check current user * wip: update php-build
1 parent d1db433 commit c27e49b

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Inputs
4444

4545
The following configuration options are available:
4646

47-
+ `version` The version of PHPUnit to use e.g. `9` or `9.5.0` (default: latest)
47+
+ `version` The version of PHPUnit to use e.g. `latest`, `9` or `9.5.0` (default: `composer` - use the version specified in composer.json)
4848
+ `php_version` The version of PHP to use e.g. `7.4` (default: latest)
4949
+ `php_extensions` Space-separated list of extensions using [php-build][php-build] e.g. `xdebug mbstring` (default: N/A)
5050
+ `vendored_phpunit_path` The path to a phar file already present on the runner (default: N/A)
@@ -96,7 +96,7 @@ PHP and PHPUnit versions
9696
9797
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:
9898
99-
+ `version` - the version number of PHPUnit to run e.g. `9` or `9.5.0` (default: latest)
99+
+ `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`
100100
+ `php_version` - the version number of PHP to use e.g. `7.4` (default: latest)
101101
+ `php_extensions` - a space-separated list of extensions to install using [php-build][php-build] e.g. `xdebug mbstring` (default: N/A)
102102

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Run your PHPUnit tests in your Github Actions.
44
inputs:
55
version:
66
description: What version of PHPUnit to use
7-
default: latest
7+
default: composer
88
required: false
99

1010
php_version:
@@ -143,7 +143,7 @@ runs:
143143
id: phpunit_run
144144
run: |
145145
set -e
146-
bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a62bbb7b8eade18e3c56b/php-build.bash) phpunit
146+
bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/8e7b8be8ce6c9bc342fc698b9a35de69e7b855b7/php-build.bash) phpunit
147147
${{ github.action_path }}/phpunit-action.bash
148148
shell: bash
149149

phpunit-action.bash

+24
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,28 @@ docker_tag=$(cat ./docker_tag)
55

66
echo "Docker tag: $docker_tag" >> output.log 2>&1
77

8+
function get_version_from_composer() {
9+
version_string="*"
10+
11+
if [ -f composer.lock ]
12+
then
13+
version_string=$(jq -r 'first(.["packages-dev"][]?, .packages[]? | select(.name == "phpunit/phpunit") | .version)' composer.lock)
14+
else
15+
version_string=$(jq '.["require-dev"]["phpunit/phpunit"] // .["require"]["phpunit/phpunit"]' composer.json)
16+
version_string=$(echo "$version_string" | sed -E 's/^[^0-9]*//')
17+
fi
18+
19+
echo $version_string
20+
}
21+
822
if [ -z "$ACTION_PHPUNIT_PATH" ]
923
then
1024
phar_url="https://phar.phpunit.de/phpunit"
25+
if [ "$ACTION_VERSION" == "composer" ]
26+
then
27+
ACTION_VERSION=$(get_version_from_composer)
28+
fi
29+
1130
if [ "$ACTION_VERSION" != "latest" ]
1231
then
1332
phar_url="${phar_url}-${ACTION_VERSION}"
@@ -141,6 +160,11 @@ fi
141160

142161
echo "Command: ${command_string[@]}" >> output.log 2>&1
143162

163+
me=$(whoami)
164+
echo "Current user: $me"
165+
166+
ls -la
167+
144168
docker run --rm \
145169
--volume "${phar_path}":/usr/local/bin/phpunit \
146170
--volume "${GITHUB_WORKSPACE}":/app \

0 commit comments

Comments
 (0)