chore(ci): Linting Improved (#2000)

This commit is contained in:
Georg Lauterbach 2021-06-01 18:12:17 +02:00 committed by GitHub
parent a0f4a37512
commit abdf681d02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 56 deletions

View file

@ -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

View file

@ -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)

View file

@ -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}"

View file

@ -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

19
test/linting/.ecrc.json Normal file
View file

@ -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
}
}

View file

@ -1,4 +1,5 @@
ignored:
- DL3005
- DL3008
- DL3015

View file

@ -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=<SOURCE FILE>` 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 ${?}