From abdf681d0265fce41aa971dd6b8194c902a3c1f6 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach <44545919+aendeavor@users.noreply.github.com> Date: Tue, 1 Jun 2021 18:12:17 +0200 Subject: [PATCH] chore(ci): Linting Improved (#2000) --- .github/workflows/linting.yml | 6 +-- Makefile | 6 +-- target/scripts/start-mailserver.sh | 5 +- target/scripts/startup/setup-stack.sh | 2 +- test/linting/.ecrc.json | 19 +++++++ test/linting/.hadolint.yaml | 1 + test/linting/lint.sh | 77 +++++++++++---------------- 7 files changed, 60 insertions(+), 56 deletions(-) create mode 100644 test/linting/.ecrc.json diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 74ce4560..ec1a1e32 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -21,7 +21,7 @@ jobs: sudo chmod +rx /usr/local/bin/hadolint make hadolint env: - HADOLINT_VERSION: 1.19.0 + HADOLINT_VERSION: 2.4.1 - name: ShellCheck run: | sudo curl -S -L "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJ @@ -29,7 +29,7 @@ jobs: sudo rm -rf "shellcheck-v${SHELLCHECK_VERSION}" make shellcheck env: - SHELLCHECK_VERSION: 0.7.1 + SHELLCHECK_VERSION: 0.7.2 - name: ECLint run: | sudo curl -S -L "https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${ECLINT_VERSION}/ec-linux-amd64.tar.gz" | tar -xaz @@ -38,4 +38,4 @@ jobs: sudo chmod +x /usr/bin/eclint make eclint env: - ECLINT_VERSION: 2.3.1 + ECLINT_VERSION: 2.3.5 diff --git a/Makefile b/Makefile index f4b8b8d5..a0eb90cc 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ NAME ?= mailserver-testing:ci VCS_REF = $(shell git rev-parse --short HEAD) VCS_VER = $(shell git describe --tags --contains --always) -HADOLINT_VERSION = 1.19.0 -SHELLCHECK_VERSION = 0.7.1 -ECLINT_VERSION = 2.3.1 +HADOLINT_VERSION = 2.4.1 +SHELLCHECK_VERSION = 0.7.2 +ECLINT_VERSION = 2.3.5 export CDIR = $(shell pwd) diff --git a/target/scripts/start-mailserver.sh b/target/scripts/start-mailserver.sh index 3ee888be..5cc028cb 100755 --- a/target/scripts/start-mailserver.sh +++ b/target/scripts/start-mailserver.sh @@ -55,10 +55,7 @@ VARS[POSTSCREEN_ACTION]="${POSTSCREEN_ACTION:=enforce}" VARS[RELAY_HOST]="${RELAY_HOST:=}" VARS[REPORT_RECIPIENT]="${REPORT_RECIPIENT:="0"}" VARS[SMTP_ONLY]="${SMTP_ONLY:=0}" -SPAMASSASSIN_SPAM_TO_INBOX_IS_SET="$(\ - if [[ -n ${SPAMASSASSIN_SPAM_TO_INBOX+'set'} ]]; \ - then echo true ; else echo false ; fi )" -VARS[SPAMASSASSIN_SPAM_TO_INBOX_IS_SET]="${SPAMASSASSIN_SPAM_TO_INBOX}" +VARS[SPAMASSASSIN_SPAM_TO_INBOX_SET]="${SPAMASSASSIN_SPAM_TO_INBOX:-not set}" VARS[SPAMASSASSIN_SPAM_TO_INBOX]="${SPAMASSASSIN_SPAM_TO_INBOX:=0}" VARS[SPOOF_PROTECTION]="${SPOOF_PROTECTION:=0}" VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}" diff --git a/target/scripts/startup/setup-stack.sh b/target/scripts/startup/setup-stack.sh index 385d2dab..e2399f41 100644 --- a/target/scripts/startup/setup-stack.sh +++ b/target/scripts/startup/setup-stack.sh @@ -1454,7 +1454,7 @@ function _setup_security_stack sed -i "s|\$final_spam_destiny.*=.*$|\$final_spam_destiny = D_BOUNCE;|g" /etc/amavis/conf.d/49-docker-mailserver sed -i "s|\$final_bad_header_destiny.*=.*$|\$final_bad_header_destiny = D_BOUNCE;|g" /etc/amavis/conf.d/49-docker-mailserver - if ! ${SPAMASSASSIN_SPAM_TO_INBOX_IS_SET} + if [[ ${VARS[SPAMASSASSIN_SPAM_TO_INBOX_SET]} == 'not set' ]] then _notify 'warn' 'Spam messages WILL NOT BE DELIVERED, you will NOT be notified of ANY message bounced. Please define SPAMASSASSIN_SPAM_TO_INBOX explicitly.' fi diff --git a/test/linting/.ecrc.json b/test/linting/.ecrc.json new file mode 100644 index 00000000..27ac948d --- /dev/null +++ b/test/linting/.ecrc.json @@ -0,0 +1,19 @@ +{ + "Version": "2.3.5", + "Verbose": false, + "Debug": false, + "IgnoreDefaults": false, + "SpacesAftertabs": true, + "NoColor": false, + "Exclude": [], + "AllowedContentTypes": [], + "PassedFiles": [], + "Disable": { + "EndOfLine": false, + "Indentation": false, + "InsertFinalNewline": false, + "TrimTrailingWhitespace": false, + "IndentSize": false, + "MaxLineLength": false + } +} diff --git a/test/linting/.hadolint.yaml b/test/linting/.hadolint.yaml index b936bf6a..74c65ac6 100644 --- a/test/linting/.hadolint.yaml +++ b/test/linting/.hadolint.yaml @@ -1,4 +1,5 @@ ignored: + - DL3005 - DL3008 - DL3015 diff --git a/test/linting/lint.sh b/test/linting/lint.sh index d9801d24..bb2d53e7 100755 --- a/test/linting/lint.sh +++ b/test/linting/lint.sh @@ -1,30 +1,13 @@ #! /bin/bash -# version v0.1.3 stable -# executed by CI / manually (via Make) -# task checks files agains linting targets +# version v0.2.0 unstable +# executed by Make during CI or manually +# task checks files against linting targets SCRIPT="lint.sh" -function _get_current_directory -{ - if dirname "$(readlink -f "${0}")" &>/dev/null - then - CDIR="$(dirname "$(readlink -f "${0}")")" - elif realpath -e -L "${0}" &>/dev/null - then - CDIR="$(realpath -e -L "${0}")" - CDIR="${CDIR%/setup.sh}" - fi -} - -CDIR="$(pwd)" -_get_current_directory - -# ? ––––––––––––––––––––––––––––––––––––––––––––– ERRORS - set -eEuo pipefail -trap '__log_err ${FUNCNAME[0]:-"?"} ${BASH_COMMAND:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR +trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" ${LINENO:-?} ${?:-?}' ERR function __log_err { @@ -33,18 +16,14 @@ function __log_err " – function = ${1} / ${2}" \ " – line = ${3}" \ " – exit code = ${4}" - - unset CDIR SCRIPT OS VERSION } -# ? ––––––––––––––––––––––––––––––––––––––––––––– LOG - function __log_info { printf "\n––– \e[34m%s\e[0m\n%s\n%s\n\n" \ "${SCRIPT:-${0}}" \ " – type = INFO" \ - " – message = ${*}" + " – version = ${*}" } function __log_failure @@ -52,7 +31,7 @@ function __log_failure printf "\n––– \e[91m%s\e[0m\n%s\n%s\n\n" \ "${SCRIPT:-${0}}" \ " – type = FAILURE" \ - " – message = ${*:-'errors encountered'}" + " – message = ${*:-errors encountered}" } function __log_success @@ -63,13 +42,25 @@ function __log_success " – message = no errors detected" } -function __in_path { __which "${@}" && return 0 ; return 1 ; } -function __which { command -v "${@}" &>/dev/null ; } +function __in_path +{ + command -v "${@}" &>/dev/null && return 0 ; return 1 ; +} function _eclint { local SCRIPT='EDITORCONFIG LINTER' - local LINT=(eclint -exclude "(.*\.git.*|.*\.md$|\.bats$|\.cf$|\.conf$|\.init$)") + + local IGNORE='.*\.git.*|.*\.md$|\.bats$|\.cf$|' + IGNORE+='\.conf$|\.init$|.*test/.*|.*tools/.*' + + local LINT=( + eclint + -config + "${CDIR}/test/linting/.ecrc.json" + -exclude + "(${IGNORE})" + ) if ! __in_path "${LINT[0]}" then @@ -77,7 +68,7 @@ function _eclint return 2 fi - __log_info 'linter version:' "$(${LINT[0]} --version)" + __log_info "$(${LINT[0]} --version)" if "${LINT[@]}" then @@ -91,7 +82,7 @@ function _eclint function _hadolint { local SCRIPT='HADOLINT' - local LINT=(hadolint -c "${CDIR}/.hadolint.yaml") + local LINT=(hadolint -c "${CDIR}/test/linting/.hadolint.yaml") if ! __in_path "${LINT[0]}" then @@ -99,11 +90,9 @@ function _hadolint return 2 fi - __log_info 'linter version:' \ - "$(${LINT[0]} --version | grep -E -o "v[0-9\.]*")" + __log_info "$(${LINT[0]} --version | grep -E -o "[0-9\.]*")" - if git ls-files --exclude='Dockerfile*' --ignored | \ - xargs --max-lines=1 "${LINT[@]}" + if "${LINT[@]}" Dockerfile then __log_success else @@ -124,8 +113,7 @@ function _shellcheck return 2 fi - __log_info 'linter version:' \ - "$(${LINT[0]} --version | grep -m 2 -o "[0-9.]*")" + __log_info "$(${LINT[0]} --version | grep -m 2 -o "[0-9.]*")" # an overengineered solution to allow shellcheck -x to # properly follow `source=` when sourcing @@ -186,22 +174,21 @@ function _shellcheck fi } -function _main +function __main { - case ${1:-} in + case "${1:-}" in 'eclint' ) _eclint ;; 'hadolint' ) _hadolint ;; 'shellcheck' ) _shellcheck ;; *) - __log_failure \ - "${SCRIPT}: '${1}' is not a command nor an option." - exit 3 + __log_failure "'${1:-}' is not a command nor an option." + return 3 ;; esac } # prefer linters installed in tools -PATH="$(pwd)/tools:${PATH}" +PATH="${CDIR}/tools:${PATH}" export PATH -_main "${@}" || exit ${?} +__main "${@}" || exit ${?}