mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
scripts: revised linting script (#2737)
The new version uses our `log.sh` helper to simplify logging significantly. Moreover, the script was adjusted to the current style and the GitHub workflow was streamlined. The workflow is ot providing the version anymore (which was useless anyway), and has been compacted.
This commit is contained in:
parent
26d241381f
commit
8a4329ae9f
23
.github/workflows/linting.yml
vendored
23
.github/workflows/linting.yml
vendored
|
@ -1,11 +1,9 @@
|
|||
name: "Lint"
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
branches: [ master ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
@ -16,23 +14,12 @@ jobs:
|
|||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Hadolint
|
||||
run: |
|
||||
make hadolint
|
||||
env:
|
||||
HADOLINT_VERSION: 2.4.1
|
||||
run: make hadolint
|
||||
|
||||
- name: ShellCheck
|
||||
run: |
|
||||
make shellcheck
|
||||
env:
|
||||
SHELLCHECK_VERSION: 0.8.0
|
||||
run: make shellcheck
|
||||
|
||||
- name: ECLint
|
||||
run: |
|
||||
make eclint
|
||||
env:
|
||||
ECLINT_VERSION: 2.3.5
|
||||
run: make eclint
|
||||
|
|
|
@ -1,97 +1,52 @@
|
|||
#! /bin/bash
|
||||
|
||||
# version v0.2.0 unstable
|
||||
# executed by Make during CI or manually
|
||||
# version v0.3.0
|
||||
# executed by Make (during CI or manually)
|
||||
# task checks files against linting targets
|
||||
|
||||
SCRIPT="lint.sh"
|
||||
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||
REPO_ROOT=$(realpath "${SCRIPT_DIR}"/../../)
|
||||
|
||||
HADOLINT_VERSION=2.8.0
|
||||
ECLINT_VERSION=2.3.5
|
||||
SHELLCHECK_VERSION=0.8.0
|
||||
|
||||
set -eEuo pipefail
|
||||
shopt -s inherit_errexit
|
||||
trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" ${LINENO:-?} ${?:-?}' ERR
|
||||
|
||||
function __log_err
|
||||
{
|
||||
printf "\n--- \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \
|
||||
" - script = ${SCRIPT:-${0}}" \
|
||||
" - function = ${1} / ${2}" \
|
||||
" - line = ${3}" \
|
||||
" - exit code = ${4}"
|
||||
}
|
||||
REPOSITORY_ROOT=$(realpath "$(dirname "$(readlink -f "${0}")")"/../../)
|
||||
LOG_LEVEL=${LOG_LEVEL:-debug}
|
||||
HADOLINT_VERSION='2.9.2'
|
||||
ECLINT_VERSION='2.4.0'
|
||||
SHELLCHECK_VERSION='0.8.0'
|
||||
|
||||
function __log_info
|
||||
{
|
||||
printf "\n--- \e[34m%s\e[0m\n%s\n%s\n\n" \
|
||||
"${SCRIPT:-${0}}" \
|
||||
" - type = INFO" \
|
||||
" - version = ${*}"
|
||||
}
|
||||
|
||||
function __log_failure
|
||||
{
|
||||
printf "\n--- \e[91m%s\e[0m\n%s\n%s\n\n" \
|
||||
"${SCRIPT:-${0}}" \
|
||||
" - type = FAILURE" \
|
||||
" - message = ${*:-errors encountered}"
|
||||
}
|
||||
|
||||
function __log_success
|
||||
{
|
||||
printf "\n--- \e[32m%s\e[0m\n%s\n%s\n\n" \
|
||||
"${SCRIPT}" \
|
||||
" - type = SUCCESS" \
|
||||
" - message = no errors detected"
|
||||
}
|
||||
|
||||
function __in_path
|
||||
{
|
||||
command -v "${@}" &>/dev/null && return 0 ; return 1 ;
|
||||
}
|
||||
# shellcheck source=./../../target/scripts/helpers/log.sh
|
||||
source "${REPOSITORY_ROOT}/target/scripts/helpers/log.sh"
|
||||
|
||||
function _eclint
|
||||
{
|
||||
local SCRIPT='EDITORCONFIG LINTER'
|
||||
|
||||
if docker run --rm --tty \
|
||||
--volume "${REPO_ROOT}:/ci:ro" \
|
||||
--volume "${REPOSITORY_ROOT}:/ci:ro" \
|
||||
--workdir "/ci" \
|
||||
--name eclint \
|
||||
"mstruebing/editorconfig-checker:${ECLINT_VERSION}" ec -config "/ci/test/linting/.ecrc.json"
|
||||
then
|
||||
__log_success
|
||||
_log 'info' 'ECLint succeeded'
|
||||
else
|
||||
__log_failure
|
||||
_log 'error' 'ECLint failed'
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function _hadolint
|
||||
{
|
||||
local SCRIPT='HADOLINT'
|
||||
|
||||
if docker run --rm --tty \
|
||||
--volume "${REPO_ROOT}:/ci:ro" \
|
||||
--volume "${REPOSITORY_ROOT}:/ci:ro" \
|
||||
--workdir "/ci" \
|
||||
"hadolint/hadolint:v${HADOLINT_VERSION}-alpine" hadolint --config "/ci/test/linting/.hadolint.yaml" Dockerfile
|
||||
then
|
||||
__log_success
|
||||
_log 'info' 'Hadolint succeeded'
|
||||
else
|
||||
__log_failure
|
||||
_log 'error' 'Hadolint failed'
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function _shellcheck
|
||||
{
|
||||
local SCRIPT='SHELLCHECK'
|
||||
|
||||
# File paths for shellcheck:
|
||||
F_SH=$(find . -type f -iname '*.sh' \
|
||||
-not -path './test/bats/*' \
|
||||
|
@ -132,28 +87,28 @@ function _shellcheck
|
|||
# `source=relative/path/to/file.sh` will check the source value in each source-path as well.
|
||||
# shellcheck disable=SC2068
|
||||
if docker run --rm --tty \
|
||||
--volume "${REPO_ROOT}:/ci:ro" \
|
||||
--volume "${REPOSITORY_ROOT}:/ci:ro" \
|
||||
--workdir "/ci" \
|
||||
"koalaman/shellcheck-alpine:v${SHELLCHECK_VERSION}" ${CMD_SHELLCHECK[@]}
|
||||
then
|
||||
__log_success
|
||||
_log 'info' 'ShellCheck succeeded'
|
||||
else
|
||||
__log_failure
|
||||
_log 'error' 'ShellCheck failed'
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function __main
|
||||
function _main
|
||||
{
|
||||
case "${1:-}" in
|
||||
'eclint' ) _eclint ;;
|
||||
'hadolint' ) _hadolint ;;
|
||||
'shellcheck' ) _shellcheck ;;
|
||||
*)
|
||||
__log_failure "'${1:-}' is not a command nor an option."
|
||||
( 'eclint' ) _eclint ;;
|
||||
( 'hadolint' ) _hadolint ;;
|
||||
( 'shellcheck' ) _shellcheck ;;
|
||||
( * )
|
||||
_log 'error' "'${1:-}' is not a command nor an option"
|
||||
return 3
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
__main "${@}" || exit ${?}
|
||||
_main "${@}" || exit ${?}
|
||||
|
|
Loading…
Reference in a new issue