-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cytopia/release-0.1
Initial Release
- Loading branch information
Showing
10 changed files
with
354 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
|
||
### | ||
### Enable sudo (required for docker service) | ||
### | ||
sudo: required | ||
|
||
|
||
### | ||
### Language | ||
### | ||
language: minimal | ||
|
||
|
||
### | ||
### Add services | ||
### | ||
services: | ||
- docker | ||
|
||
|
||
### | ||
### Build Matrix | ||
### | ||
env: | ||
matrix: | ||
- VERSION=5.6 | ||
- VERSION=7.0 | ||
- VERSION=7.1 | ||
- VERSION=7.2 | ||
- VERSION=7.3 | ||
- VERSION=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 | ||
- if [ "${VERSION}" != "latest" ]; then retry make build TAG=${VERSION}-cli-alpine; else retry make build; fi | ||
- if [ "${VERSION}" != "latest" ]; then retry make test TAG=${VERSION}-cli-alpine; else retry make test; fi | ||
|
||
|
||
### | ||
### 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 | ||
while ! make push TAG="${VERSION}-${TRAVIS_TAG}"; do sleep 1; done; | ||
elif [ "${TRAVIS_BRANCH}" == "master" ]; then | ||
while ! make push TAG=${VERSION}; do sleep 1; done; | ||
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then | ||
while ! make push TAG="${VERSION}-${TRAVIS_BRANCH}"; do sleep 1; done; | ||
else | ||
echo "Skipping branch ${TRAVIS_BRANCH}"; | ||
fi | ||
else | ||
echo "Skipping push on PR"; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ARG VERSION | ||
FROM php:${VERSION} | ||
|
||
RUN set -eux \ | ||
&& apk add --no-cache bash | ||
|
||
COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh | ||
|
||
ENV WORKDIR /data | ||
WORKDIR /data | ||
|
||
CMD ["*.php"] | ||
ENTRYPOINT ["/docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
ifneq (,) | ||
.error This Makefile requires GNU Make. | ||
endif | ||
|
||
.PHONY: build rebuild lint test _test-run-ok _test-run-fail tag pull login push enter | ||
|
||
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
DIR = . | ||
FILE = Dockerfile | ||
IMAGE = cytopia/phplint | ||
TAG = latest | ||
|
||
build: | ||
$(eval VERSION = $(shell if [ '$(TAG)' = "latest" ]; then echo '7-cli-alpine'; else echo '$(TAG)'; fi)) | ||
docker build --build-arg VERSION=$(VERSION) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) | ||
|
||
rebuild: pull | ||
$(eval VERSION = $(shell if [ '$(TAG)' = "latest" ]; then echo '7-cli-alpine'; else echo '$(TAG)'; fi)) | ||
docker build --no-cache --build-arg VERSION=$(VERSION) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) | ||
|
||
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-run-ok | ||
@$(MAKE) --no-print-directory _test-run-fail | ||
|
||
_test-run-ok: | ||
@echo "------------------------------------------------------------" | ||
@echo "- Testing correct files (1/2)" | ||
@echo "------------------------------------------------------------" | ||
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE); then \ | ||
echo "Failed"; \ | ||
exit 1; \ | ||
fi; \ | ||
echo "Success" | ||
@echo "------------------------------------------------------------" | ||
@echo "- Testing correct files (2/2)" | ||
@echo "------------------------------------------------------------" | ||
@if ! docker run --rm -v $(CURRENT_DIR)/tests:/data $(IMAGE) -i './fail/*' '*.php'; then \ | ||
echo "Failed"; \ | ||
exit 1; \ | ||
fi; \ | ||
echo "Success"; | ||
|
||
_test-run-fail: | ||
@echo "------------------------------------------------------------" | ||
@echo "- Testing failures (1/2)" | ||
@echo "------------------------------------------------------------" | ||
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE); then \ | ||
echo "Failed"; \ | ||
exit 1; \ | ||
fi; \ | ||
echo "Success" | ||
@echo "------------------------------------------------------------" | ||
@echo "- Testing failures (2/2)" | ||
@echo "------------------------------------------------------------" | ||
@if docker run --rm -v $(CURRENT_DIR)/tests:/data $(IMAGE); 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Be strict | ||
set -e | ||
set -u | ||
set -o pipefail | ||
|
||
|
||
### | ||
### Globals | ||
### | ||
ARG_IGNORE= # phplint arg to ignore files found via glob | ||
REG_GLOB='(\*.+)|(.+\*)|(.+\*.+)' # Regex pattern to identify valid glob supported by 'find' | ||
|
||
|
||
### | ||
### Show Usage | ||
### | ||
print_usage() { | ||
>&2 echo "Usage: cytopia/phplint [-i] <PATH-TO-FILE>" | ||
>&2 echo " cytopia/phplint [-i] <GLOB-PATTERN>" | ||
>&2 echo " cytopia/phplint --version" | ||
>&2 echo " cytopia/phplint --help" | ||
>&2 echo | ||
>&2 echo " -i <GLOB-PATTERN> Ignore glob pattern when using the GLOB-PATTERN for file search." | ||
>&2 echo " (e.g.: -i '\.test*.php')" | ||
>&2 echo " <PATH-TO-FILE> Path to file to validate" | ||
>&2 echo " <GLOB-PATTERN> Glob pattern for recursive scanning. (e.g.: *\\.php)" | ||
>&2 echo " Anything that \"find . -name '<GLOB-PATTERN>'\" will take is valid." | ||
} | ||
|
||
|
||
### | ||
### Validate PHP file | ||
### | ||
### @param string Path to file. | ||
### @return int Success (0: success, >0: Failure) | ||
### | ||
_phplint() { | ||
local file="${1}" | ||
# shellcheck disable=SC2155 | ||
local ret=0 | ||
local cmd="php -d display_errors=1 -d error_reporting=-1 -l ${file}" | ||
|
||
echo "${cmd}" | ||
if ! output="$( eval "${cmd}" 2>&1)"; then | ||
echo "${output}" | ||
ret=$(( ret + 1 )) | ||
fi | ||
|
||
return "${ret}" | ||
} | ||
|
||
|
||
### | ||
### Arguments appended? | ||
### | ||
if [ "${#}" -gt "0" ]; then | ||
|
||
while [ "${#}" -gt "0" ]; do | ||
case "${1}" in | ||
# Show Help and exit | ||
--help) | ||
print_usage | ||
exit 0 | ||
;; | ||
# Show Version and exit | ||
--version) | ||
php --version || true | ||
exit 0 | ||
;; | ||
# Ignore glob patterh | ||
-i) | ||
shift | ||
if [ "${#}" -lt "1" ]; then | ||
>&2 echo "Error, -i requires an argument" | ||
exit 1 | ||
fi | ||
ARG_IGNORE="${1}" | ||
shift | ||
;; | ||
# Anything else is handled here | ||
*) | ||
# Case 1/2: Its a file | ||
if [ -f "${1}" ]; then | ||
# Argument check | ||
if [ "${#}" -gt "1" ]; then | ||
>&2 echo "Error, you cannot specify arguments after the file position." | ||
print_usage | ||
exit 1 | ||
fi | ||
_phplint "${1}" | ||
exit "${?}" | ||
# Case 2/2: Its a glob | ||
else | ||
# Glob check | ||
if ! echo "${1}" | grep -qE "${REG_GLOB}"; then | ||
>&2 echo "Error, wrong glob format. Allowed: '${REG_GLOB}'" | ||
exit 1 | ||
fi | ||
# Argument check | ||
if [ "${#}" -gt "1" ]; then | ||
>&2 echo "Error, you cannot specify arguments after the glob position." | ||
print_usage | ||
exit 1 | ||
fi | ||
|
||
# Iterate over all files found by glob and jsonlint them | ||
if [ -z "${ARG_IGNORE}" ]; then | ||
find_cmd="find . -name \"${1}\" -type f -print0" | ||
else | ||
find_cmd="find . -not \( -path \"${ARG_IGNORE}\" \) -name \"${1}\" -type f -print0" | ||
fi | ||
|
||
echo "${find_cmd}" | ||
ret=0 | ||
while IFS= read -rd '' file; do | ||
if ! _phplint "${file}"; then | ||
ret=$(( ret + 1 )) | ||
fi | ||
done < <(eval "${find_cmd}") | ||
exit "${ret}" | ||
fi | ||
;; | ||
esac | ||
done | ||
|
||
### | ||
### No arguments appended | ||
### | ||
else | ||
print_usage | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
echo 'test' | ||
echo 'test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
function foo($test) { | ||
return $test; | ||
} | ||
|
||
foo1('test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
echo 'test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
function foo($test) { | ||
return $test; | ||
} | ||
|
||
echo foo('test'); |