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 Jun 16, 2019
2 parents c738cbd + a35a93c commit 29cbbc4
Show file tree
Hide file tree
Showing 64 changed files with 2,115 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---

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


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


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


###
### Build Matrix
###
env:
matrix:
- VERSION=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 build TAG=${VERSION}; do sleep 1; done
- while ! make test TAG=${VERSION}; 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
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
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:latest as builder

RUN set -x \
&& apk add --no-cache \
moreutils

FROM alpine:latest
LABEL \
maintainer="cytopia <[email protected]>" \
repo="https://github.com/cytopia/docker-jsonlint"

RUN set -x \
&& apk add --no-cache \
bash \
dos2unix \
file \
grep \
sed

COPY --from=builder /usr/bin/isutf8 /usr/bin/isutf8
COPY data /usr/bin/
WORKDIR /data
CMD ["usage"]
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.
101 changes: 101 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
ifneq (,)
.error This Makefile requires GNU Make.
endif

.PHONY: build rebuild test _test_req _test_run_succ _test_run_fail tag pull login push enter

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

DIR = .
FILE = Dockerfile
IMAGE = cytopia/file-lint
TAG = latest

build:
docker build -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

rebuild: pull
docker build --no-cache -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

test:
@$(MAKE) --no-print-directory _test_req
@$(MAKE) --no-print-directory _test_run_succ
@$(MAKE) --no-print-directory _test_run_fail

_test_req:
@echo "------------------------------------------------------------"
@echo "- Testing requirements"
@echo "------------------------------------------------------------"
@docker run --rm $(IMAGE) file-empty --info
@docker run --rm $(IMAGE) file-cr --info
@docker run --rm $(IMAGE) file-crlf --info
@docker run --rm $(IMAGE) file-nullbyte --info
@docker run --rm $(IMAGE) file-trailing-newline --info
@docker run --rm $(IMAGE) file-trailing-single-newline --info
@docker run --rm $(IMAGE) file-trailing-space --info
@docker run --rm $(IMAGE) file-utf8 --info
@docker run --rm $(IMAGE) file-utf8-bom --info

_test_run_succ:
@echo "------------------------------------------------------------"
@echo "- Runtime test: False positives"
@echo "------------------------------------------------------------"
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-empty --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-cr --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-crlf --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-nullbyte --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-trailing-newline --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-trailing-single-newline --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-trailing-space --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-utf8 --path .
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-utf8-bom --path .

_test_run_fail:
@echo "------------------------------------------------------------"
@echo "- Runtime test: True flaws"
@echo "------------------------------------------------------------"
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-empty --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-cr --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-crlf --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-nullbyte --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-trailing-newline --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-trailing-single-newline --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-trailing-space --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-utf8 --path .; then \
exit 1; \
fi
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-utf8-bom --path .; then \
exit 1; \
fi

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 $(ARG) $(IMAGE):$(TAG) bash
73 changes: 73 additions & 0 deletions data/aci-trailing-newline
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh -u

NAME="aci-trailing-newline"



print_usage() {
echo "Usage: ${NAME} -n file"
echo " ${NAME} -1 file"
echo " ${NAME} -v"
echo
echo "Validates if a file has at least 1 or exactly only 1 trailing newline."
echo "Returns 0, if condition is met, otherwise > 0"
echo
echo " -n Must have at least 1 trailing newline at the end of the file."
echo " -1 Must have exactly only 1 trailing newline at the end of the file."
echo " -v Show version"
exit 1
}
print_version() {
echo "${NAME} v0.1 (2016-08-21)"
echo "Written by cytopia <[email protected]>"
echo "https://github.com/cytopia"
}

if [ "${#}" = "1" ] && [ "${1}" = "-v" ]; then
print_version
exit 0
fi

if [ "${#}" != "2" ]; then
print_usage
exit 1
fi
if [ "${1}" != "-n" ] && [ "${1}" != "-1" ]; then
print_usage
exit 1
fi

OPTION="${1}"
FILE="${2}"

#
# Validate file
#
if [ ! -f "${FILE}" ]; then
echo "No such file: ${FILE}"
exit 1
fi
if [ ! -r "${FILE}" ]; then
echo "Cannot read file: ${FILE}"
exit 1
fi



# No trailing newline at the end of the file
if ! tail -c 1 "${FILE}" | grep -qE "^$"; then
exit 2
fi


# Check if only 1 trailing newline
if [ "${OPTION}" = "-1" ]; then

# At least two newlines at the end of the file
if tail -c 2 "${FILE}" | grep -qE "^$"; then
exit 3
fi

fi

exit 0
Loading

0 comments on commit 29cbbc4

Please sign in to comment.