Skip to content

Commit 29cbbc4

Browse files
authored
Merge pull request #1 from cytopia/release-0.1
Initial release
2 parents c738cbd + a35a93c commit 29cbbc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2115
-0
lines changed

.travis.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
3+
###
4+
### Enable sudo (required for docker service)
5+
###
6+
sudo: required
7+
8+
9+
###
10+
### Language
11+
###
12+
language: python
13+
14+
15+
###
16+
### Add services
17+
###
18+
services:
19+
- docker
20+
21+
22+
###
23+
### Build Matrix
24+
###
25+
env:
26+
matrix:
27+
- VERSION=latest
28+
29+
30+
###
31+
### Install requirements
32+
###
33+
install:
34+
# Get newer docker version
35+
- while ! sudo apt-get update; do sleep 1; done
36+
- while ! sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; do sleep 1; done
37+
- docker version
38+
39+
40+
###
41+
### Check generation changes, build and test
42+
###
43+
before_script:
44+
- while ! make build TAG=${VERSION}; do sleep 1; done
45+
- while ! make test TAG=${VERSION}; do sleep 1; done
46+
47+
48+
###
49+
### Push to Dockerhub
50+
###
51+
script:
52+
# Push to docker hub on success
53+
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
54+
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
55+
if [ -n "${TRAVIS_TAG}" ]; then
56+
while ! make push TAG="${VERSION}-${TRAVIS_TAG}"; do sleep 1; done;
57+
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
58+
while ! make push TAG=${VERSION}; do sleep 1; done;
59+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
60+
while ! make push TAG="${VERSION}-${TRAVIS_BRANCH}"; do sleep 1; done;
61+
else
62+
echo "Skipping branch ${TRAVIS_BRANCH}";
63+
fi
64+
else
65+
echo "Skipping push on PR";
66+
fi

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM alpine:latest as builder
2+
3+
RUN set -x \
4+
&& apk add --no-cache \
5+
moreutils
6+
7+
FROM alpine:latest
8+
LABEL \
9+
maintainer="cytopia <[email protected]>" \
10+
repo="https://github.com/cytopia/docker-jsonlint"
11+
12+
RUN set -x \
13+
&& apk add --no-cache \
14+
bash \
15+
dos2unix \
16+
file \
17+
grep \
18+
sed
19+
20+
COPY --from=builder /usr/bin/isutf8 /usr/bin/isutf8
21+
COPY data /usr/bin/
22+
WORKDIR /data
23+
CMD ["usage"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 cytopia <https://github.com/cytopia>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: build rebuild test _test_req _test_run_succ _test_run_fail tag pull login push enter
6+
7+
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8+
9+
DIR = .
10+
FILE = Dockerfile
11+
IMAGE = cytopia/file-lint
12+
TAG = latest
13+
14+
build:
15+
docker build -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
16+
17+
rebuild: pull
18+
docker build --no-cache -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
19+
20+
test:
21+
@$(MAKE) --no-print-directory _test_req
22+
@$(MAKE) --no-print-directory _test_run_succ
23+
@$(MAKE) --no-print-directory _test_run_fail
24+
25+
_test_req:
26+
@echo "------------------------------------------------------------"
27+
@echo "- Testing requirements"
28+
@echo "------------------------------------------------------------"
29+
@docker run --rm $(IMAGE) file-empty --info
30+
@docker run --rm $(IMAGE) file-cr --info
31+
@docker run --rm $(IMAGE) file-crlf --info
32+
@docker run --rm $(IMAGE) file-nullbyte --info
33+
@docker run --rm $(IMAGE) file-trailing-newline --info
34+
@docker run --rm $(IMAGE) file-trailing-single-newline --info
35+
@docker run --rm $(IMAGE) file-trailing-space --info
36+
@docker run --rm $(IMAGE) file-utf8 --info
37+
@docker run --rm $(IMAGE) file-utf8-bom --info
38+
39+
_test_run_succ:
40+
@echo "------------------------------------------------------------"
41+
@echo "- Runtime test: False positives"
42+
@echo "------------------------------------------------------------"
43+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-empty --path .
44+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-cr --path .
45+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-crlf --path .
46+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-nullbyte --path .
47+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-trailing-newline --path .
48+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-trailing-single-newline --path .
49+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-trailing-space --path .
50+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-utf8 --path .
51+
@docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) file-utf8-bom --path .
52+
53+
_test_run_fail:
54+
@echo "------------------------------------------------------------"
55+
@echo "- Runtime test: True flaws"
56+
@echo "------------------------------------------------------------"
57+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-empty --path .; then \
58+
exit 1; \
59+
fi
60+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-cr --path .; then \
61+
exit 1; \
62+
fi
63+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-crlf --path .; then \
64+
exit 1; \
65+
fi
66+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-nullbyte --path .; then \
67+
exit 1; \
68+
fi
69+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-trailing-newline --path .; then \
70+
exit 1; \
71+
fi
72+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-trailing-single-newline --path .; then \
73+
exit 1; \
74+
fi
75+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-trailing-space --path .; then \
76+
exit 1; \
77+
fi
78+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-utf8 --path .; then \
79+
exit 1; \
80+
fi
81+
@if docker run --rm -v $(CURRENT_DIR)/tests/err:/data $(IMAGE) file-utf8-bom --path .; then \
82+
exit 1; \
83+
fi
84+
85+
tag:
86+
docker tag $(IMAGE) $(IMAGE):$(TAG)
87+
88+
pull:
89+
@grep -E '^\s*FROM' Dockerfile \
90+
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
91+
| xargs -n1 docker pull;
92+
93+
login:
94+
yes | docker login --username $(USER) --password $(PASS)
95+
96+
push:
97+
@$(MAKE) tag TAG=$(TAG)
98+
docker push $(IMAGE):$(TAG)
99+
100+
enter:
101+
docker run --rm --name $(subst /,-,$(IMAGE)) -it $(ARG) $(IMAGE):$(TAG) bash

data/aci-trailing-newline

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh -u
2+
3+
NAME="aci-trailing-newline"
4+
5+
6+
7+
print_usage() {
8+
echo "Usage: ${NAME} -n file"
9+
echo " ${NAME} -1 file"
10+
echo " ${NAME} -v"
11+
echo
12+
echo "Validates if a file has at least 1 or exactly only 1 trailing newline."
13+
echo "Returns 0, if condition is met, otherwise > 0"
14+
echo
15+
echo " -n Must have at least 1 trailing newline at the end of the file."
16+
echo " -1 Must have exactly only 1 trailing newline at the end of the file."
17+
echo " -v Show version"
18+
exit 1
19+
}
20+
print_version() {
21+
echo "${NAME} v0.1 (2016-08-21)"
22+
echo "Written by cytopia <[email protected]>"
23+
echo "https://github.com/cytopia"
24+
}
25+
26+
if [ "${#}" = "1" ] && [ "${1}" = "-v" ]; then
27+
print_version
28+
exit 0
29+
fi
30+
31+
if [ "${#}" != "2" ]; then
32+
print_usage
33+
exit 1
34+
fi
35+
if [ "${1}" != "-n" ] && [ "${1}" != "-1" ]; then
36+
print_usage
37+
exit 1
38+
fi
39+
40+
OPTION="${1}"
41+
FILE="${2}"
42+
43+
#
44+
# Validate file
45+
#
46+
if [ ! -f "${FILE}" ]; then
47+
echo "No such file: ${FILE}"
48+
exit 1
49+
fi
50+
if [ ! -r "${FILE}" ]; then
51+
echo "Cannot read file: ${FILE}"
52+
exit 1
53+
fi
54+
55+
56+
57+
# No trailing newline at the end of the file
58+
if ! tail -c 1 "${FILE}" | grep -qE "^$"; then
59+
exit 2
60+
fi
61+
62+
63+
# Check if only 1 trailing newline
64+
if [ "${OPTION}" = "-1" ]; then
65+
66+
# At least two newlines at the end of the file
67+
if tail -c 2 "${FILE}" | grep -qE "^$"; then
68+
exit 3
69+
fi
70+
71+
fi
72+
73+
exit 0

0 commit comments

Comments
 (0)