Skip to content

Commit

Permalink
move test tools into vendor-bin (open-telemetry#1302)
Browse files Browse the repository at this point in the history
* move test tools into vendor-bin
To reduce (hopefully, eliminate) the situations where our testing tools have conflicting
dependencies, use bamarni/composer-bin-plugin to manage them as separate vendored dirs.
Add symlinks under tools/, and update Makefile to use the self-contained versions.
Remove the dependencies from root composer.json
Rejigger dockerfile to add opcache, and some config required for latest version of grpc

* update action tools locations

* revert phpstan from vendor-bin
the phpstan plugins do not work. phpstan has no dependencies anyway, so it's safe enough to keep in vendor

* remove tools symlinks, update makefile
  • Loading branch information
brettmc committed May 5, 2024
1 parent 8e810c6 commit 8031c78
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 42 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ jobs:
key: ${{ runner.os }}-${{ matrix.php-version }}-php-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-version }}-php-
- name: Cache test tools
id: test-tools-cache
uses: actions/cache@v3
with:
path: vendor-bin
key: ${{ runner.os }}-${{ matrix.php-version }}-php-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-version }}-php-
- name: Install dependencies
id: composer
Expand All @@ -95,25 +103,25 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
env:
PHP_CS_FIXER_IGNORE_ENV: 1
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no -vvv
run: vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no -vvv

- name: Check Dependencies
id: deps
continue-on-error: ${{ matrix.experimental }}
run: vendor/bin/deptrac --formatter=github-actions --report-uncovered
run: vendor-bin/deptrac/vendor/bin/deptrac --formatter=github-actions --report-uncovered

- name: Run Phan
id: phan
continue-on-error: ${{ matrix.experimental }}
env:
XDEBUG_MODE: off
PHAN_DISABLE_XDEBUG_WARN: 1
run: vendor/bin/phan
run: vendor-bin/phan/vendor/bin/phan

- name: Run Psalm
id: psalm
continue-on-error: ${{ matrix.experimental }}
run: vendor/bin/psalm --output-format=github
run: vendor-bin/psalm/vendor/bin/psalm --output-format=github

- name: Run Phpstan
id: phpstan
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ composer.phar
composer.lock
var/
vendor/
vendor-bin/**/vendor/
vendor-bin/**/composer.lock
coverage.clover
tests/coverage
.php-cs-fixer.cache
Expand Down
16 changes: 11 additions & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ To downgrade to the lowest dependencies, you can run
make update-lowest
```

To run all checks without doing a composer update:

```shell
make all-checks
```

## Coding Guidelines
Even though it may not be reflected everywhere in the codebase yet, we aim to provide software which is easy to read and change.
The methods described in Clean Code book(s) by Robert C. Martin (Uncle Bob) are a de facto industry standards nowadays.
Expand Down Expand Up @@ -71,14 +77,14 @@ This does the following things:
### Other PHP versions

We aim to support officially supported PHP versions, according to https://www.php.net/supported-versions.php. The
developer image `ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base` is tagged as `8.0`, `8.1`, `8.2` and `8.3`
respectively, with `8.0` being the default. You can execute the test suite against other PHP versions by running the
developer image `ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base` is tagged as `8.1`, `8.2` and `8.3`
respectively, with `8.1` being the default. You can execute the test suite against other PHP versions by running the
following command:

```bash
PHP_VERSION=8.0 make all
#or
PHP_VERSION=8.1 make all
#or
PHP_VERSION=8.3 make all
```

## Proto Generation
Expand Down Expand Up @@ -212,7 +218,7 @@ To make sure the different components of the library are distributable as separa
For this purpose we use [Deptrac](https://github.com/qossmic/deptrac) and the respective configuration can be found
[here](./deptrac.yaml)

To validatethe dependencies inside the code base, you can run:
To validate the dependencies inside the code base, you can run:

```bash
make deptrac
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ test-compliance: ## Run compliance tests
test-trace-compliance: ## Run trace compliance tests
$(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --group trace-compliance
phan: ## Run phan
$(DC_RUN_PHP) env XDEBUG_MODE=off env PHAN_DISABLE_XDEBUG_WARN=1 vendor/bin/phan
$(DC_RUN_PHP) env XDEBUG_MODE=off env PHAN_DISABLE_XDEBUG_WARN=1 vendor-bin/phan/vendor/bin/phan
psalm: ## Run psalm
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/psalm --threads=1 --no-cache
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/psalm/vendor/bin/psalm --threads=1 --no-cache
psalm-info: ## Run psalm and show info
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/psalm --show-info=true --threads=1
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/psalm/vendor/bin/psalm --show-info=true --threads=1
phpstan: ## Run phpstan
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpstan analyse --memory-limit=256M
packages-composer: ## Validate composer packages
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/otel packages:composer:validate
benchmark: ## Run phpbench
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpbench run --report=default
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/phpbench/vendor/bin/phpbench run --report=default
phpmetrics: ## Run php metrics
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpmetrics --config=./phpmetrics.json --junit=junit.xml
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/phpmetrics/vendor/bin/phpmetrics --config=./phpmetrics.json --junit=junit.xml
smoke-test-examples: smoke-test-isolated-examples smoke-test-exporter-examples smoke-test-collector-integration smoke-test-prometheus-example ## Run smoke test examples
smoke-test-isolated-examples: ## Run smoke test isolated examples
$(DC_RUN_PHP) php ./examples/traces/getting_started.php
Expand Down Expand Up @@ -91,13 +91,13 @@ protobuf: ## Generate protobuf files
bash: ## bash shell into container
$(DC_RUN_PHP) bash
style: ## Run style check/fix
$(DC_RUN_PHP) env XDEBUG_MODE=off env PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no -vvv
$(DC_RUN_PHP) env XDEBUG_MODE=off env PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no -vvv
rector-write: ## Run rector
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/rector process src
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/rector/vendor/bin/rector process src
rector: ## Run rector (dry-run)
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/rector process src --dry-run
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/rector/vendor/bin/rector process src --dry-run
deptrac: ## Run deptrac
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/deptrac --formatter=table --report-uncovered --no-cache
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/deptrac/vendor/bin/deptrac --formatter=table --report-uncovered --no-cache
w3c-test-service:
@$(DOCKER_COMPOSE) -f docker-compose.w3cTraceContext.yaml run --rm php ./tests/TraceContext/W3CTestService/trace-context-test.sh
semconv: ## Generate semconv files
Expand Down
18 changes: 7 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"bamarni/composer-bin-plugin": true,
"composer/package-versions-deprecated": true,
"php-http/discovery": true,
"symfony/runtime": true,
Expand Down Expand Up @@ -83,33 +84,23 @@
"ext-grpc": "*",
"grpc/grpc": "^1.30",
"assertwell/phpunit-global-state": "^0.2.2",
"composer/xdebug-handler": "^3.0",
"bamarni/composer-bin-plugin": "^1.8",
"dg/bypass-finals": "^1.4",
"friendsofphp/php-cs-fixer": "^3.51",
"guzzlehttp/guzzle": "^7.4",
"guzzlehttp/psr7": "^2.1",
"mikey179/vfsstream": "^1.6.11",
"mockery/mockery": "^1.5.1",
"monolog/monolog": "^2.3",
"nikic/php-parser": "^4.15.4",
"nyholm/psr7": "^1.4",
"open-telemetry/dev-tools": "dev-main",
"phan/phan": "^5.4",
"php-http/mock-client": "^1.5",
"phpbench/phpbench": "^1.2",
"phpdocumentor/reflection-docblock": "^5.3",
"phpmetrics/phpmetrics": "^2.8",
"phpspec/prophecy": "^1.17.0",
"phpspec/prophecy-phpunit": "^2",
"phpstan/phpstan": "^1.10.13",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^10",
"psalm/plugin-mockery": "^1",
"psalm/plugin-phpunit": "^0.18.4",
"psalm/psalm": "^5",
"qossmic/deptrac-shim": "^0.24 || ^1",
"rector/rector": "^1",
"symfony/http-client": "^5.2",
"symfony/var-exporter": "^5.4 || ^6.4 || ^7.0",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0"
Expand All @@ -122,6 +113,11 @@
"symfony/yaml": "Allows loading config from yaml files"
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"target-directory": "vendor-bin",
"forward-command": true
},
"spi": {
"OpenTelemetry\\Config\\SDK\\Configuration\\ComponentProvider": [
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorB3",
Expand Down
26 changes: 13 additions & 13 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
ARG PHP_VERSION=8.0
FROM php:${PHP_VERSION}-cli-alpine as php_build
FROM php:${PHP_VERSION}-cli-alpine

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions; \
apk add --update binutils; \
install-php-extensions \
RUN chmod +x /usr/local/bin/install-php-extensions \
&& apk add binutils \
&& install-php-extensions \
@composer \
ast \
xdebug \
zip \
pcntl \
grpc \
intl\
opcache \
pcntl \
protobuf \
sockets \
intl \
@composer \
; \
# strip debug symbols from extensions to reduce size
find /usr/local/lib/php/extensions -name "*.so" -exec strip --strip-debug {} \;;
xdebug \
zip \
&& find /usr/local/lib/php/extensions -name "*.so" -exec strip --strip-debug {} \;

FROM php_build
RUN echo "grpc.enable_fork_support = 1" > $(php-config --ini-dir)/grpc.ini \
&& echo "grpc.poll_strategy = epoll1" >> $(php-config --ini-dir)/grpc.ini

WORKDIR /usr/src/myapp

Expand Down
10 changes: 10 additions & 0 deletions vendor-bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Testing tools installed and managed by https://github.com/bamarni/composer-bin-plugin.

Note that this should only be used for tools that are self-contained (specifically, *not* phpunit).

To add a tool:
- `composer bin <tool-name> require --dev <package>`
- `cd tools`
- `ln -s ../vendor-bin/<tool-name>/vendor/bin/<tool-executable>`

Tools are automatically updated as part of `composer update`.
5 changes: 5 additions & 0 deletions vendor-bin/deptrac/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"qossmic/deptrac-shim": "^1.0"
}
}
5 changes: 5 additions & 0 deletions vendor-bin/phan/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"phan/phan": "^5.4"
}
}
5 changes: 5 additions & 0 deletions vendor-bin/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.54"
}
}
5 changes: 5 additions & 0 deletions vendor-bin/phpbench/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"phpbench/phpbench": "^1.2"
}
}
5 changes: 5 additions & 0 deletions vendor-bin/phpmetrics/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"phpmetrics/phpmetrics": "^2.8"
}
}
7 changes: 7 additions & 0 deletions vendor-bin/psalm/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require-dev": {
"vimeo/psalm": "^5.24",
"psalm/plugin-mockery": "^1",
"psalm/plugin-phpunit": "^0.18.4"
}
}
5 changes: 5 additions & 0 deletions vendor-bin/rector/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"rector/rector": "^1.0"
}
}

0 comments on commit 8031c78

Please sign in to comment.