From 75be9aef2795e8494436de0e30b3f585ca7e8828 Mon Sep 17 00:00:00 2001 From: Arnie Date: Mon, 19 Nov 2018 19:31:44 +0100 Subject: [PATCH] Make php 7.0 cs fixer --- code-formatter/Dockerfile | 4 +- code-formatter/Dockerfile.56 | 41 +++++++++++++++++++ code-formatter/Makefile | 6 ++- .../src/inc/formatters/php-cs-fixer.shinc | 9 +++- code-formatter/src/inc/variables.shinc | 5 ++- 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 code-formatter/Dockerfile.56 diff --git a/code-formatter/Dockerfile b/code-formatter/Dockerfile index 5886cf7..51a4bcc 100644 --- a/code-formatter/Dockerfile +++ b/code-formatter/Dockerfile @@ -1,4 +1,4 @@ -FROM node:8-slim +FROM node:8-stretch # https support RUN apt-get update && \ @@ -8,7 +8,7 @@ RUN apt-get update && \ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt-get update && \ - apt-get install -y yarn php5-cli && \ + apt-get install -y yarn php7.0-cli && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/* /tmp/* /var/tmp/* diff --git a/code-formatter/Dockerfile.56 b/code-formatter/Dockerfile.56 new file mode 100644 index 0000000..5886cf7 --- /dev/null +++ b/code-formatter/Dockerfile.56 @@ -0,0 +1,41 @@ +FROM node:8-slim + +# https support +RUN apt-get update && \ + apt-get install -y apt-transport-https ca-certificates + +# add yarn and php +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ + apt-get update && \ + apt-get install -y yarn php5-cli && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/* /tmp/* /var/tmp/* + + +# add php fixer +RUN curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.10.0/php-cs-fixer.phar -o /usr/local/bin/php-cs-fixer && \ + chmod a+x /usr/local/bin/php-cs-fixer + +WORKDIR /app + +# add csscomb and prettier +RUN yarn add prettier csscomb --global && \ + ln -s /app/node_modules/.bin/prettier /usr/local/bin/prettier && \ + ln -s /app/node_modules/.bin/csscomb /usr/local/bin/csscomb + +COPY ["src/entry.sh", "/app/entry.sh"] + +COPY ["src/inc", "/app/inc"] + +WORKDIR /code + + +CMD ["/app/entry.sh"] +ENTRYPOINT ["/app/entry.sh"] + + +ARG VERSION +ARG COMMIT_SHA +ENV VERSION=$VERSION +ENV COMMIT_SHA=$COMMIT_SHA diff --git a/code-formatter/Makefile b/code-formatter/Makefile index d078e2c..c4ce603 100644 --- a/code-formatter/Makefile +++ b/code-formatter/Makefile @@ -17,13 +17,15 @@ GIT_TAG = $(shell git describe --tags --exact-match 2>/dev/null) VERSION := $(or $(GIT_TAG),latest) -all : VERSION := 1.0.1 +all : VERSION := 1.0.2 all : build release .PHONY : all build : - docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT_SHA=$(COMMIT) -t $(DOCKER_REGISTRY)/$(APP_NAME):$(VERSION) . + docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT_SHA=$(COMMIT) -t $(DOCKER_REGISTRY)/$(APP_NAME):$(VERSION)-php7.2 . + docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT_SHA=$(COMMIT) -t $(DOCKER_REGISTRY)/$(APP_NAME):$(VERSION)-php5.6 . + docker tag $(DOCKER_REGISTRY)/$(APP_NAME):$(VERSION)-php7.2 $(DOCKER_REGISTRY)/$(APP_NAME):$(VERSION) release : build docker push $(DOCKER_REGISTRY)/$(APP_NAME):$(VERSION) diff --git a/code-formatter/src/inc/formatters/php-cs-fixer.shinc b/code-formatter/src/inc/formatters/php-cs-fixer.shinc index 8f0d500..c50c4b1 100644 --- a/code-formatter/src/inc/formatters/php-cs-fixer.shinc +++ b/code-formatter/src/inc/formatters/php-cs-fixer.shinc @@ -3,13 +3,18 @@ __phpFixer() { local failed=0 + local args="" __msg "PHP-cs-fixer" + if [[ ${VERBOSE} -eq 1 ]]; then + args="${args} -vvv" + fi + # Cannot chain php files without specifying a config CS file :( if [[ ${DRY_RUN} -eq 0 ]]; then for file in "${PHP_FILES[@]}"; do - php-cs-fixer fix "${file}" + php-cs-fixer ${args} fix "${file}" [[ $? -ne 0 ]] && failed=1 done else @@ -17,7 +22,7 @@ __phpFixer() { local invalid_syntax=() for file in "${PHP_FILES[@]}"; do - php-cs-fixer fix --dry-run "${file}" + php-cs-fixer ${args} fix --dry-run "${file}" case $? in 0) #all good diff --git a/code-formatter/src/inc/variables.shinc b/code-formatter/src/inc/variables.shinc index dfb2773..f458513 100644 --- a/code-formatter/src/inc/variables.shinc +++ b/code-formatter/src/inc/variables.shinc @@ -11,7 +11,7 @@ PHP_FILES=() DRY_RUN=0 - +VERBOSE=0 __initVariables() { @@ -21,6 +21,9 @@ __initVariables() { --dry-run) DRY_RUN=1 ;; + --verbose) + VERBOSE=1 + ;; *.css|*.scss|*.sass|*.less) __path_exists "${1}" if [[ $? -ne 0 ]]; then