Skip to content

Commit abd997d

Browse files
author
Greg Bowler
committed
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 8b81f7e commit abd997d

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
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)
@@ -95,7 +95,7 @@ PHP and PHPUnit versions
9595
9696
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:
9797
98-
+ `version` - the version number of PHPUnit to run e.g. `9` or `9.5.0` (default: latest)
98+
+ `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`
9999
+ `php_version` - the version number of PHP to use e.g. `7.4` (default: latest)
100100
+ `php_extensions` - a space-separated list of extensions to install using [php-build][php-build] e.g. `xdebug mbstring` (default: N/A)
101101

action.yml

Lines changed: 2 additions & 2 deletions
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:
@@ -138,7 +138,7 @@ runs:
138138
id: phpunit_run
139139
run: |
140140
set -e
141-
bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a62bbb7b8eade18e3c56b/php-build.bash) phpunit
141+
bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/8e7b8be8ce6c9bc342fc698b9a35de69e7b855b7/php-build.bash) phpunit
142142
${{ github.action_path }}/phpunit-action.bash
143143
shell: bash
144144

phpunit-action.bash

Lines changed: 24 additions & 0 deletions
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}"
@@ -135,6 +154,11 @@ fi
135154

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

157+
me=$(whoami)
158+
echo "Current user: $me"
159+
160+
ls -la
161+
138162
docker run --rm \
139163
--volume "${phar_path}":/usr/local/bin/phpunit \
140164
--volume "${GITHUB_WORKSPACE}":/app \

0 commit comments

Comments
 (0)