Skip to content

Commit 1138af8

Browse files
authored
Merge pull request #9 from devilbox/improve-linting
Improve linting
2 parents bc0da08 + 1ee8dfd commit 1138af8

File tree

3 files changed

+146
-11
lines changed

3 files changed

+146
-11
lines changed

.github/workflows/lint.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
3+
# -------------------------------------------------------------------------------------------------
4+
# Job Name
5+
# -------------------------------------------------------------------------------------------------
6+
name: lint
7+
8+
9+
# -------------------------------------------------------------------------------------------------
10+
# When to run
11+
# -------------------------------------------------------------------------------------------------
12+
on:
13+
# Runs on Pull Requests
14+
pull_request:
15+
16+
17+
# -------------------------------------------------------------------------------------------------
18+
# What to run
19+
# -------------------------------------------------------------------------------------------------
20+
jobs:
21+
# -----------------------------------------------------------------------------------------------
22+
# JOB (1/1): Lint
23+
# -----------------------------------------------------------------------------------------------
24+
lint:
25+
name: lint
26+
runs-on: ubuntu-latest
27+
steps:
28+
29+
- name: "[SETUP] Checkout repository"
30+
uses: actions/checkout@v3
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Lint Files
35+
uses: cytopia/[email protected]
36+
with:
37+
command: |
38+
make -f Makefile.lint lint-files
39+
40+
- name: Lint Yaml
41+
uses: cytopia/[email protected]
42+
with:
43+
command: |
44+
make -f Makefile.lint lint-yaml
45+
46+
- name: Lint JSON
47+
uses: cytopia/[email protected]
48+
with:
49+
command: |
50+
make -f Makefile.lint lint-json
51+
52+
- name: Lint Bash
53+
uses: cytopia/[email protected]
54+
with:
55+
command: |
56+
make -f Makefile.lint lint-bash

.yamllint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
extends: default
3+
4+
ignore: |
5+
.yamllint
6+
7+
8+
rules:
9+
truthy:
10+
allowed-values: ['true', 'false']
11+
check-keys: False
12+
level: error
13+
line-length: disable

Makefile.lint

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ endif
1212
# -------------------------------------------------------------------------------------------------
1313
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
1414
# File lint
15-
FL_VERSION = 0.4
15+
FL_VERSION = latest
1616
FL_IGNORES = .git/,.github/
1717
# Json lint
1818
JL_VERSION = latest
1919
JL_IGNORES = .git/,.github/
2020
# Yamllint
21-
YL_VERSION = 1.26-0.9
21+
YL_VERSION = latest
2222
# Shellcheck
2323
SC_IGNORES = .git/,.github/
2424
SC_VERSION = stable
2525

26+
# Ensure to use correct docker platform for linting images
27+
LINT_ARCH = linux/amd64
28+
ifeq ($(strip $(shell uname -m)),arm64)
29+
LINT_ARCH = linux/arm64
30+
endif
31+
2632

2733
# -------------------------------------------------------------------------------------------------
2834
# Lint Targets
@@ -35,25 +41,27 @@ lint: lint-bash
3541

3642

3743
.PHONY: lint-files
44+
lint-files: _lint-files-pull
3845
lint-files:
3946
@echo "################################################################################"
4047
@echo "# Lint Files"
4148
@echo "################################################################################"
42-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-cr --text --ignore '$(FL_IGNORES)' --path .
43-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-crlf --text --ignore '$(FL_IGNORES)' --path .
44-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-trailing-single-newline --text --ignore '$(FL_IGNORES)' --path .
45-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-trailing-space --text --ignore '$(FL_IGNORES)' --path .
46-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8 --text --ignore '$(FL_IGNORES)' --path .
47-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8-bom --text --ignore '$(FL_IGNORES)' --path .
49+
@docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-cr --text --ignore '$(FL_IGNORES)' --path .
50+
@docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-crlf --text --ignore '$(FL_IGNORES)' --path .
51+
@docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-trailing-single-newline --text --ignore '$(FL_IGNORES)' --path .
52+
@docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-trailing-space --text --ignore '$(FL_IGNORES)' --path .
53+
@docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8 --text --ignore '$(FL_IGNORES)' --path .
54+
@docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8-bom --text --ignore '$(FL_IGNORES)' --path .
4855
@echo
4956

5057

5158
.PHONY: lint-yaml
59+
lint-yaml: _lint-yaml-pull
5260
lint-yaml:
5361
@echo "################################################################################"
5462
@echo "# Lint Yaml"
5563
@echo "################################################################################"
56-
@if docker run --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/yamllint:$(YL_VERSION) .; then \
64+
@if docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/yamllint:$(YL_VERSION) .; then \
5765
echo "OK"; \
5866
else \
5967
echo "Failed"; \
@@ -63,11 +71,12 @@ lint-yaml:
6371

6472

6573
.PHONY: lint-json
74+
lint-json: _lint-json-pull
6675
lint-json:
6776
@echo "################################################################################"
6877
@echo "# Lint JSON"
6978
@echo "################################################################################"
70-
@if docker run --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/jsonlint:$(JL_VERSION) \
79+
@if docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/jsonlint:$(JL_VERSION) \
7180
-t ' ' -i '$(JL_IGNORES)' '*.json'; then \
7281
echo "OK"; \
7382
else \
@@ -78,6 +87,7 @@ lint-json:
7887

7988

8089
.PHONY: lint-bash
90+
lint-bash: _lint-bash-pull
8191
lint-bash:
8292
@echo "################################################################################"
8393
@echo "# Lint Bash"
@@ -89,5 +99,61 @@ lint-bash:
8999
CMD="find . -name '*.sh' $${IGNORES} -print0"; \
90100
echo "$${CMD}"; \
91101
if [ "$$( eval "$${CMD}" )" != "" ]; then \
92-
eval "$${CMD}" | xargs -0 -n1 docker run --rm -v $(CURRENT_DIR):/data -w /data koalaman/shellcheck:$(SC_VERSION) --shell=bash; \
102+
eval "$${CMD}" | xargs -0 -n1 docker run --platform $(LINT_ARCH) --rm -v $(CURRENT_DIR):/data -w /data koalaman/shellcheck:$(SC_VERSION) --shell=bash; \
93103
fi
104+
105+
106+
# -------------------------------------------------------------------------------------------------
107+
# Helper Targets
108+
# -------------------------------------------------------------------------------------------------
109+
.PHONY: _lint-files-pull
110+
_lint-files-pull:
111+
@echo "Pulling cytopia/file-lint:$(FL_VERSION) ($(LINT_ARCH))"; \
112+
SUCC=0; \
113+
for i in $$(seq 10); do \
114+
if docker pull -q --platform $(LINT_ARCH) cytopia/file-lint:$(FL_VERSION); then \
115+
SUCC=1; \
116+
break; \
117+
fi; \
118+
sleep 1; \
119+
done; \
120+
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
121+
122+
.PHONY: _lint-yaml-pull
123+
_lint-yaml-pull:
124+
@echo "Pulling cytopia/yamllint:$(YL_VERSION) ($(LINT_ARCH))"; \
125+
SUCC=0; \
126+
for i in $$(seq 10); do \
127+
if docker pull -q --platform $(LINT_ARCH) cytopia/yamllint:$(YL_VERSION); then \
128+
SUCC=1; \
129+
break; \
130+
fi; \
131+
sleep 1; \
132+
done; \
133+
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
134+
135+
.PHONY: _lint-json-pull
136+
_lint-json-pull:
137+
@echo "Pulling cytopia/jsonlint:$(JL_VERSION) ($(LINT_ARCH))"; \
138+
SUCC=0; \
139+
for i in $$(seq 10); do \
140+
if docker pull -q --platform $(LINT_ARCH) cytopia/jsonlint:$(JL_VERSION); then \
141+
SUCC=1; \
142+
break; \
143+
fi; \
144+
sleep 1; \
145+
done; \
146+
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
147+
148+
.PHONY: _lint-bash-pull
149+
_lint-bash-pull:
150+
@echo "Pulling koalaman/shellcheck:$(SC_VERSION) ($(LINT_ARCH))"; \
151+
SUCC=0; \
152+
for i in $$(seq 10); do \
153+
if docker pull -q --platform $(LINT_ARCH) koalaman/shellcheck:$(SC_VERSION); then \
154+
SUCC=1; \
155+
break; \
156+
fi; \
157+
sleep 1; \
158+
done; \
159+
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;

0 commit comments

Comments
 (0)