summaryrefslogtreecommitdiff
path: root/Build/source/libs/libpng/libpng-src/ci/ci_lint_ci.sh
blob: 123ed482f10218c90a54c060c7050fba789614e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -e

# Copyright (c) 2019-2024 Cosmin Truta.
#
# Use, modification and distribution are subject to the MIT License.
# Please see the accompanying file LICENSE_MIT.txt
#
# SPDX-License-Identifier: MIT

# shellcheck source="ci/lib/ci.lib.sh"
source "$(dirname "$0")/lib/ci.lib.sh"
cd "$CI_TOPLEVEL_DIR"

CI_SHELLCHECK="$(command -v shellcheck || true)"
CI_YAMLLINT="$(command -v yamllint || true)"
CI_LINT_COUNTER=0

function ci_lint_ci_config_files {
    ci_info "linting: CI config files"
    local MY_FILE
    if [[ -x $CI_YAMLLINT ]]
    then
        ci_spawn "$CI_YAMLLINT" --version
        for MY_FILE in "$CI_TOPLEVEL_DIR"/.*.yml
        do
            ci_spawn "$CI_YAMLLINT" --strict "$MY_FILE" ||
                CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1))
        done
    else
        ci_warn "program not found: 'yamllint'; skipping checks"
    fi
}

function ci_lint_ci_scripts {
    ci_info "linting: CI scripts"
    local MY_FILE
    if [[ -x $CI_SHELLCHECK ]]
    then
        ci_spawn "$CI_SHELLCHECK" --version
        for MY_FILE in "$CI_SCRIPT_DIR"/*.sh
        do
            ci_spawn "$CI_SHELLCHECK" -x "$MY_FILE" ||
                CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1))
        done
    else
        ci_warn "program not found: 'shellcheck'; skipping checks"
    fi
}

function ci_lint_ci_scripts_license {
    ci_info "linting: CI scripts license"
    ci_spawn grep -F "MIT License" ci/LICENSE_MIT.txt || {
        ci_warn "bad or missing CI license file: '$CI_SCRIPT_DIR/LICENSE_MIT.txt'"
        CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1))
    }
}

function usage {
    echo "usage: $CI_SCRIPT_NAME"
    exit 0
}

function main {
    local opt
    while getopts ":" opt
    do
        # This ain't a while-loop. It only pretends to be.
        [[ $1 == -[?h]* || $1 == --help ]] && usage
        ci_err "unknown option: '$1'"
    done
    shift $((OPTIND - 1))
    # And... go!
    [[ $# -eq 0 ]] || ci_err "unexpected argument: '$1'"
    ci_lint_ci_config_files
    ci_lint_ci_scripts
    ci_lint_ci_scripts_license
    if [[ $CI_LINT_COUNTER -eq 0 ]]
    then
        ci_info "success!"
        exit 0
    else
        ci_info "failed on $CI_LINT_COUNTER file(s)"
        exit 1
    fi
}

main "$@"