Skip to content

Commit 412e265

Browse files
committed
Initial release
1 parent c906d82 commit 412e265

File tree

8 files changed

+322
-1
lines changed

8 files changed

+322
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.php_cs.cache

.travis.yml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
3+
###
4+
### Enable sudo (required for docker service)
5+
###
6+
sudo: required
7+
8+
9+
###
10+
### Language
11+
###
12+
language: python
13+
14+
15+
###
16+
### Add services
17+
###
18+
services:
19+
- docker
20+
21+
22+
###
23+
### Build Matrix
24+
###
25+
env:
26+
matrix:
27+
- PCF=1 PHP=5.6
28+
- PCF=1 PHP=7.0
29+
- PCF=1 PHP=7.1
30+
- PCF=1 PHP=latest
31+
- PCF=2 PHP=5.6
32+
- PCF=2 PHP=7.0
33+
- PCF=2 PHP=7.1
34+
- PCF=2 PHP=7.2
35+
- PCF=2 PHP=7.3
36+
- PCF=2 PHP=latest
37+
- PCF=latest PHP=5.6
38+
- PCF=latest PHP=7.0
39+
- PCF=latest PHP=7.1
40+
- PCF=latest PHP=7.2
41+
- PCF=latest PHP=7.3
42+
- PCF=latest PHP=latest
43+
44+
45+
###
46+
### Install requirements
47+
###
48+
install:
49+
# Get newer docker version
50+
- while ! sudo apt-get update; do sleep 1; done
51+
- while ! sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; do sleep 1; done
52+
- docker version
53+
54+
55+
###
56+
### Check generation changes, build and test
57+
###
58+
before_script:
59+
- while ! make lint; do sleep 1; done
60+
- while ! make build PCF=${PCF} PHP=${PHP}; do sleep 1; done
61+
- while ! make test PCF=${PCF} PHP=${PHP}; do sleep 1; done
62+
63+
64+
###
65+
### Push to Dockerhub
66+
###
67+
script:
68+
# Push to docker hub on success
69+
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
70+
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
71+
if [ -n "${TRAVIS_TAG}" ]; then
72+
if [ "${PCF}" == "latest" ] && [ "${PHP}" == "latest" ]; then
73+
while ! make push TAG="latest-${TRAVIS_TAG}"; do sleep 1; done;
74+
else
75+
if [ "${PHP}" == "latest" ]; then
76+
while ! make push TAG="${PCF}-${TRAVIS_TAG}"; do sleep 1; done;
77+
else
78+
while ! make push TAG="${PCF}-php${PHP}-${TRAVIS_TAG}"; do sleep 1; done;
79+
fi
80+
fi
81+
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
82+
if [ "${PCF}" == "latest" ] && [ "${PHP}" == "latest" ]; then
83+
while ! make push TAG=latest; do sleep 1; done;
84+
else
85+
if [ "${PHP}" == "latest" ]; then
86+
while ! make push TAG=${PCF}; do sleep 1; done;
87+
else
88+
while ! make push TAG=${PCF}-php${PHP}; do sleep 1; done;
89+
fi
90+
fi
91+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
92+
if [ "${PCF}" == "latest" ] && [ "${PHP}" == "latest" ]; then
93+
while ! make push TAG="latest-${TRAVIS_BRANCH}"; do sleep 1; done;
94+
else
95+
if [ "${PHP}" == "latest" ]; then
96+
while ! make push TAG="${PCF}-${TRAVIS_BRANCH}"; do sleep 1; done;
97+
else
98+
while ! make push TAG="${PCF}-php${PHP}-${TRAVIS_BRANCH}"; do sleep 1; done;
99+
fi
100+
fi
101+
else
102+
echo "Skipping branch ${TRAVIS_BRANCH}";
103+
fi
104+
else
105+
echo "Skipping push on PR";
106+
fi

Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG PHP
2+
FROM php:7.1 as builder
3+
4+
# Install build dependencies
5+
RUN set -eux \
6+
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
7+
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
8+
ca-certificates \
9+
curl \
10+
git \
11+
&& git clone https://github.com/FriendsOfPHP/PHP-CS-Fixer
12+
13+
ARG PCF
14+
RUN set -eux \
15+
&& cd PHP-CS-Fixer \
16+
&& if [ "${PCF}" = "latest" ]; then \
17+
VERSION="$( git describe --abbrev=0 --tags )"; \
18+
else \
19+
VERSION="$( git tag | grep -E "^v?${PCF}\.[.0-9]+\$" | sort -V | tail -1 )"; \
20+
fi \
21+
&& curl -sS -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/${VERSION}/php-cs-fixer.phar -o /php-cs-fixer \
22+
&& chmod +x /php-cs-fixer \
23+
&& mv /php-cs-fixer /usr/bin/php-cs-fixer
24+
25+
RUN set -eux \
26+
&& php-cs-fixer --version
27+
28+
29+
FROM php:${PHP} as production
30+
LABEL \
31+
maintainer="cytopia <[email protected]>" \
32+
repo="https://github.com/cytopia/docker-php-cs-fixer"
33+
34+
COPY --from=builder /usr/bin/php-cs-fixer /usr/bin/php-cs-fixer
35+
ENV WORKDIR /data
36+
WORKDIR /data
37+
38+
ENTRYPOINT ["php-cs-fixer"]
39+
CMD ["--version"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 cytopia <https://github.com/cytopia>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: build rebuild lint test _test-php-cs-fixer-version _test-php-version _test-run tag pull login push enter
6+
7+
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8+
9+
DIR = .
10+
FILE = Dockerfile
11+
IMAGE = cytopia/php-cs-fixer
12+
TAG = latest
13+
14+
PHP = latest
15+
PCF = latest
16+
17+
build:
18+
ifeq ($(PHP),latest)
19+
docker build --build-arg PHP=7-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
20+
else
21+
docker build --build-arg PHP=$(PHP)-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
22+
endif
23+
24+
rebuild: pull
25+
ifeq ($(PHP),latest)
26+
docker build --no-cache --build-arg PHP=7-cli-alpine -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
27+
else
28+
docker build --no-cache --build-arg PHP=$(PHP)-cli-alpine -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
29+
endif
30+
31+
lint:
32+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path .
33+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path .
34+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path .
35+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path .
36+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path .
37+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path .
38+
39+
test:
40+
@$(MAKE) --no-print-directory _test-php-cs-fixer-version
41+
@$(MAKE) --no-print-directory _test-php-version
42+
@$(MAKE) --no-print-directory _test-run
43+
44+
_test-php-cs-fixer-version:
45+
@echo "------------------------------------------------------------"
46+
@echo "- Testing correct phpcs version"
47+
@echo "------------------------------------------------------------"
48+
@echo "Fetching latest version from GitHub"; \
49+
if [ "$(PCF)" = "latest" ]; then \
50+
LATEST="$$( \
51+
curl -L -sS https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases \
52+
| tac | tac \
53+
| grep -Eo 'tag/v?[.0-9]+?\.[.0-9]+\"' \
54+
| grep -Eo '[.0-9]+' \
55+
| sort -V \
56+
| tail -1 \
57+
)"; \
58+
echo "Testing for latest: $${LATEST}"; \
59+
if ! docker run --rm $(IMAGE) --version | grep -E "^PHP CS Fixer (version)?$${LATEST}"; then \
60+
echo "Failed"; \
61+
exit 1; \
62+
fi; \
63+
else \
64+
echo "Testing for tag: $(PCF).x.x"; \
65+
if ! docker run --rm $(IMAGE) --version | grep -E "^PHP CS Fixer (version[[:space:]])?$(PCF)\.[.0-9]+"; then \
66+
echo "Failed"; \
67+
exit 1; \
68+
fi; \
69+
fi; \
70+
echo "Success"; \
71+
72+
_test-php-version:
73+
@echo "------------------------------------------------------------"
74+
@echo "- Testing correct PHP version"
75+
@echo "------------------------------------------------------------"
76+
@if [ "$(PHP)" = "latest" ]; then \
77+
echo "Fetching latest version from GitHub"; \
78+
LATEST="$$( \
79+
curl -L -sS https://github.com/php/php-src/releases \
80+
| tac | tac \
81+
| grep -Eo '/php-[.0-9]+?\.[.0-9]+"' \
82+
| grep -Eo '[.0-9]+' \
83+
| sort -V \
84+
| tail -1 \
85+
)"; \
86+
echo "Testing for latest: $${LATEST}"; \
87+
if ! docker run --rm --entrypoint=php $(IMAGE) --version | head -1 | grep -E "^PHP[[:space:]]+$${LATEST}[[:space:]]"; then \
88+
echo "Failed"; \
89+
exit 1; \
90+
fi; \
91+
else \
92+
echo "Testing for tag: $(PHP).x"; \
93+
if ! docker run --rm --entrypoint=php $(IMAGE) --version | head -1 | grep -E "^PHP[[:space:]]+$(PHP)\.[.0-9]+[[:space:]]"; then \
94+
echo "Failed"; \
95+
exit 1; \
96+
fi; \
97+
fi; \
98+
echo "Success"; \
99+
100+
_test-run:
101+
@echo "------------------------------------------------------------"
102+
@echo "- Testing phpcs (success)"
103+
@echo "------------------------------------------------------------"
104+
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) fix --dry-run --diff .; then \
105+
echo "Failed"; \
106+
exit 1; \
107+
fi; \
108+
echo "Success";
109+
@echo "------------------------------------------------------------"
110+
@echo "- Testing phpcs (failure)"
111+
@echo "------------------------------------------------------------"
112+
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) fix --dry-run --diff .; then \
113+
echo "Failed"; \
114+
exit 1; \
115+
fi; \
116+
echo "Success";
117+
118+
tag:
119+
docker tag $(IMAGE) $(IMAGE):$(TAG)
120+
121+
pull:
122+
@grep -E '^\s*FROM' Dockerfile \
123+
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
124+
| xargs -n1 docker pull;
125+
126+
login:
127+
yes | docker login --username $(USER) --password $(PASS)
128+
129+
push:
130+
@$(MAKE) tag TAG=$(TAG)
131+
docker push $(IMAGE):$(TAG)
132+
133+
enter:
134+
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Docker images for PHP Coding Standards Fixer come with all available PHP version
7171
#### Latest stable php-cs-fixer `1.x.x` version
7272
| Docker tag | php-cs-fixer version | PHP version |
7373
|-----------------|-----------------------|-----------------------|
74-
| `1` | latest stable `1.x.x` | latest stable |
74+
| `1` | latest stable `1.x.x` | latest stable supported version |
7575
| `1-php7.1` | latest stable `1.x.x` | latest stable `7.1.x` |
7676
| `1-php7.0` | latest stable `1.x.x` | latest stable `7.0.x` |
7777
| `1-php5.6` | latest stable `1.x.x` | latest stable `5.6.x` |

tests/fail/fail.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
echo "test";
4+
5+
if ( 1 ==2) {
6+
echo "asd"; }

tests/ok/ok.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Ci test file
4+
* php version 7.
5+
*
6+
* @category Awesome-ci
7+
*
8+
* @author cytopia <[email protected]>
9+
* @copyright 2019 cytopia
10+
* @license MIT, https://opensource.org/licenses/MIT
11+
*
12+
* @link https://github.com/cytopia/docker-phpcs
13+
*/
14+
echo 'test';

0 commit comments

Comments
 (0)