diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8e85703 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +--- +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..9a507e8 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,12 @@ +# The labels in this file are automatically synced with the repository +# using the micnncim/action-label-syncer action. +--- +- name: C-dependency + color: 1abc9c + description: "Category: Dependency" +- name: PR-block + color: 3498db + description: "Pull Request: Do not merge" +- name: PR-merge + color: 3498db + description: "Pull Request: Merge when ready" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..03439b4 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,33 @@ +--- +name-template: '$RESOLVED_VERSION 🌈' +tag-template: '$RESOLVED_VERSION' +version-template: '$MAJOR.$MINOR' +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧰 Maintenance' + label: 'chore' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: minor +template: | + ## Changes + + $CHANGES diff --git a/.github/workflows/action_branch.yml b/.github/workflows/action_branch.yml new file mode 100644 index 0000000..08a0c91 --- /dev/null +++ b/.github/workflows/action_branch.yml @@ -0,0 +1,38 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: build + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + push: + paths: + - 'Makefile' + - 'Dockerfiles/**' + - 'tests/**' + - '.github/workflows/action*.yml' + - '.github/workflows/params.yml' + +jobs: + + # (1/2) Determine repository params + params: + uses: ./.github/workflows/params.yml + + # (2/2) Build + docker: + needs: [params] + uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master + with: + enabled: true + can_deploy: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release-') }} + matrix: ${{ needs.params.outputs.matrix }} + refs: ${{ needs.params.outputs.refs }} + secrets: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }} diff --git a/.github/workflows/action_pull_request.yml b/.github/workflows/action_pull_request.yml new file mode 100644 index 0000000..21b075b --- /dev/null +++ b/.github/workflows/action_pull_request.yml @@ -0,0 +1,35 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: build + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + pull_request: + + +jobs: + + # (1/2) Determine repository params + params: + uses: ./.github/workflows/params.yml + # Only run for forks (contributor) + if: github.event.pull_request.head.repo.fork + + # (2/2) Build + docker: + needs: [params] + uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master + with: + enabled: true + can_deploy: false + matrix: ${{ needs.params.outputs.matrix }} + refs: ${{ needs.params.outputs.refs }} + secrets: + dockerhub_username: "" + dockerhub_password: "" diff --git a/.github/workflows/action_schedule.yml b/.github/workflows/action_schedule.yml new file mode 100644 index 0000000..c25dfa2 --- /dev/null +++ b/.github/workflows/action_schedule.yml @@ -0,0 +1,35 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: nightly + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs daily + schedule: + - cron: '0 0 * * *' + + +jobs: + + # (1/2) Determine repository params + params: + uses: ./.github/workflows/params.yml + + # (2/2) Build + docker: + needs: [params] + uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master + with: + enabled: true + can_deploy: true + matrix: ${{ needs.params.outputs.matrix }} + refs: ${{ needs.params.outputs.refs }} + secrets: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..f83d099 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,22 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: lint + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs on Pull Requests + pull_request: + + +# ------------------------------------------------------------------------------------------------- +# What to run +# ------------------------------------------------------------------------------------------------- +jobs: + lint: + uses: devilbox/github-actions/.github/workflows/lint-generic.yml@master diff --git a/.github/workflows/params.yml b/.github/workflows/params.yml new file mode 100644 index 0000000..58823aa --- /dev/null +++ b/.github/workflows/params.yml @@ -0,0 +1,99 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: params + + +# ------------------------------------------------------------------------------------------------- +# Custom Variables +# ------------------------------------------------------------------------------------------------- +env: + MATRIX: >- + [ + { + "NAME": "pcs", + "VERSION": [ + "latest", + + "PCS-latest PHP-latest", + "PCS-latest PHP-8.1", + "PCS-latest PHP-8.0", + "PCS-latest PHP-7.4", + "PCS-latest PHP-7.3", + "PCS-latest PHP-7.2", + "PCS-latest PHP-7.1", + "PCS-latest PHP-7.0", + "PCS-latest PHP-5.6", + + "PCS-3 PHP-latest", + "PCS-3 PHP-8.1", + "PCS-3 PHP-8.0", + "PCS-3 PHP-7.4", + "PCS-3 PHP-7.3", + "PCS-3 PHP-7.2", + "PCS-3 PHP-7.1", + "PCS-3 PHP-7.0", + "PCS-3 PHP-5.6", + + "PCS-2 PHP-7.4", + "PCS-2 PHP-7.3", + "PCS-2 PHP-7.2", + "PCS-2 PHP-7.1", + "PCS-2 PHP-7.0", + "PCS-2 PHP-5.6" + ], + "FLAVOUR": ["latest"], + "ARCH": ["linux/amd64", "linux/386", "linux/arm64"] + } + ] + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + workflow_call: + outputs: + matrix: + description: "The determined version matrix" + value: ${{ jobs.params.outputs.matrix }} + refs: + description: "The determined git ref matrix (only during scheduled run)" + value: ${{ jobs.params.outputs.refs }} + +jobs: + params: + runs-on: ubuntu-latest + + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + refs: ${{ steps.set-refs.outputs.matrix }} + + steps: + - name: "[Set-Output] Matrix" + id: set-matrix + run: | + echo "matrix=$( echo '${{ env.MATRIX }}' | jq -M -c )" >> $GITHUB_OUTPUT + + - name: "[Set-Output] Matrix 'Refs' (master branch and latest tag)" + id: set-refs + uses: cytopia/git-ref-matrix-action@v0.1.12 + with: + repository_default_branch: master + branches: master + num_latest_tags: 0 + if: github.event_name == 'schedule' + + - name: "[DEBUG] Show settings'" + run: | + echo 'Matrix' + echo '--------------------' + echo '${{ steps.set-matrix.outputs.matrix }}' + echo + + echo 'Matrix: Refs' + echo '--------------------' + echo '${{ steps.set-matrix-refs.outputs.matrix }}' + echo diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..1a63d7e --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,19 @@ +--- +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - master + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5 + with: + publish: true + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_DRAFTER_TOKEN }} diff --git a/.github/workflows/repository.yml b/.github/workflows/repository.yml new file mode 100644 index 0000000..ca21e7d --- /dev/null +++ b/.github/workflows/repository.yml @@ -0,0 +1,25 @@ +--- +name: Repository + +on: + push: + branches: + - master + paths: + - .github/labels.yml + +jobs: + labels: + name: Labels + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Sync labels + uses: micnncim/action-label-syncer@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + manifest: .github/labels.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7457dff --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Makefile.docker +Makefile.lint diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ec90804..0000000 --- a/.travis.yml +++ /dev/null @@ -1,116 +0,0 @@ ---- - -### -### Enable sudo (required for docker service) -### -sudo: required - - -### -### Language -### -language: minimal - - -### -### Add services -### -services: - - docker - - -### -### Build Matrix -### -env: - matrix: - - PHPCS=2 PHP=5.6 - - PHPCS=3 PHP=5.6 - - PHPCS=latest PHP=5.6 - - PHPCS=2 PHP=7.0 - - PHPCS=3 PHP=7.0 - - PHPCS=latest PHP=7.0 - - PHPCS=2 PHP=7.1 - - PHPCS=3 PHP=7.1 - - PHPCS=latest PHP=7.1 - - PHPCS=2 PHP=7.2 - - PHPCS=3 PHP=7.2 - - PHPCS=latest PHP=7.2 - - PHPCS=2 PHP=7.3 - - PHPCS=3 PHP=7.3 - - PHPCS=latest PHP=7.3 - - PHPCS=2 PHP=7.4 - - PHPCS=3 PHP=7.4 - - PHPCS=latest PHP=7.4 - - PHPCS=2 PHP=latest - - PHPCS=3 PHP=latest - - PHPCS=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 PHPCS=${PHPCS} PHP=${PHP} - - retry make test PHPCS=${PHPCS} 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 [ "${PHPCS}" == "latest" ] && [ "${PHP}" == "latest" ]; then - while ! make push TAG="latest-${TRAVIS_TAG}"; do sleep 1; done; - else - if [ "${PHP}" == "latest" ]; then - while ! make push TAG="${PHPCS}-${TRAVIS_TAG}"; do sleep 1; done; - else - while ! make push TAG="${PHPCS}-php${PHP}-${TRAVIS_TAG}"; do sleep 1; done; - fi - fi - elif [ "${TRAVIS_BRANCH}" == "master" ]; then - if [ "${PHPCS}" == "latest" ] && [ "${PHP}" == "latest" ]; then - while ! make push TAG=latest; do sleep 1; done; - else - if [ "${PHP}" == "latest" ]; then - while ! make push TAG=${PHPCS}; do sleep 1; done; - else - while ! make push TAG=${PHPCS}-php${PHP}; do sleep 1; done; - fi - fi - elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then - if [ "${PHPCS}" == "latest" ] && [ "${PHP}" == "latest" ]; then - while ! make push TAG="latest-${TRAVIS_BRANCH}"; do sleep 1; done; - else - if [ "${PHP}" == "latest" ]; then - while ! make push TAG="${PHPCS}-${TRAVIS_BRANCH}"; do sleep 1; done; - else - while ! make push TAG="${PHPCS}-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/.yamllint b/.yamllint new file mode 100644 index 0000000..2c7758f --- /dev/null +++ b/.yamllint @@ -0,0 +1,13 @@ +--- +extends: default + +ignore: | + .yamllint + + +rules: + truthy: + allowed-values: ['true', 'false'] + check-keys: False + level: error + line-length: disable diff --git a/Dockerfile b/Dockerfiles/Dockerfile.latest similarity index 77% rename from Dockerfile rename to Dockerfiles/Dockerfile.latest index 8bec8ea..16809d3 100644 --- a/Dockerfile +++ b/Dockerfiles/Dockerfile.latest @@ -1,5 +1,5 @@ -ARG PHP -FROM php:7.3 as builder +ARG PHP_VERSION +FROM php:${PHP_VERSION} as builder # Install build dependencies RUN set -eux \ @@ -10,20 +10,20 @@ RUN set -eux \ git \ && git clone https://github.com/squizlabs/PHP_CodeSniffer -ARG PHPCS +ARG PCS_VERSION RUN set -eux \ && cd PHP_CodeSniffer \ - && if [ "${PHPCS}" = "latest" ]; then \ + && if [ "${PCS_VERSION}" = "latest" ]; then \ VERSION="$( git describe --abbrev=0 --tags )"; \ else \ - VERSION="$( git tag | grep -E "^v?${PHPCS}\.[.0-9]+\$" | sort -V | tail -1 )"; \ + VERSION="$( git tag | grep -E "^v?${PCS_VERSION}\.[.0-9]+\$" | sort -V | tail -1 )"; \ fi \ && curl -sS -L https://github.com/squizlabs/PHP_CodeSniffer/releases/download/${VERSION}/phpcs.phar -o /phpcs.phar \ && chmod +x /phpcs.phar \ && mv /phpcs.phar /usr/bin/phpcs -FROM php:${PHP} as production +FROM php:${PHP_VERSION} as production LABEL \ maintainer="cytopia " \ repo="https://github.com/cytopia/docker-phpcs" diff --git a/Makefile b/Makefile index 5fe51d8..e8fe092 100644 --- a/Makefile +++ b/Makefile @@ -2,90 +2,211 @@ ifneq (,) .error This Makefile requires GNU Make. endif -.PHONY: build rebuild lint test _test-phpcs-version _test-php-version _test-run _get-php-version tag pull login push enter - -CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) -CURRENT_PHP_VERSION = - -DIR = . -FILE = Dockerfile -IMAGE = cytopia/phpcs -TAG = latest - -PHP = latest -PHPCS = latest - -build: -ifeq ($(PHP),latest) - docker build --build-arg PHP=7-cli-alpine --build-arg PHPCS=$(PHPCS) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) +# Ensure additional Makefiles are present +MAKEFILES = Makefile.docker Makefile.lint +$(MAKEFILES): URL=https://raw.githubusercontent.com/devilbox/makefiles/master/$(@) +$(MAKEFILES): + @if ! (curl --fail -sS -o $(@) $(URL) || wget -O $(@) $(URL)); then \ + echo "Error, curl or wget required."; \ + echo "Exiting."; \ + false; \ + fi +include $(MAKEFILES) + +# Set default Target +.DEFAULT_GOAL := help + + +# ------------------------------------------------------------------------------------------------- +# Default configuration +# ------------------------------------------------------------------------------------------------- +# Own vars +TAG = latest + +# Makefile.docker overwrites +NAME = phpcs +VERSION = latest +IMAGE = cytopia/phpcs +FLAVOUR = latest +FILE = Dockerfile.${FLAVOUR} +DIR = Dockerfiles + +# Extract PHP- and PCS- version from VERSION string +ifeq ($(strip $(VERSION)),latest) + PHP_VERSION = latest + PCS_VERSION = latest else - docker build --build-arg PHP=$(PHP)-cli-alpine --build-arg PHPCS=$(PHPCS) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) + PHP_VERSION = $(subst PHP-,,$(shell echo "$(VERSION)" | grep -Eo 'PHP-([.0-9]+|latest)')) + PCS_VERSION = $(subst PCS-,,$(shell echo "$(VERSION)" | grep -Eo 'PCS-([.0-9]+|latest)')) endif -rebuild: pull -ifeq ($(PHP),latest) - docker build --no-cache --build-arg PHP=7-cli-alpine --build-arg PHPCS=$(PHPCS) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) +# Building from master branch: Tag == 'latest' +ifeq ($(strip $(TAG)),latest) + ifeq ($(strip $(VERSION)),latest) + DOCKER_TAG = $(FLAVOUR) + else + ifeq ($(strip $(FLAVOUR)),latest) + ifeq ($(strip $(PHP_VERSION)),latest) + DOCKER_TAG = $(PCS_VERSION) + else + DOCKER_TAG = $(PCS_VERSION)-php$(PHP_VERSION) + endif + else + ifeq ($(strip $(PHP_VERSION)),latest) + DOCKER_TAG = $(FLAVOUR)-$(PCS_VERSION) + else + DOCKER_TAG = $(FLAVOUR)-$(PCS_VERSION)-php$(PHP_VERSION) + endif + endif + endif +# Building from any other branch or tag: Tag == '' else - docker build --no-cache --build-arg PHP=$(PHP)-cli-alpine --build-arg PHPCS=$(PHPCS) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) + ifeq ($(strip $(VERSION)),latest) + ifeq ($(strip $(FLAVOUR)),latest) + DOCKER_TAG = latest-$(TAG) + else + DOCKER_TAG = $(FLAVOUR)-latest-$(TAG) + endif + else + ifeq ($(strip $(FLAVOUR)),latest) + ifeq ($(strip $(PHP_VERSION)),latest) + DOCKER_TAG = $(PCS_VERSION)-$(TAG) + else + DOCKER_TAG = $(PCS_VERSION)-php$(PHP_VERSION)-$(TAG) + endif + else + ifeq ($(strip $(PHP_VERSION)),latest) + DOCKER_TAG = $(FLAVOUR)-$(PCS_VERSION)-$(TAG) + else + DOCKER_TAG = $(FLAVOUR)-$(PCS_VERSION)-php$(PHP_VERSION)-$(TAG) + endif + endif + 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 . - +# Makefile.lint overwrites +FL_IGNORES = .git/,.github/,tests/ +SC_IGNORES = .git/,.github/,tests/ +JL_IGNORES = .git/,.github/,./tests/ + +out: + @echo "PHP: $(subst PHP-,,$(shell echo "$(VERSION)" | grep -Eo 'PHP-[.0-9]+'))" + @echo "PCS: $(subst PCS-,,$(shell echo "$(VERSION)" | grep -Eo 'PCS-[.0-9]+'))" + + +# ------------------------------------------------------------------------------------------------- +# Default Target +# ------------------------------------------------------------------------------------------------- +.PHONY: help +help: + @echo "lint Lint project files and repository" + @echo + @echo "build [ARCH=...] [TAG=...] Build Docker image" + @echo "rebuild [ARCH=...] [TAG=...] Build Docker image without cache" + @echo "push [ARCH=...] [TAG=...] Push Docker image to Docker hub" + @echo + @echo "manifest-create [ARCHES=...] [TAG=...] Create multi-arch manifest" + @echo "manifest-push [TAG=...] Push multi-arch manifest" + @echo + @echo "test [ARCH=...] Test built Docker image" + @echo + + +# ------------------------------------------------------------------------------------------------- +# Target Overrides +# ------------------------------------------------------------------------------------------------- +.PHONY: docker-pull-base-image +docker-pull-base-image: + @echo "################################################################################" + @echo "# Pulling Base Image php:$(PHP_VERSION) (platform: $(ARCH))" + @echo "################################################################################" + @echo "docker pull --platform $(ARCH) php:$(PHP_VERSION)"; \ + while ! docker pull --platform $(ARCH) php:$(PHP_VERSION); do sleep 1; done \ + + +# ------------------------------------------------------------------------------------------------- +# Docker Targets +# ------------------------------------------------------------------------------------------------- +.PHONY: build +build: ARGS+=--build-arg PCS_VERSION=$(PCS_VERSION) +build: ARGS+=--build-arg PHP_VERSION=$(PHP_VERSION) +build: docker-arch-build + +.PHONY: rebuild +rebuild: ARGS+=--build-arg PCS_VERSION=$(PCS_VERSION) +rebuild: ARGS+=--build-arg PHP_VERSION=$(PHP_VERSION) +rebuild: docker-arch-rebuild + +.PHONY: push +push: docker-arch-push + + +# ------------------------------------------------------------------------------------------------- +# Manifest Targets +# ------------------------------------------------------------------------------------------------- +.PHONY: manifest-create +manifest-create: docker-manifest-create + +.PHONY: manifest-push +manifest-push: docker-manifest-push + + +# ------------------------------------------------------------------------------------------------- +# Test Targets +# ------------------------------------------------------------------------------------------------- +.PHONY: test test: - @$(MAKE) --no-print-directory _test-phpcs-version - @$(MAKE) --no-print-directory _test-php-version - @$(MAKE) --no-print-directory _test-run +test: _test-phpcs-version +test: _test-php-version +test: _test-run +.PHONY: _test-phpcs-version _test-phpcs-version: @echo "------------------------------------------------------------" @echo "- Testing correct phpcs version" @echo "------------------------------------------------------------" - @if [ "$(PHPCS)" = "latest" ]; then \ + @if [ "$(PCS_VERSION)" = "latest" ]; then \ echo "Fetching latest version from GitHub"; \ LATEST="$$( \ curl -L -sS https://github.com/squizlabs/PHP_CodeSniffer/releases \ | tac | tac \ - | grep -Eo '/[.0-9]+?\.[.0-9]+/' \ + | grep -Eo '/[.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_CodeSniffer[[:space:]]+version[[:space:]]+v?$${LATEST}"; then \ + if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) --version | grep -E "^PHP_CodeSniffer[[:space:]]+version[[:space:]]+v?$${LATEST}"; then \ echo "Failed"; \ exit 1; \ fi; \ else \ - echo "Testing for tag: $(PHPCS).x.x"; \ - if ! docker run --rm $(IMAGE) --version | grep -E "^PHP_CodeSniffer[[:space:]]+version[[:space:]]+v?$(PHPCS)\.[.0-9]+"; then \ + echo "Testing for tag: $(PCS_VERSION).x.x"; \ + if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) --version | grep -E "^PHP_CodeSniffer[[:space:]]+version[[:space:]]+v?$(PCS_VERSION)\.[.0-9]+"; then \ echo "Failed"; \ exit 1; \ fi; \ fi; \ echo "Success"; \ +.PHONY: _test-php-version _test-php-version: _get-php-version @echo "------------------------------------------------------------" @echo "- Testing correct PHP version" @echo "------------------------------------------------------------" @echo "Testing for tag: $(CURRENT_PHP_VERSION)" - @if ! docker run --rm --entrypoint=php $(IMAGE) --version | head -1 | grep -E "^PHP[[:space:]]+$(CURRENT_PHP_VERSION)([.0-9]+)?"; then \ + @if ! docker run --rm --platform $(ARCH) --entrypoint=php $(IMAGE):$(DOCKER_TAG) --version | head -1 | grep -E "^PHP[[:space:]]+$(CURRENT_PHP_VERSION)([.0-9]+)?"; then \ echo "Failed"; \ exit 1; \ fi; \ echo "Success"; +.PHONY: _test-run _test-run: @echo "------------------------------------------------------------" @echo "- Testing phpcs (success)" @echo "------------------------------------------------------------" - @if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) .; then \ + @if ! docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE):$(DOCKER_TAG) .; then \ echo "Failed"; \ exit 1; \ fi; \ @@ -93,35 +214,14 @@ _test-run: @echo "------------------------------------------------------------" @echo "- Testing phpcs (failure)" @echo "------------------------------------------------------------" - @if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) .; then \ + @if docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE):$(DOCKER_TAG) .; then \ echo "Failed"; \ exit 1; \ fi; \ echo "Success"; -tag: - docker tag $(IMAGE) $(IMAGE):$(TAG) - -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" - docker pull php:$(PHP)-cli-alpine - -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 \ diff --git a/README.md b/README.md index 39d87b7..d78d538 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ # Docker image for `phpcs` -[![Build Status](https://travis-ci.com/cytopia/docker-phpcs.svg?branch=master)](https://travis-ci.com/cytopia/docker-phpcs) [![Tag](https://img.shields.io/github/tag/cytopia/docker-phpcs.svg)](https://github.com/cytopia/docker-phpcs/releases) -[![](https://images.microbadger.com/badges/version/cytopia/phpcs:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/phpcs:latest "phpcs") -[![](https://images.microbadger.com/badges/image/cytopia/phpcs:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/phpcs:latest "phpcs") -[![](https://img.shields.io/docker/pulls/cytopia/phpcs.svg)](https://hub.docker.com/r/cytopia/phpcs) [![](https://img.shields.io/badge/github-cytopia%2Fdocker--phpcs-red.svg)](https://github.com/cytopia/docker-phpcs "github.com/cytopia/docker-phpcs") [![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT) +[![lint](https://github.com/cytopia/docker-phpcs/workflows/lint/badge.svg)](https://github.com/cytopia/docker-phpcs/actions?query=workflow%3Alint) +[![build](https://github.com/cytopia/docker-phpcs/workflows/build/badge.svg)](https://github.com/cytopia/docker-phpcs/actions?query=workflow%3Abuild) +[![nightly](https://github.com/cytopia/docker-phpcs/workflows/nightly/badge.svg)](https://github.com/cytopia/docker-phpcs/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] **•** @@ -21,80 +23,124 @@ > [goimports][gimp-git-lnk] **•** > [golint][glint-git-lnk] **•** > [jsonlint][jlint-git-lnk] **•** +> [kubeval][kubeval-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] -> #### All [#awesome-ci](https://github.com/topics/awesome-ci) Makefiles -> -> Visit **[cytopia/makefiles](https://github.com/cytopia/makefiles)** for seamless project integration, minimum required best-practice code linting and CI. +View **[Dockerfiles](https://github.com/cytopia/docker-phpcs/blob/master/Dockerfiles/)** on GitHub. -View **[Dockerfile](https://github.com/cytopia/docker-phpcs/blob/master/Dockerfile)** on GitHub. -[![Docker hub](http://dockeri.co/image/cytopia/phpcs?&kill_cache=1)](https://hub.docker.com/r/cytopia/phpcs) +**Available Architectures:** `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` Tiny Alpine-based multistage-builld dockerized version of [phpcs](https://github.com/squizlabs/PHP_CodeSniffer)[1]. The image is built nightly against multiple stable versions and pushed to Dockerhub. [1] Official project: https://github.com/squizlabs/PHP_CodeSniffer +## :whale: Available Docker image versions -## Available Docker image versions - -Docker images for PHP CodeSniffer come with all available PHP versions. In doubt use `latest` tag. - -#### Latest stable phpcs version -| Docker tag | phpcs version | PHP version | -|-----------------|-----------------------|-----------------------| -| `latest` | latest stable | latest stable | -| `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` | -| `latest-php7.0` | latest stable | latest stable `7.0.x` | -| `latest-php5.6` | latest stable | latest stable `5.6.x` | - -#### Latest stable phpcs `3.x.x` version -| Docker tag | phpcs version | PHP version | -|-----------------|-----------------------|-----------------------| -| `3` | latest stable `3.x.x` | latest stable | -| `3-php7.4` | latest stable `3.x.x` | latest stable `7.4.x` | -| `3-php7.3` | latest stable `3.x.x` | latest stable `7.3.x` | -| `3-php7.2` | latest stable `3.x.x` | latest stable `7.2.x` | -| `3-php7.1` | latest stable `3.x.x` | latest stable `7.1.x` | -| `3-php7.0` | latest stable `3.x.x` | latest stable `7.0.x` | -| `3-php5.6` | latest stable `3.x.x` | latest stable `5.6.x` | - -#### Latest stable phpcs `2.x.x` version -| Docker tag | phpcs version | PHP version | -|-----------------|-----------------------|-----------------------| -| `2` | latest stable `2.x.x` | latest stable | -| `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` | -| `2-php7.0` | latest stable `2.x.x` | latest stable `7.0.x` | -| `2-php5.6` | latest stable `2.x.x` | latest stable `5.6.x` | - - -## Docker mounts - -The working directory inside the Docker container is **`/data/`** and should be mounted locally to -the root of your project. - - -## Usage +[![](https://img.shields.io/docker/pulls/cytopia/phpcs.svg)](https://hub.docker.com/r/cytopia/phpcs) +[![Docker](https://badgen.net/badge/icon/:latest?icon=docker&label=cytopia/phpcs)](https://hub.docker.com/r/cytopia/phpcs) + +#### Rolling releaess + +The following Docker image tags are rolling releases and are built and updated every night. + +[![nightly](https://github.com/cytopia/docker-phpcs/workflows/nightly/badge.svg)](https://github.com/cytopia/docker-phpcs/actions?query=workflow%3Anightly) + + +| Docker Tag | Git Ref | PHPCS | PHP | Available Architectures | +|-----------------------|--------------|--------------|------------|----------------------------------------------| +| **`latest`** | master | latest | latest | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php8.1` | master | latest | **`8.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php8.0` | master | latest | **`8.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.4` | master | latest | **`7.4`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.3` | master | latest | **`7.3`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.2` | master | latest | **`7.2`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.1` | master | latest | **`7.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.0` | master | latest | **`7.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php5.6` | master | latest | **`5.6`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| | | | | | +| **`3`** | master | **`3.x.x`** | latest | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php8.1` | master | **`3.x.x`** | **`8.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php8.0` | master | **`3.x.x`** | **`8.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.4` | master | **`3.x.x`** | **`7.4`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.3` | master | **`3.x.x`** | **`7.3`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.2` | master | **`3.x.x`** | **`7.2`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.1` | master | **`3.x.x`** | **`7.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.0` | master | **`3.x.x`** | **`7.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php5.6` | master | **`3.x.x`** | **`5.6`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| | | | | | +| **`2`** | master | **`2.x.x`** | latest | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php8.1` | master | **`2.x.x`** | **`8.1`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php8.0` | master | **`2.x.x`** | **`8.0`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.4` | master | **`2.x.x`** | **`7.4`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.3` | master | **`2.x.x`** | **`7.3`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.2` | master | **`2.x.x`** | **`7.2`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.1` | master | **`2.x.x`** | **`7.1`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.0` | master | **`2.x.x`** | **`7.0`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php5.6` | master | **`2.x.x`** | **`5.6`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | + +#### Point in time releases + +The following Docker image tags are built once and can be used for reproducible builds. Its version never changes so you will have to update tags in your pipelines from time to time in order to stay up-to-date. + +[![build](https://github.com/cytopia/docker-phpcs/workflows/build/badge.svg)](https://github.com/cytopia/docker-phpcs/actions?query=workflow%3Abuild) + + +| Docker Tag | Git Ref | PHPCS | PHP | Available Architectures | +|-----------------------|--------------|--------------|------------|----------------------------------------------| +| **`latest-`** | git: `` | latest | latest | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php8.1-` | git: `` | latest | **`8.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php8.0-` | git: `` | latest | **`8.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.4-` | git: `` | latest | **`7.4`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.3-` | git: `` | latest | **`7.3`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.2-` | git: `` | latest | **`7.2`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.1-` | git: `` | latest | **`7.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php7.0-` | git: `` | latest | **`7.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `latest-php5.6-` | git: `` | latest | **`5.6`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| | git: `` | | | | +| **`3-`** | git: `` | **`3.x.x`** | latest | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php8.1-` | git: `` | **`3.x.x`** | **`8.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php8.0-` | git: `` | **`3.x.x`** | **`8.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.4-` | git: `` | **`3.x.x`** | **`7.4`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.3-` | git: `` | **`3.x.x`** | **`7.3`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.2-` | git: `` | **`3.x.x`** | **`7.2`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.1-` | git: `` | **`3.x.x`** | **`7.1`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php7.0-` | git: `` | **`3.x.x`** | **`7.0`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| `3-php5.6-` | git: `` | **`3.x.x`** | **`5.6`** | `amd64`, `i386`, `arm64`, `arm/v7`, `arm/v6` | +| | git: `` | | | | +| **`2-`** | git: `` | **`2.x.x`** | latest | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php8.1-` | git: `` | **`2.x.x`** | **`8.1`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php8.0-` | git: `` | **`2.x.x`** | **`8.0`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.4-` | git: `` | **`2.x.x`** | **`7.4`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.3-` | git: `` | **`2.x.x`** | **`7.3`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.2-` | git: `` | **`2.x.x`** | **`7.2`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.1-` | git: `` | **`2.x.x`** | **`7.1`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php7.0-` | git: `` | **`2.x.x`** | **`7.0`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | +| `2-php5.6-` | git: `` | **`2.x.x`** | **`5.6`** | `amd64`, `i286`, `arm64`, `arm/v7`, `arm/v6` | + +> Where `` refers to the chosen git tag from this repository. + + +## :open_file_folder: Docker mounts + +The working directory inside the Docker container is **`/data/`** and should be mounted locally. + + +## :computer: Usage ### Basic ```bash @@ -130,7 +176,7 @@ phpcs: ``` -## Related [#awesome-ci](https://github.com/topics/awesome-ci) projects +## :arrows_counterclockwise: Related [#awesome-ci](https://github.com/topics/awesome-ci) projects ### Docker images @@ -149,11 +195,13 @@ linter below for reproducible local or remote CI tests: | [golint][glint-git-lnk] | [![glint-hub-img]][glint-hub-lnk] | Go | Lint Go code | | [eslint][elint-git-lnk] | [![elint-hub-img]][elint-hub-lnk] | Javascript | Lint Javascript code | | [jsonlint][jlint-git-lnk] | [![jlint-hub-img]][jlint-hub-lnk] | JSON | Lint JSON files **[1]** | +| [kubeval][kubeval-git-lnk] | [![kubeval-hub-img]][kubeval-hub-lnk] | K8s | Lint Kubernetes files | | [checkmake][cm-git-lnk] | [![cm-hub-img]][cm-hub-lnk] | Make | Lint Makefiles | | [phpcbf][pcbf-git-lnk] | [![pcbf-hub-img]][pcbf-hub-lnk] | PHP | PHP Code Beautifier and Fixer | | [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 | @@ -191,6 +239,10 @@ linter below for reproducible local or remote CI tests: [alint-hub-img]: https://img.shields.io/docker/pulls/cytopia/ansible-lint.svg [alint-hub-lnk]: https://hub.docker.com/r/cytopia/ansible-lint +[kubeval-git-lnk]: https://github.com/cytopia/docker-kubeval +[kubeval-hub-img]: https://img.shields.io/docker/pulls/cytopia/kubeval.svg +[kubeval-hub-lnk]: https://hub.docker.com/r/cytopia/kubeval + [gfmt-git-lnk]: https://github.com/cytopia/docker-gofmt [gfmt-hub-img]: https://img.shields.io/docker/pulls/cytopia/gofmt.svg [gfmt-hub-lnk]: https://hub.docker.com/r/cytopia/gofmt @@ -227,6 +279,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 @@ -274,7 +330,8 @@ Visit **[cytopia/makefiles](https://github.com/cytopia/makefiles)** for dependen The provided Makefiles will only require GNU Make and Docker itself removing the need to install anything else. -## License +## :page_facing_up: License + **[MIT License](LICENSE)**