diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..11a8bdc --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,200 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: build + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs on Pull Requests + pull_request: + # Runs on Push + push: + + +# ------------------------------------------------------------------------------------------------- +# What to run +# ------------------------------------------------------------------------------------------------- +jobs: + build: + name: "[ ${{ matrix.version }} ]" + runs-on: ubuntu-latest + strategy: + fail-fast: False + matrix: + version: + - 'PCF-latest PHP-latest' + - 'PCF-latest PHP-8.0' + - 'PCF-latest PHP-7.4' + - 'PCF-latest PHP-7.3' + - 'PCF-latest PHP-7.2' + - 'PCF-latest PHP-7.1' + - 'PCF-latest PHP-7.0' + - 'PCF-latest PHP-5.6' + + - 'PCF-2 PHP-latest' + - 'PCF-2 PHP-8.0' + - 'PCF-2 PHP-7.4' + - 'PCF-2 PHP-7.3' + - 'PCF-2 PHP-7.2' + - 'PCF-2 PHP-7.1' + - 'PCF-2 PHP-7.0' + - 'PCF-2 PHP-5.6' + + - 'PCF-1 PHP-latest' + - 'PCF-1 PHP-7.1' + - 'PCF-1 PHP-7.0' + - 'PCF-1 PHP-5.6' + steps: + + # ------------------------------------------------------------ + # Checkout repository + # ------------------------------------------------------------ + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set variables + id: vars + run: | + + PCF_VERSION="$( echo "${VERSION}" | awk '{print $1}' | sed 's/PCF\-//g' )" + PHP_VERSION="$( echo "${VERSION}" | awk '{print $2}' | sed 's/PHP\-//g' )" + + if [ "${PCF_VERSION}" = "latest" ] && [ "${PHP_VERSION}" = "latest" ]; then + TAG=latest + elif [ "${PHP_VERSION}" = "latest" ]; then + TAG="${PCF_VERSION}" + else + TAG="${PCF_VERSION}-php${PHP_VERSION}" + fi + + # Retrieve git info (tags, etc) + git fetch --all + + # Branch, Tag or Commit + GIT_TYPE="$( \ + curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ + | sh \ + | grep '^GIT_TYPE' \ + | sed 's|.*=||g' \ + )" + # Branch name, Tag name or Commit Hash + GIT_SLUG="$( \ + curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ + | sh \ + | grep '^GIT_NAME' \ + | sed 's|.*=||g' \ + )" + # Docker Tag + if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then + DOCKER_TAG="${TAG}" + else + DOCKER_TAG="${TAG}-${GIT_SLUG}" + fi + + # Output + echo "GIT_TYPE=${GIT_TYPE}" + echo "GIT_SLUG=${GIT_SLUG}" + echo "DOCKER_TAG=${DOCKER_TAG}" + echo "PCF_VERSION=${PCF_VERSION}" + echo "PHP_VERSION=${PHP_VERSION}" + + # Export variable + # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files + echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} + echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} + echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} + echo "PCF_VERSION=${PCF_VERSION}" >> ${GITHUB_ENV} + echo "PHP_VERSION=${PHP_VERSION}" >> ${GITHUB_ENV} + env: + VERSION: ${{ matrix.version }} + + + # ------------------------------------------------------------ + # Build + # ------------------------------------------------------------ + - name: Build + run: | + retry() { + for n in $(seq ${RETRIES}); do + echo "[${n}/${RETRIES}] ${*}"; + if eval "${*}"; then + echo "[SUCC] ${n}/${RETRIES}"; + return 0; + fi; + sleep 2; + echo "[FAIL] ${n}/${RETRIES}"; + done; + return 1; + } + retry make build PHP=${PHP_VERSION} PCF=${PCF_VERSION} + env: + RETRIES: 20 + + - name: Test + run: | + retry() { + for n in $(seq ${RETRIES}); do + echo "[${n}/${RETRIES}] ${*}"; + if eval "${*}"; then + echo "[SUCC] ${n}/${RETRIES}"; + return 0; + fi; + sleep 2; + echo "[FAIL] ${n}/${RETRIES}"; + done; + return 1; + } + retry make test PHP=${PHP_VERSION} PCF=${PCF_VERSION} + env: + RETRIES: 20 + + + # ------------------------------------------------------------ + # Deploy + # ------------------------------------------------------------ + - name: Publish images (only repo owner) + run: | + retry() { + for n in $(seq ${RETRIES}); do + echo "[${n}/${RETRIES}] ${*}"; + if eval "${*}"; then + echo "[SUCC] ${n}/${RETRIES}"; + return 0; + fi; + sleep ${PAUSE}; + echo "[FAIL] ${n}/${RETRIES}"; + done; + return 1; + } + + # Output + echo "GIT_TYPE=${GIT_TYPE}" + echo "GIT_SLUG=${GIT_SLUG}" + echo "DOCKER_TAG=${DOCKER_TAG}" + + # Tag image + retry make tag TAG=${DOCKER_TAG} + docker images + + # Login and Push + retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} + retry make push TAG=${DOCKER_TAG} + env: + RETRIES: 20 + PAUSE: 10 + # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions + if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id + && ( + (github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) + || + (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) + || + (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-')) + ) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..5443ecc --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,38 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: lint + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs on Pull Requests + pull_request: + + +# ------------------------------------------------------------------------------------------------- +# What to run +# ------------------------------------------------------------------------------------------------- +jobs: + lint: + name: "Lint" + runs-on: ubuntu-latest + steps: + # ------------------------------------------------------------ + # Setup repository + # ------------------------------------------------------------ + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # ------------------------------------------------------------ + # Lint repository + # ------------------------------------------------------------ + - name: Lint + run: | + make lint diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..6b40bde --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,202 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: nightly + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs daily + schedule: + - cron: '0 0 * * *' + + +# ------------------------------------------------------------------------------------------------- +# What to run +# ------------------------------------------------------------------------------------------------- +jobs: + nightly: + name: "[ ${{ matrix.version }} ] (ref: ${{ matrix.refs }})" + runs-on: ubuntu-latest + strategy: + fail-fast: False + matrix: + version: + - 'PCF-latest PHP-latest' + - 'PCF-latest PHP-8.0' + - 'PCF-latest PHP-7.4' + - 'PCF-latest PHP-7.3' + - 'PCF-latest PHP-7.2' + - 'PCF-latest PHP-7.1' + - 'PCF-latest PHP-7.0' + - 'PCF-latest PHP-5.6' + + - 'PCF-2 PHP-latest' + - 'PCF-2 PHP-8.0' + - 'PCF-2 PHP-7.4' + - 'PCF-2 PHP-7.3' + - 'PCF-2 PHP-7.2' + - 'PCF-2 PHP-7.1' + - 'PCF-2 PHP-7.0' + - 'PCF-2 PHP-5.6' + + - 'PCF-1 PHP-latest' + - 'PCF-1 PHP-7.1' + - 'PCF-1 PHP-7.0' + - 'PCF-1 PHP-5.6' + refs: + - 'master' + steps: + + # ------------------------------------------------------------ + # Checkout repository + # ------------------------------------------------------------ + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + ref: ${{ matrix.refs }} + + - name: Set variables + id: vars + run: | + + PCF_VERSION="$( echo "${VERSION}" | awk '{print $1}' | sed 's/PCF\-//g' )" + PHP_VERSION="$( echo "${VERSION}" | awk '{print $2}' | sed 's/PHP\-//g' )" + + if [ "${PCF_VERSION}" = "latest" ] && [ "${PHP_VERSION}" = "latest" ]; then + TAG=latest + elif [ "${PHP_VERSION}" = "latest" ]; then + TAG="${PCF_VERSION}" + else + TAG="${PCF_VERSION}-php${PHP_VERSION}" + fi + + # Retrieve git info (tags, etc) + git fetch --all + + # Branch, Tag or Commit + GIT_TYPE="$( \ + curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ + | sh \ + | grep '^GIT_TYPE' \ + | sed 's|.*=||g' \ + )" + # Branch name, Tag name or Commit Hash + GIT_SLUG="$( \ + curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ + | sh \ + | grep '^GIT_NAME' \ + | sed 's|.*=||g' \ + )" + # Docker Tag + if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then + DOCKER_TAG="${TAG}" + else + DOCKER_TAG="${TAG}-${GIT_SLUG}" + fi + + # Output + echo "GIT_TYPE=${GIT_TYPE}" + echo "GIT_SLUG=${GIT_SLUG}" + echo "DOCKER_TAG=${DOCKER_TAG}" + echo "PCF_VERSION=${PCF_VERSION}" + echo "PHP_VERSION=${PHP_VERSION}" + + # Export variable + # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files + echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} + echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} + echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} + echo "PCF_VERSION=${PCF_VERSION}" >> ${GITHUB_ENV} + echo "PHP_VERSION=${PHP_VERSION}" >> ${GITHUB_ENV} + env: + VERSION: ${{ matrix.version }} + + + # ------------------------------------------------------------ + # Build + # ------------------------------------------------------------ + - name: Build + run: | + retry() { + for n in $(seq ${RETRIES}); do + echo "[${n}/${RETRIES}] ${*}"; + if eval "${*}"; then + echo "[SUCC] ${n}/${RETRIES}"; + return 0; + fi; + sleep 2; + echo "[FAIL] ${n}/${RETRIES}"; + done; + return 1; + } + retry make build PHP=${PHP_VERSION} PCF=${PCF_VERSION} + env: + RETRIES: 20 + + - name: Test + run: | + retry() { + for n in $(seq ${RETRIES}); do + echo "[${n}/${RETRIES}] ${*}"; + if eval "${*}"; then + echo "[SUCC] ${n}/${RETRIES}"; + return 0; + fi; + sleep 2; + echo "[FAIL] ${n}/${RETRIES}"; + done; + return 1; + } + retry make test PHP=${PHP_VERSION} PCF=${PCF_VERSION} + env: + RETRIES: 20 + + + # ------------------------------------------------------------ + # Deploy + # ------------------------------------------------------------ + - name: Publish images (only repo owner) + run: | + retry() { + for n in $(seq ${RETRIES}); do + echo "[${n}/${RETRIES}] ${*}"; + if eval "${*}"; then + echo "[SUCC] ${n}/${RETRIES}"; + return 0; + fi; + sleep ${PAUSE}; + echo "[FAIL] ${n}/${RETRIES}"; + done; + return 1; + } + + # Output + echo "GIT_TYPE=${GIT_TYPE}" + echo "GIT_SLUG=${GIT_SLUG}" + echo "DOCKER_TAG=${DOCKER_TAG}" + + # Tag image + retry make tag TAG=${DOCKER_TAG} + docker images + + # Login and Push + retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} + retry make push TAG=${DOCKER_TAG} + env: + RETRIES: 20 + PAUSE: 10 + # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions + if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id + && ( + (github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) + || + (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) + || + (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-')) + ) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 21d7a5b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,111 +0,0 @@ ---- - -### -### Enable sudo (required for docker service) -### -sudo: required - - -### -### Language -### -language: minimal - - -### -### 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: - - retry() { - for ((n=0; n<10; n++)); do - echo "[${n}] ${*}"; - if eval "${*}"; then - return 0; - fi; - done; - return 1; - } - - -### -### Check generation changes, build and test -### -before_script: - - retry make lint - - retry make build PCF=${PCF} PHP=${PHP} - - retry make test PCF=${PCF} PHP=${PHP} - - -### -### 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 diff --git a/Dockerfile b/Dockerfile index 21aff70..a94d8fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG PHP -FROM php:7.1 as builder +FROM php:${PHP}-cli as builder # Install build dependencies RUN set -eux \ @@ -14,10 +14,11 @@ ARG PCF RUN set -eux \ && cd PHP-CS-Fixer \ && if [ "${PCF}" = "latest" ]; then \ - VERSION="$( git tag | sort -V | tail -1 )"; \ + VERSION="$( git tag | grep -E '^v?[.0-9]+$' | sort -V | tail -1 )"; \ else \ VERSION="$( git tag | grep -E "^v?${PCF}\.[.0-9]+\$" | sort -V | tail -1 )"; \ fi \ + && echo "Version: ${VERSION}" \ && 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 @@ -26,7 +27,8 @@ RUN set -eux \ && php-cs-fixer --version -FROM php:${PHP} as production +ARG PHP +FROM php:${PHP}-cli-alpine as production LABEL \ maintainer="cytopia " \ repo="https://github.com/cytopia/docker-php-cs-fixer" diff --git a/Makefile b/Makefile index caa3737..286fee6 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,11 @@ ifneq (,) .error This Makefile requires GNU Make. endif -.PHONY: build rebuild lint test _test-php-cs-fixer-version _test-php-version _test-run _get-php-version tag pull login push enter +.PHONY: lint build rebuild test +# -------------------------------------------------------------------------------------------------- +# VARIABLES +# -------------------------------------------------------------------------------------------------- CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) CURRENT_PHP_VERSION = @@ -11,55 +14,73 @@ DIR = . FILE = Dockerfile IMAGE = cytopia/php-cs-fixer TAG = latest +NO_CACHE = PHP = latest PCF = latest +PHP_LATEST = $(shell \ + while ! DATA="$$( curl -sS --fail 'https://github.com/docker-library/php' )"; do \ + sleep 1; \ + done; \ + echo "$${DATA}" | grep -Eo 'php/tree/master/[.0-9]+"' | grep -Eo '[.0-9]+' | sort | tail -1 \ +) + + +# -------------------------------------------------------------------------------------------------- +# DEFAULT TARGET +# -------------------------------------------------------------------------------------------------- +help: + @echo "lint Lint repository files" + @echo "build [PHP=] [PCF=] Build image with PHP and PCF version" + @echo "test [PHP=] [PCF=] Test image with PHP and PCF version" + + +# -------------------------------------------------------------------------------------------------- +# LINT TARGETS +# -------------------------------------------------------------------------------------------------- +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 . + + +# -------------------------------------------------------------------------------------------------- +# BUILD TARGETS +# -------------------------------------------------------------------------------------------------- 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) + docker build $(NO_CACHE) --build-arg PHP=7.1 --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) + docker build $(NO_CACHE) --build-arg PHP=$(PHP) --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) + docker build $(NO_CACHE) --build-arg PHP=$(PHP_LATEST) --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) + docker build $(NO_CACHE) --build-arg PHP=$(PHP) --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 +rebuild: _pull +rebuild: NO_CACHE=--no-cache +rebuild: build -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 TARGETS +# -------------------------------------------------------------------------------------------------- test: @$(MAKE) --no-print-directory _test-php-cs-fixer-version @$(MAKE) --no-print-directory _test-php-version @$(MAKE) --no-print-directory _test-run +.PHONY: _test-php-cs-fixer-version _test-php-cs-fixer-version: @echo "------------------------------------------------------------" @echo "- Testing correct phpcs version" @@ -88,6 +109,7 @@ _test-php-cs-fixer-version: fi; \ echo "Success"; \ +.PHONY: _test-php-version _test-php-version: _get-php-version @echo "------------------------------------------------------------" @echo "- Testing correct PHP version" @@ -107,6 +129,7 @@ _test-php-version: _get-php-version fi; \ echo "Success"; \ +.PHONY: _test-run _test-run: @echo "------------------------------------------------------------" @echo "- Testing phpcs (success)" @@ -125,45 +148,30 @@ _test-run: fi; \ echo "Success"; -tag: - docker tag $(IMAGE) $(IMAGE):$(TAG) -pull: +# -------------------------------------------------------------------------------------------------- +# HELPER TARGETS +# -------------------------------------------------------------------------------------------------- +.PHONY: _pull +_pull: @echo "Pull base image" - @grep -E '^\s*FROM' Dockerfile \ - | sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \ - | head -1 \ - | xargs -n1 docker pull; - @echo "Pull target image" ifeq ($(PCF),1) ifeq ($(PHP),latest) @# PHP CS Fixer version 1 goes only up to PHP 7.1 - docker pull php:7.1-cli-alpine + docker pull php:7.1 else docker pull php:$(PHP)-cli-alpine endif else ifeq ($(PHP),latest) - docker pull php:7-cli-alpine + docker pull php:$(PHP_LATEST)-cli-alpine else docker pull php:$(PHP)-cli-alpine endif endif - - - -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) - # Fetch latest available PHP version for cli-alpine +.PHONY: _get-php-version _get-php-version: $(eval CURRENT_PHP_VERSION = $(shell \ if [ "$(PHP)" = "latest" ]; then \ @@ -177,3 +185,20 @@ _get-php-version: echo $(PHP); \ fi; \ )) + + +# -------------------------------------------------------------------------------------------------- +# DEPLOY TARGETS +# -------------------------------------------------------------------------------------------------- +.PHONY: tag +tag: + docker tag $(IMAGE) $(IMAGE):$(TAG) + +.PHONY: login +login: + yes | docker login --username $(USER) --password $(PASS) + +.PHONY: push +push: + @$(MAKE) tag TAG=$(TAG) + docker push $(IMAGE):$(TAG) diff --git a/README.md b/README.md index 662fff3..0b855fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Docker image for `php-cs-fixer` -[![Build Status](https://travis-ci.com/cytopia/docker-php-cs-fixer.svg?branch=master)](https://travis-ci.com/cytopia/docker-php-cs-fixer) [![Tag](https://img.shields.io/github/tag/cytopia/docker-php-cs-fixer.svg)](https://github.com/cytopia/docker-php-cs-fixer/releases) [![](https://images.microbadger.com/badges/version/cytopia/php-cs-fixer:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/php-cs-fixer:latest "php-cs-fixer") [![](https://images.microbadger.com/badges/image/cytopia/php-cs-fixer:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/php-cs-fixer:latest "php-cs-fixer") @@ -8,11 +7,16 @@ [![](https://img.shields.io/badge/github-cytopia%2Fdocker--php--cs--fixer-red.svg)](https://github.com/cytopia/docker-php-cs-fixer "github.com/cytopia/docker-php-cs-fixer") [![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT) +[![lint](https://github.com/cytopia/docker-php-cs-fixer/workflows/lint/badge.svg)](https://github.com/cytopia/docker-php-cs-fixer/actions?query=workflow%3Alint) +[![build](https://github.com/cytopia/docker-php-cs-fixer/workflows/build/badge.svg)](https://github.com/cytopia/docker-php-cs-fixer/actions?query=workflow%3Abuild) +[![nightly](https://github.com/cytopia/docker-php-cs-fixer/workflows/nightly/badge.svg)](https://github.com/cytopia/docker-php-cs-fixer/actions?query=workflow%3Anightly) + > #### All [#awesome-ci](https://github.com/topics/awesome-ci) Docker images > -> [ansible][ansible-git-lnk] **•** > [ansible-lint][alint-git-lnk] **•** +> [ansible][ansible-git-lnk] **•** > [awesome-ci][aci-git-lnk] **•** +> [bandit][bandit-git-lnk] **•** > [black][black-git-lnk] **•** > [checkmake][cm-git-lnk] **•** > [eslint][elint-git-lnk] **•** @@ -23,16 +27,16 @@ > [jsonlint][jlint-git-lnk] **•** > [linkcheck][linkcheck-git-lnk] **•** > [mypy][mypy-git-lnk] **•** +> [php-cs-fixer][pcsf-git-lnk] **•** > [phpcbf][pcbf-git-lnk] **•** > [phpcs][pcs-git-lnk] **•** > [phplint][plint-git-lnk] **•** -> [php-cs-fixer][pcsf-git-lnk] **•** > [pycodestyle][pycs-git-lnk] **•** > [pydocstyle][pyds-git-lnk] **•** > [pylint][pylint-git-lnk] **•** > [terraform-docs][tfdocs-git-lnk] **•** -> [terragrunt][tg-git-lnk] **•** > [terragrunt-fmt][tgfmt-git-lnk] **•** +> [terragrunt][tg-git-lnk] **•** > [yamlfmt][yfmt-git-lnk] **•** > [yamllint][ylint-git-lnk] @@ -55,9 +59,11 @@ The image is built nightly against multiple stable versions and pushed to Docker Docker images for PHP Coding Standards Fixer come with all available PHP versions. In doubt use `latest` tag. #### Latest stable php-cs-fixer version -| Docker tag | php-cs-fixer version | PHP version | +| Docker tag | php-cs-fixer version | PHP version | |-----------------|-----------------------|-----------------------| | `latest` | latest stable | latest stable | +| `latest-php8.0` | latest stable | latest stable `8.0.x` | +| `latest-php7.4` | latest stable | latest stable `7.4.x` | | `latest-php7.3` | latest stable | latest stable `7.3.x` | | `latest-php7.2` | latest stable | latest stable `7.2.x` | | `latest-php7.1` | latest stable | latest stable `7.1.x` | @@ -65,9 +71,11 @@ Docker images for PHP Coding Standards Fixer come with all available PHP version | `latest-php5.6` | latest stable | latest stable `5.6.x` | #### Latest stable php-cs-fixer `2.x.x` version -| Docker tag | php-cs-fixer version | PHP version | +| Docker tag | php-cs-fixer version | PHP version | |-----------------|-----------------------|-----------------------| | `2` | latest stable `2.x.x` | latest stable | +| `2-php8.0` | latest stable `2.x.x` | latest stable `8.0.x` | +| `2-php7.4` | latest stable `2.x.x` | latest stable `7.4.x` | | `2-php7.3` | latest stable `2.x.x` | latest stable `7.3.x` | | `2-php7.2` | latest stable `2.x.x` | latest stable `7.2.x` | | `2-php7.1` | latest stable `2.x.x` | latest stable `7.1.x` | @@ -75,7 +83,7 @@ Docker images for PHP Coding Standards Fixer come with all available PHP version | `2-php5.6` | latest stable `2.x.x` | latest stable `5.6.x` | #### Latest stable php-cs-fixer `1.x.x` version -| Docker tag | php-cs-fixer version | PHP version | +| Docker tag | php-cs-fixer version | PHP version | |-----------------|-----------------------|-----------------------| | `1` | latest stable `1.x.x` | latest stable supported version | | `1-php7.1` | latest stable `1.x.x` | latest stable `7.1.x` | @@ -145,11 +153,8 @@ Using cache file ".php_cs.cache". +if (1 ==2) { + echo "asd"; +} - - ----------- end diff ----------- - Checked all files in 0.004 seconds, 10.000 MB memory used ``` @@ -226,6 +231,7 @@ linter below for reproducible local or remote CI tests: | [phpcs][pcs-git-lnk] | [![pcs-hub-img]][pcs-hub-lnk] | PHP | PHP Code Sniffer | | [phplint][plint-git-lnk] | [![plint-hub-img]][plint-hub-lnk] | PHP | PHP Code Linter **[1]** | | [php-cs-fixer][pcsf-git-lnk] | [![pcsf-hub-img]][pcsf-hub-lnk] | PHP | PHP Coding Standards Fixer | +| [bandit][bandit-git-lnk] | [![bandit-hub-img]][bandit-hub-lnk] | Python | A security linter from PyCQA | [black][black-git-lnk] | [![black-hub-img]][black-hub-lnk] | Python | The uncompromising Python code formatter | | [mypy][mypy-git-lnk] | [![mypy-hub-img]][mypy-hub-lnk] | Python | Static source code analysis | | [pycodestyle][pycs-git-lnk] | [![pycs-hub-img]][pycs-hub-lnk] | Python | Python style guide checker | @@ -299,6 +305,10 @@ linter below for reproducible local or remote CI tests: [pcsf-hub-img]: https://img.shields.io/docker/pulls/cytopia/php-cs-fixer.svg [pcsf-hub-lnk]: https://hub.docker.com/r/cytopia/php-cs-fixer +[bandit-git-lnk]: https://github.com/cytopia/docker-bandit +[bandit-hub-img]: https://img.shields.io/docker/pulls/cytopia/bandit.svg +[bandit-hub-lnk]: https://hub.docker.com/r/cytopia/bandit + [black-git-lnk]: https://github.com/cytopia/docker-black [black-hub-img]: https://img.shields.io/docker/pulls/cytopia/black.svg [black-hub-lnk]: https://hub.docker.com/r/cytopia/black