Skip to content

Commit

Permalink
Merge pull request #1 from cytopia/release-0.1
Browse files Browse the repository at this point in the history
Initial release
  • Loading branch information
cytopia authored Jul 2, 2019
2 parents c906d82 + 4a09d86 commit 697c251
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.php_cs.cache
106 changes: 106 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---

###
### Enable sudo (required for docker service)
###
sudo: required


###
### Language
###
language: python


###
### Add services
###
services:
- docker


###
### Build Matrix
###
env:
matrix:
- PCF=1 PHP=5.6
- PCF=1 PHP=7.0
- PCF=1 PHP=7.1
- PCF=1 PHP=latest
- PCF=2 PHP=5.6
- PCF=2 PHP=7.0
- PCF=2 PHP=7.1
- PCF=2 PHP=7.2
- PCF=2 PHP=7.3
- PCF=2 PHP=latest
- PCF=latest PHP=5.6
- PCF=latest PHP=7.0
- PCF=latest PHP=7.1
- PCF=latest PHP=7.2
- PCF=latest PHP=7.3
- PCF=latest PHP=latest


###
### Install requirements
###
install:
# Get newer docker version
- while ! sudo apt-get update; do sleep 1; done
- while ! sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; do sleep 1; done
- docker version


###
### Check generation changes, build and test
###
before_script:
- while ! make lint; do sleep 1; done
- while ! make build PCF=${PCF} PHP=${PHP}; do sleep 1; done
- while ! make test PCF=${PCF} PHP=${PHP}; do sleep 1; done


###
### Push to Dockerhub
###
script:
# Push to docker hub on success
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
if [ -n "${TRAVIS_TAG}" ]; then
if [ "${PCF}" == "latest" ] && [ "${PHP}" == "latest" ]; then
while ! make push TAG="latest-${TRAVIS_TAG}"; do sleep 1; done;
else
if [ "${PHP}" == "latest" ]; then
while ! make push TAG="${PCF}-${TRAVIS_TAG}"; do sleep 1; done;
else
while ! make push TAG="${PCF}-php${PHP}-${TRAVIS_TAG}"; do sleep 1; done;
fi
fi
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
if [ "${PCF}" == "latest" ] && [ "${PHP}" == "latest" ]; then
while ! make push TAG=latest; do sleep 1; done;
else
if [ "${PHP}" == "latest" ]; then
while ! make push TAG=${PCF}; do sleep 1; done;
else
while ! make push TAG=${PCF}-php${PHP}; do sleep 1; done;
fi
fi
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
if [ "${PCF}" == "latest" ] && [ "${PHP}" == "latest" ]; then
while ! make push TAG="latest-${TRAVIS_BRANCH}"; do sleep 1; done;
else
if [ "${PHP}" == "latest" ]; then
while ! make push TAG="${PCF}-${TRAVIS_BRANCH}"; do sleep 1; done;
else
while ! make push TAG="${PCF}-php${PHP}-${TRAVIS_BRANCH}"; do sleep 1; done;
fi
fi
else
echo "Skipping branch ${TRAVIS_BRANCH}";
fi
else
echo "Skipping push on PR";
fi
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG PHP
FROM php:7.1 as builder

# Install build dependencies
RUN set -eux \
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
ca-certificates \
curl \
git \
&& git clone https://github.com/FriendsOfPHP/PHP-CS-Fixer

ARG PCF
RUN set -eux \
&& cd PHP-CS-Fixer \
&& if [ "${PCF}" = "latest" ]; then \
VERSION="$( git describe --abbrev=0 --tags )"; \
else \
VERSION="$( git tag | grep -E "^v?${PCF}\.[.0-9]+\$" | sort -V | tail -1 )"; \
fi \
&& curl -sS -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/${VERSION}/php-cs-fixer.phar -o /php-cs-fixer \
&& chmod +x /php-cs-fixer \
&& mv /php-cs-fixer /usr/bin/php-cs-fixer

RUN set -eux \
&& php-cs-fixer --version


FROM php:${PHP} as production
LABEL \
maintainer="cytopia <cytopia@everythingcli.org>" \
repo="https://github.com/cytopia/docker-php-cs-fixer"

COPY --from=builder /usr/bin/php-cs-fixer /usr/bin/php-cs-fixer
ENV WORKDIR /data
WORKDIR /data

ENTRYPOINT ["php-cs-fixer"]
CMD ["--version"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 cytopia <https://github.com/cytopia>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
158 changes: 158 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
ifneq (,)
.error This Makefile requires GNU Make.
endif

.PHONY: build rebuild lint test _test-php-cs-fixer-version _test-php-version _test-run tag pull login push enter

CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

DIR = .
FILE = Dockerfile
IMAGE = cytopia/php-cs-fixer
TAG = latest

PHP = latest
PCF = latest

build:
ifeq ($(PCF),1)
ifeq ($(PHP),latest)
@# PHP CS Fixer version 1 goes only up to PHP 7.1
docker build --build-arg PHP=7.1-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
else
docker build --build-arg PHP=$(PHP)-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
endif
else
ifeq ($(PHP),latest)
docker build --build-arg PHP=7-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
else
docker build --build-arg PHP=$(PHP)-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
endif
endif

rebuild: pull
ifeq ($(PCF),1)
ifeq ($(PHP),latest)
@# PHP CS Fixer version 1 goes only up to PHP 7.1
docker build --no-cache --build-arg PHP=7.1-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
else
docker build --no-cache --build-arg PHP=$(PHP)-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
endif
else
ifeq ($(PHP),latest)
docker build --no-cache --build-arg PHP=7-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
else
docker build --no-cache --build-arg PHP=$(PHP)-cli-alpine --build-arg PCF=$(PCF) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
endif
endif

lint:
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path .

test:
@$(MAKE) --no-print-directory _test-php-cs-fixer-version
@$(MAKE) --no-print-directory _test-php-version
@$(MAKE) --no-print-directory _test-run

_test-php-cs-fixer-version:
@echo "------------------------------------------------------------"
@echo "- Testing correct phpcs version"
@echo "------------------------------------------------------------"
@echo "Fetching latest version from GitHub"; \
if [ "$(PCF)" = "latest" ]; then \
LATEST="$$( \
curl -L -sS https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases \
| tac | tac \
| grep -Eo 'tag/v?[.0-9]+?\.[.0-9]+\"' \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 \
)"; \
echo "Testing for latest: $${LATEST}"; \
if ! docker run --rm $(IMAGE) --version | grep -E "^PHP CS Fixer (version)?$${LATEST}"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(PCF).x.x"; \
if ! docker run --rm $(IMAGE) --version | grep -E "^PHP CS Fixer (version[[:space:]])?$(PCF)\.[.0-9]+"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \

_test-php-version:
@echo "------------------------------------------------------------"
@echo "- Testing correct PHP version"
@echo "------------------------------------------------------------"
@if [ "$(PCF)" = "1" ] && [ "$(PHP)" = "latest" ]; then \
echo "Testing for tag: 7.1.x"; \
if ! docker run --rm --entrypoint=php $(IMAGE) --version | head -1 | grep -E "^PHP[[:space:]]+7\.1\.[.0-9]+[[:space:]]"; then \
echo "Failed"; \
exit 1; \
fi; \
elif [ "$(PHP)" = "latest" ]; then \
echo "Fetching latest version from GitHub"; \
LATEST="$$( \
curl -L -sS https://github.com/php/php-src/releases \
| tac | tac \
| grep -Eo '/php-[.0-9]+?\.[.0-9]+"' \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 \
)"; \
echo "Testing for latest: $${LATEST}"; \
if ! docker run --rm --entrypoint=php $(IMAGE) --version | head -1 | grep -E "^PHP[[:space:]]+$${LATEST}[[:space:]]"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(PHP).x"; \
if ! docker run --rm --entrypoint=php $(IMAGE) --version | head -1 | grep -E "^PHP[[:space:]]+$(PHP)\.[.0-9]+[[:space:]]"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \

_test-run:
@echo "------------------------------------------------------------"
@echo "- Testing phpcs (success)"
@echo "------------------------------------------------------------"
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) fix --dry-run --diff .; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
@echo "------------------------------------------------------------"
@echo "- Testing phpcs (failure)"
@echo "------------------------------------------------------------"
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) fix --dry-run --diff .; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";

tag:
docker tag $(IMAGE) $(IMAGE):$(TAG)

pull:
@grep -E '^\s*FROM' Dockerfile \
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
| xargs -n1 docker pull;

login:
yes | docker login --username $(USER) --password $(PASS)

push:
@$(MAKE) tag TAG=$(TAG)
docker push $(IMAGE):$(TAG)

enter:
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Docker images for PHP Coding Standards Fixer come with all available PHP version
#### Latest stable php-cs-fixer `1.x.x` version
| Docker tag | php-cs-fixer version | PHP version |
|-----------------|-----------------------|-----------------------|
| `1` | latest stable `1.x.x` | latest stable |
| `1` | latest stable `1.x.x` | latest stable supported version |
| `1-php7.1` | latest stable `1.x.x` | latest stable `7.1.x` |
| `1-php7.0` | latest stable `1.x.x` | latest stable `7.0.x` |
| `1-php5.6` | latest stable `1.x.x` | latest stable `5.6.x` |
Expand Down
6 changes: 6 additions & 0 deletions tests/fail/fail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

echo "test";

if ( 1 ==2) {
echo "asd"; }
14 changes: 14 additions & 0 deletions tests/ok/ok.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Ci test file
* php version 7.
*
* @category Awesome-ci
*
* @author cytopia <cytopia@everything-cli.org>
* @copyright 2019 cytopia
* @license MIT, https://opensource.org/licenses/MIT
*
* @link https://github.com/cytopia/docker-phpcs
*/
echo 'test';

0 comments on commit 697c251

Please sign in to comment.