From a8720ae89db8755dd35c5060b046c5c115b30069 Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 24 Oct 2022 12:59:35 +0200 Subject: [PATCH 1/2] Auto-select architecture for linting --- Makefile.lint | 88 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 11 deletions(-) diff --git a/Makefile.lint b/Makefile.lint index e5cbe0f..fcd0cc1 100644 --- a/Makefile.lint +++ b/Makefile.lint @@ -12,17 +12,23 @@ endif # ------------------------------------------------------------------------------------------------- CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) # File lint -FL_VERSION = 0.4 +FL_VERSION = latest FL_IGNORES = .git/,.github/ # Json lint JL_VERSION = latest JL_IGNORES = .git/,.github/ # Yamllint -YL_VERSION = 1.26-0.9 +YL_VERSION = latest # Shellcheck SC_IGNORES = .git/,.github/ SC_VERSION = stable +# Ensure to use correct docker platform for linting images +LINT_ARCH = linux/amd64 +ifeq ($(strip $(shell uname -m)),arm64) + LINT_ARCH = linux/arm64 +endif + # ------------------------------------------------------------------------------------------------- # Lint Targets @@ -35,25 +41,27 @@ lint: lint-bash .PHONY: lint-files +lint-files: _lint-files-pull lint-files: @echo "################################################################################" @echo "# Lint Files" @echo "################################################################################" - @docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-cr --text --ignore '$(FL_IGNORES)' --path . - @docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-crlf --text --ignore '$(FL_IGNORES)' --path . - @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 . - @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 . - @docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8 --text --ignore '$(FL_IGNORES)' --path . - @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 . + @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 . + @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 . + @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 . + @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 . + @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 . + @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 . @echo .PHONY: lint-yaml +lint-yaml: _lint-yaml-pull lint-yaml: @echo "################################################################################" @echo "# Lint Yaml" @echo "################################################################################" - @if docker run --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/yamllint:$(YL_VERSION) .; then \ + @if docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/yamllint:$(YL_VERSION) .; then \ echo "OK"; \ else \ echo "Failed"; \ @@ -63,11 +71,12 @@ lint-yaml: .PHONY: lint-json +lint-json: _lint-json-pull lint-json: @echo "################################################################################" @echo "# Lint JSON" @echo "################################################################################" - @if docker run --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/jsonlint:$(JL_VERSION) \ + @if docker run --platform $(LINT_ARCH) --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/jsonlint:$(JL_VERSION) \ -t ' ' -i '$(JL_IGNORES)' '*.json'; then \ echo "OK"; \ else \ @@ -78,6 +87,7 @@ lint-json: .PHONY: lint-bash +lint-bash: _lint-bash-pull lint-bash: @echo "################################################################################" @echo "# Lint Bash" @@ -89,5 +99,61 @@ lint-bash: CMD="find . -name '*.sh' $${IGNORES} -print0"; \ echo "$${CMD}"; \ if [ "$$( eval "$${CMD}" )" != "" ]; then \ - eval "$${CMD}" | xargs -0 -n1 docker run --rm -v $(CURRENT_DIR):/data -w /data koalaman/shellcheck:$(SC_VERSION) --shell=bash; \ + eval "$${CMD}" | xargs -0 -n1 docker run --platform $(LINT_ARCH) --rm -v $(CURRENT_DIR):/data -w /data koalaman/shellcheck:$(SC_VERSION) --shell=bash; \ fi + + +# ------------------------------------------------------------------------------------------------- +# Helper Targets +# ------------------------------------------------------------------------------------------------- +.PHONY: _lint-files-pull +_lint-files-pull: + @echo "Pulling cytopia/file-lint:$(FL_VERSION) ($(LINT_ARCH))"; \ + SUCC=0; \ + for i in $$(seq 10); do \ + if docker pull -q --platform $(LINT_ARCH) cytopia/file-lint:$(FL_VERSION); then \ + SUCC=1; \ + break; \ + fi; \ + sleep 1; \ + done; \ + if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi; + +.PHONY: _lint-yaml-pull +_lint-yaml-pull: + @echo "Pulling cytopia/yamllint:$(YL_VERSION) ($(LINT_ARCH))"; \ + SUCC=0; \ + for i in $$(seq 10); do \ + if docker pull -q --platform $(LINT_ARCH) cytopia/yamllint:$(YL_VERSION); then \ + SUCC=1; \ + break; \ + fi; \ + sleep 1; \ + done; \ + if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi; + +.PHONY: _lint-json-pull +_lint-json-pull: + @echo "Pulling cytopia/jsonlint:$(JL_VERSION) ($(LINT_ARCH))"; \ + SUCC=0; \ + for i in $$(seq 10); do \ + if docker pull -q --platform $(LINT_ARCH) cytopia/jsonlint:$(JL_VERSION); then \ + SUCC=1; \ + break; \ + fi; \ + sleep 1; \ + done; \ + if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi; + +.PHONY: _lint-bash-pull +_lint-bash-pull: + @echo "Pulling koalaman/shellcheck:$(SC_VERSION) ($(LINT_ARCH))"; \ + SUCC=0; \ + for i in $$(seq 10); do \ + if docker pull -q --platform $(LINT_ARCH) koalaman/shellcheck:$(SC_VERSION); then \ + SUCC=1; \ + break; \ + fi; \ + sleep 1; \ + done; \ + if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi; From 1ee8dfdf2f98fd094a95fdae6996c7e2793ff36f Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 24 Oct 2022 12:59:50 +0200 Subject: [PATCH 2/2] Integration tests --- .github/workflows/lint.yml | 56 ++++++++++++++++++++++++++++++++++++++ .yamllint | 13 +++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .yamllint diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..51d2210 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,56 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: lint + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs on Pull Requests + pull_request: + + +# ------------------------------------------------------------------------------------------------- +# What to run +# ------------------------------------------------------------------------------------------------- +jobs: + # ----------------------------------------------------------------------------------------------- + # JOB (1/1): Lint + # ----------------------------------------------------------------------------------------------- + lint: + name: lint + runs-on: ubuntu-latest + steps: + + - name: "[SETUP] Checkout repository" + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Lint Files + uses: cytopia/shell-command-retry-action@v0.1.3 + with: + command: | + make -f Makefile.lint lint-files + + - name: Lint Yaml + uses: cytopia/shell-command-retry-action@v0.1.3 + with: + command: | + make -f Makefile.lint lint-yaml + + - name: Lint JSON + uses: cytopia/shell-command-retry-action@v0.1.3 + with: + command: | + make -f Makefile.lint lint-json + + - name: Lint Bash + uses: cytopia/shell-command-retry-action@v0.1.3 + with: + command: | + make -f Makefile.lint lint-bash diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..2c7758f --- /dev/null +++ b/.yamllint @@ -0,0 +1,13 @@ +--- +extends: default + +ignore: | + .yamllint + + +rules: + truthy: + allowed-values: ['true', 'false'] + check-keys: False + level: error + line-length: disable