Skip to content

Commit

Permalink
Local build: rely only on docker (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored May 31, 2024
1 parent 0ee79dd commit 51b3b85
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/Makefile export-ignore
/Dockerfile export-ignore
/docker-compose.yml export-ignore
/infection.json export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
/coverage
/test/fixtures/wrapper_batchsize_suite/tmp
/vendor
/.phpunit.cache
composer.lock
.env
.phpunit.cache
.phpunit.result.cache
.php_cs.cache
composer.lock
infections.log
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:8.3

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

RUN install-php-extensions @composer pcov

ARG USER_ID
ARG GROUP_ID

RUN groupadd --gid ${GROUP_ID} code \
&& useradd --create-home --shell /bin/bash --uid ${USER_ID} --gid code code

USER code
43 changes: 24 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DOCKER_PHP_EXEC := docker compose run php

SRCS := $(shell find ./src ./test -type f -not -path "*/tmp/*")

Expand All @@ -11,22 +12,26 @@ BASE_BRANCH ?= $(LOCAL_BASE_BRANCH)
all: csfix static-analysis test
@echo "Done."

vendor: composer.json
composer update
composer bump
.env: /etc/passwd /etc/group Makefile
printf "USER_ID=%s\nGROUP_ID=%s\n" `id --user "${USER}"` `id --group "${USER}"` > .env

vendor: .env docker-compose.yml Dockerfile composer.json
docker compose build --pull
$(DOCKER_PHP_EXEC) composer update
$(DOCKER_PHP_EXEC) composer bump
touch vendor

.PHONY: csfix
csfix: vendor
vendor/bin/phpcbf || true
vendor/bin/phpcs --cache
$(DOCKER_PHP_EXEC) vendor/bin/phpcbf || true
$(DOCKER_PHP_EXEC) vendor/bin/phpcs --cache

.PHONY: static-analysis
static-analysis: vendor
php -d zend.assertions=1 vendor/bin/phpstan $(PHPSTAN_ARGS)
$(DOCKER_PHP_EXEC) php -d zend.assertions=1 vendor/bin/phpstan --memory-limit=512M $(PHPSTAN_ARGS)

coverage/junit.xml: vendor $(SRCS) Makefile
php -d zend.assertions=1 \
coverage/junit.xml: vendor $(SRCS)
$(DOCKER_PHP_EXEC) php -d zend.assertions=1 \
-d pcov.enabled=1 \
vendor/bin/phpunit \
--coverage-clover=coverage/clover.xml \
Expand All @@ -42,7 +47,7 @@ test: coverage/junit.xml
.PHONY: code-coverage
code-coverage: coverage/junit.xml
echo "Base branch: $(BASE_BRANCH)"
php -d zend.assertions=1 \
$(DOCKER_PHP_EXEC) php -d zend.assertions=1 \
-d pcov.enabled=1 \
vendor/bin/infection run \
--threads=$(shell nproc) \
Expand All @@ -59,23 +64,23 @@ code-coverage: coverage/junit.xml

.PHONY: clean
clean:
rm -r test/tmp/*
git clean -dfX

.PHONY: regenerate-fixture-results
regenerate-fixture-results: vendor
vendor/bin/phpunit \
$(DOCKER_PHP_EXEC) vendor/bin/phpunit \
--log-junit test/fixtures/special_chars/data-provider-with-special-chars.xml \
--no-configuration \
test/fixtures/special_chars/UnitTestWithDataProviderSpecialCharsTest.php \
> /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/ErrorTest.php --log-junit test/fixtures/common_results/junit/ErrorTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/FailureTest.php --log-junit test/fixtures/common_results/junit/FailureTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/IncompleteTest.php --log-junit test/fixtures/common_results/junit/IncompleteTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/RiskyTest.php --log-junit test/fixtures/common_results/junit/RiskyTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/SkippedTest.php --log-junit test/fixtures/common_results/junit/SkippedTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/SuccessTest.php --log-junit test/fixtures/common_results/junit/SuccessTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/WarningTest.php --log-junit test/fixtures/common_results/junit/WarningTest.xml > /dev/null || true
vendor/bin/phpunit --no-configuration test/fixtures/common_results/ --log-junit test/fixtures/common_results/combined.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/ErrorTest.php --log-junit test/fixtures/common_results/junit/ErrorTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/FailureTest.php --log-junit test/fixtures/common_results/junit/FailureTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/IncompleteTest.php --log-junit test/fixtures/common_results/junit/IncompleteTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/RiskyTest.php --log-junit test/fixtures/common_results/junit/RiskyTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/SkippedTest.php --log-junit test/fixtures/common_results/junit/SkippedTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/SuccessTest.php --log-junit test/fixtures/common_results/junit/SuccessTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/WarningTest.php --log-junit test/fixtures/common_results/junit/WarningTest.xml > /dev/null || true
$(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/ --log-junit test/fixtures/common_results/combined.xml > /dev/null || true
find test/fixtures/ -type f -name "*.xml" -print0 | xargs -0 sed -i 's#$(PWD)#.#g'
find test/fixtures/ -type f -name "*.xml" -print0 | xargs -0 sed -i 's#time="........"#time="1.234567"#g'
sed -i 's#name="./test/fixtures/common_results"#name=""#g' test/fixtures/common_results/combined.xml
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"phpunit/php-timer": "^6.0.0 || ^7.0.0",
"phpunit/phpunit": "^10.5.20 || ^11.1.3",
"sebastian/environment": "^6.1.0 || ^7.1.0",
"symfony/console": "^6.4.7 || ^7.0.7",
"symfony/process": "^6.4.7 || ^7.0.7"
"symfony/console": "^6.4.7 || ^7.1.0",
"symfony/process": "^6.4.7 || ^7.1.0"
},
"require-dev": {
"ext-pcov": "*",
Expand All @@ -57,7 +57,7 @@
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.0",
"squizlabs/php_codesniffer": "^3.10.1",
"symfony/filesystem": "^6.4.3 || ^7.0.7"
"symfony/filesystem": "^6.4.3 || ^7.1.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
php:
build:
context: .
args:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
volumes:
- .:${PWD}
working_dir: ${PWD}

0 comments on commit 51b3b85

Please sign in to comment.