mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
chore(ci): Linting Improved (#2000)
This commit is contained in:
parent
a0f4a37512
commit
abdf681d02
6
.github/workflows/linting.yml
vendored
6
.github/workflows/linting.yml
vendored
|
@ -21,7 +21,7 @@ jobs:
|
||||||
sudo chmod +rx /usr/local/bin/hadolint
|
sudo chmod +rx /usr/local/bin/hadolint
|
||||||
make hadolint
|
make hadolint
|
||||||
env:
|
env:
|
||||||
HADOLINT_VERSION: 1.19.0
|
HADOLINT_VERSION: 2.4.1
|
||||||
- name: ShellCheck
|
- name: ShellCheck
|
||||||
run: |
|
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
|
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}"
|
sudo rm -rf "shellcheck-v${SHELLCHECK_VERSION}"
|
||||||
make shellcheck
|
make shellcheck
|
||||||
env:
|
env:
|
||||||
SHELLCHECK_VERSION: 0.7.1
|
SHELLCHECK_VERSION: 0.7.2
|
||||||
- name: ECLint
|
- name: ECLint
|
||||||
run: |
|
run: |
|
||||||
sudo curl -S -L "https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${ECLINT_VERSION}/ec-linux-amd64.tar.gz" | tar -xaz
|
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
|
sudo chmod +x /usr/bin/eclint
|
||||||
make eclint
|
make eclint
|
||||||
env:
|
env:
|
||||||
ECLINT_VERSION: 2.3.1
|
ECLINT_VERSION: 2.3.5
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -4,9 +4,9 @@ NAME ?= mailserver-testing:ci
|
||||||
VCS_REF = $(shell git rev-parse --short HEAD)
|
VCS_REF = $(shell git rev-parse --short HEAD)
|
||||||
VCS_VER = $(shell git describe --tags --contains --always)
|
VCS_VER = $(shell git describe --tags --contains --always)
|
||||||
|
|
||||||
HADOLINT_VERSION = 1.19.0
|
HADOLINT_VERSION = 2.4.1
|
||||||
SHELLCHECK_VERSION = 0.7.1
|
SHELLCHECK_VERSION = 0.7.2
|
||||||
ECLINT_VERSION = 2.3.1
|
ECLINT_VERSION = 2.3.5
|
||||||
|
|
||||||
export CDIR = $(shell pwd)
|
export CDIR = $(shell pwd)
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,7 @@ VARS[POSTSCREEN_ACTION]="${POSTSCREEN_ACTION:=enforce}"
|
||||||
VARS[RELAY_HOST]="${RELAY_HOST:=}"
|
VARS[RELAY_HOST]="${RELAY_HOST:=}"
|
||||||
VARS[REPORT_RECIPIENT]="${REPORT_RECIPIENT:="0"}"
|
VARS[REPORT_RECIPIENT]="${REPORT_RECIPIENT:="0"}"
|
||||||
VARS[SMTP_ONLY]="${SMTP_ONLY:=0}"
|
VARS[SMTP_ONLY]="${SMTP_ONLY:=0}"
|
||||||
SPAMASSASSIN_SPAM_TO_INBOX_IS_SET="$(\
|
VARS[SPAMASSASSIN_SPAM_TO_INBOX_SET]="${SPAMASSASSIN_SPAM_TO_INBOX:-not 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]="${SPAMASSASSIN_SPAM_TO_INBOX:=0}"
|
VARS[SPAMASSASSIN_SPAM_TO_INBOX]="${SPAMASSASSIN_SPAM_TO_INBOX:=0}"
|
||||||
VARS[SPOOF_PROTECTION]="${SPOOF_PROTECTION:=0}"
|
VARS[SPOOF_PROTECTION]="${SPOOF_PROTECTION:=0}"
|
||||||
VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}"
|
VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}"
|
||||||
|
|
|
@ -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_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
|
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
|
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.'
|
_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
|
fi
|
||||||
|
|
19
test/linting/.ecrc.json
Normal file
19
test/linting/.ecrc.json
Normal 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
ignored:
|
ignored:
|
||||||
|
- DL3005
|
||||||
- DL3008
|
- DL3008
|
||||||
- DL3015
|
- DL3015
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,13 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
# version v0.1.3 stable
|
# version v0.2.0 unstable
|
||||||
# executed by CI / manually (via Make)
|
# executed by Make during CI or manually
|
||||||
# task checks files agains linting targets
|
# task checks files against linting targets
|
||||||
|
|
||||||
SCRIPT="lint.sh"
|
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
|
set -eEuo pipefail
|
||||||
trap '__log_err ${FUNCNAME[0]:-"?"} ${BASH_COMMAND:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR
|
trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" ${LINENO:-?} ${?:-?}' ERR
|
||||||
|
|
||||||
function __log_err
|
function __log_err
|
||||||
{
|
{
|
||||||
|
@ -33,18 +16,14 @@ function __log_err
|
||||||
" – function = ${1} / ${2}" \
|
" – function = ${1} / ${2}" \
|
||||||
" – line = ${3}" \
|
" – line = ${3}" \
|
||||||
" – exit code = ${4}"
|
" – exit code = ${4}"
|
||||||
|
|
||||||
unset CDIR SCRIPT OS VERSION
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ? ––––––––––––––––––––––––––––––––––––––––––––– LOG
|
|
||||||
|
|
||||||
function __log_info
|
function __log_info
|
||||||
{
|
{
|
||||||
printf "\n––– \e[34m%s\e[0m\n%s\n%s\n\n" \
|
printf "\n––– \e[34m%s\e[0m\n%s\n%s\n\n" \
|
||||||
"${SCRIPT:-${0}}" \
|
"${SCRIPT:-${0}}" \
|
||||||
" – type = INFO" \
|
" – type = INFO" \
|
||||||
" – message = ${*}"
|
" – version = ${*}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __log_failure
|
function __log_failure
|
||||||
|
@ -52,7 +31,7 @@ function __log_failure
|
||||||
printf "\n––– \e[91m%s\e[0m\n%s\n%s\n\n" \
|
printf "\n––– \e[91m%s\e[0m\n%s\n%s\n\n" \
|
||||||
"${SCRIPT:-${0}}" \
|
"${SCRIPT:-${0}}" \
|
||||||
" – type = FAILURE" \
|
" – type = FAILURE" \
|
||||||
" – message = ${*:-'errors encountered'}"
|
" – message = ${*:-errors encountered}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __log_success
|
function __log_success
|
||||||
|
@ -63,13 +42,25 @@ function __log_success
|
||||||
" – message = no errors detected"
|
" – message = no errors detected"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __in_path { __which "${@}" && return 0 ; return 1 ; }
|
function __in_path
|
||||||
function __which { command -v "${@}" &>/dev/null ; }
|
{
|
||||||
|
command -v "${@}" &>/dev/null && return 0 ; return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
function _eclint
|
function _eclint
|
||||||
{
|
{
|
||||||
local SCRIPT='EDITORCONFIG LINTER'
|
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]}"
|
if ! __in_path "${LINT[0]}"
|
||||||
then
|
then
|
||||||
|
@ -77,7 +68,7 @@ function _eclint
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__log_info 'linter version:' "$(${LINT[0]} --version)"
|
__log_info "$(${LINT[0]} --version)"
|
||||||
|
|
||||||
if "${LINT[@]}"
|
if "${LINT[@]}"
|
||||||
then
|
then
|
||||||
|
@ -91,7 +82,7 @@ function _eclint
|
||||||
function _hadolint
|
function _hadolint
|
||||||
{
|
{
|
||||||
local SCRIPT='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]}"
|
if ! __in_path "${LINT[0]}"
|
||||||
then
|
then
|
||||||
|
@ -99,11 +90,9 @@ function _hadolint
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__log_info 'linter version:' \
|
__log_info "$(${LINT[0]} --version | grep -E -o "[0-9\.]*")"
|
||||||
"$(${LINT[0]} --version | grep -E -o "v[0-9\.]*")"
|
|
||||||
|
|
||||||
if git ls-files --exclude='Dockerfile*' --ignored | \
|
if "${LINT[@]}" Dockerfile
|
||||||
xargs --max-lines=1 "${LINT[@]}"
|
|
||||||
then
|
then
|
||||||
__log_success
|
__log_success
|
||||||
else
|
else
|
||||||
|
@ -124,8 +113,7 @@ function _shellcheck
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__log_info 'linter version:' \
|
__log_info "$(${LINT[0]} --version | grep -m 2 -o "[0-9.]*")"
|
||||||
"$(${LINT[0]} --version | grep -m 2 -o "[0-9.]*")"
|
|
||||||
|
|
||||||
# an overengineered solution to allow shellcheck -x to
|
# an overengineered solution to allow shellcheck -x to
|
||||||
# properly follow `source=<SOURCE FILE>` when sourcing
|
# properly follow `source=<SOURCE FILE>` when sourcing
|
||||||
|
@ -186,22 +174,21 @@ function _shellcheck
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _main
|
function __main
|
||||||
{
|
{
|
||||||
case ${1:-} in
|
case "${1:-}" in
|
||||||
'eclint' ) _eclint ;;
|
'eclint' ) _eclint ;;
|
||||||
'hadolint' ) _hadolint ;;
|
'hadolint' ) _hadolint ;;
|
||||||
'shellcheck' ) _shellcheck ;;
|
'shellcheck' ) _shellcheck ;;
|
||||||
*)
|
*)
|
||||||
__log_failure \
|
__log_failure "'${1:-}' is not a command nor an option."
|
||||||
"${SCRIPT}: '${1}' is not a command nor an option."
|
return 3
|
||||||
exit 3
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# prefer linters installed in tools
|
# prefer linters installed in tools
|
||||||
PATH="$(pwd)/tools:${PATH}"
|
PATH="${CDIR}/tools:${PATH}"
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
_main "${@}" || exit ${?}
|
__main "${@}" || exit ${?}
|
||||||
|
|
Loading…
Reference in a new issue