|
| 1 | +ifneq (,) |
| 2 | +.error This Makefile requires GNU Make. |
| 3 | +endif |
| 4 | + |
| 5 | +.PHONY: build rebuild lint test _test_version _test_run tag pull login push enter |
| 6 | + |
| 7 | +CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 8 | + |
| 9 | +DIR = . |
| 10 | +FILE = Dockerfile |
| 11 | +IMAGE = cytopia/pylint |
| 12 | +TAG = latest |
| 13 | + |
| 14 | +build: |
| 15 | + docker build --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) |
| 16 | + |
| 17 | +rebuild: pull |
| 18 | + docker build --no-cache --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) |
| 19 | + |
| 20 | +lint: |
| 21 | + @docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path . |
| 22 | + @docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path . |
| 23 | + @docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path . |
| 24 | + @docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path . |
| 25 | + @docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path . |
| 26 | + @docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path . |
| 27 | + |
| 28 | +test: |
| 29 | + @$(MAKE) --no-print-directory _test_version |
| 30 | + @$(MAKE) --no-print-directory _test_run |
| 31 | + |
| 32 | +_test_version: |
| 33 | + @echo "------------------------------------------------------------" |
| 34 | + @echo "- Testing correct version" |
| 35 | + @echo "------------------------------------------------------------" |
| 36 | + @if [ "$(TAG)" = "latest" ]; then \ |
| 37 | + echo "Fetching latest version from GitHub"; \ |
| 38 | + LATEST="$$( \ |
| 39 | + curl -L -sS https://github.com/PyCQA/pylint/releases/ \ |
| 40 | + | tac | tac \ |
| 41 | + | grep -Eo "PyCQA/pylint/releases/tag/(pylint-)?[.0-9]+" \ |
| 42 | + | head -1 \ |
| 43 | + | sed 's/.*tag\///g' \ |
| 44 | + | grep -Eo '[.0-9]+' \ |
| 45 | + )"; \ |
| 46 | + echo "Testing for latest: $${LATEST}"; \ |
| 47 | + if ! docker run --rm $(IMAGE) --version | grep -E "$${LATEST}$$"; then \ |
| 48 | + echo "Failed"; \ |
| 49 | + exit 1; \ |
| 50 | + fi; \ |
| 51 | + else \ |
| 52 | + echo "Testing for tag: $(TAG)"; \ |
| 53 | + if ! docker run --rm $(IMAGE) --version | grep -E "^$(TAG)"; then \ |
| 54 | + echo "Failed"; \ |
| 55 | + exit 1; \ |
| 56 | + fi; \ |
| 57 | + fi; \ |
| 58 | + echo "Success"; \ |
| 59 | + |
| 60 | +_test_run: |
| 61 | + @echo "------------------------------------------------------------" |
| 62 | + @echo "- Testing pep8 standard" |
| 63 | + @echo "------------------------------------------------------------" |
| 64 | + @if ! docker run --rm -v $(CURRENT_DIR)/tests:/data $(IMAGE) test.py ; then \ |
| 65 | + echo "Failed"; \ |
| 66 | + exit 1; \ |
| 67 | + fi; \ |
| 68 | + echo "Success"; |
| 69 | + |
| 70 | +tag: |
| 71 | + docker tag $(IMAGE) $(IMAGE):$(TAG) |
| 72 | + |
| 73 | +pull: |
| 74 | + @grep -E '^\s*FROM' Dockerfile \ |
| 75 | + | sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \ |
| 76 | + | xargs -n1 docker pull; |
| 77 | + |
| 78 | +login: |
| 79 | + yes | docker login --username $(USER) --password $(PASS) |
| 80 | + |
| 81 | +push: |
| 82 | + @$(MAKE) tag TAG=$(TAG) |
| 83 | + docker push $(IMAGE):$(TAG) |
| 84 | + |
| 85 | +enter: |
| 86 | + docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG) |
0 commit comments