aboutsummaryrefslogtreecommitdiff
path: root/support/scripts/generate-gitlab-ci-yml
blob: faa52e85b27d5a74b40de4ca519ac839c19c2119 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -e
set -o pipefail

main() {
    local template="${1}"

    preamble "${template}"

    gen_basics
    gen_defconfigs
    gen_tests
}

preamble() {
    local template="${1}"

    cat - "${template}" <<-_EOF_
	# This file is generated; do not edit!
	# Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines

	image: ${CI_JOB_IMAGE}

_EOF_
}

gen_basics() {
    local tst

    # Skip basic tests when explicitly building defconfigs or runtime tests
    case "${CI_COMMIT_REF_NAME}" in
        (*-defconfigs)      return;;
        (*-*_defconfig)     return;;
        (*-runtime-tests)   return;;
        (*-tests.*)         return;;
    esac

    for tst in DEVELOPERS flake8 package; do
        printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
    done
}

gen_defconfigs() {
    local -a defconfigs
    local template cfg ext

    defconfigs=( $(cd configs; LC_ALL=C ls -1 *_defconfig) )

    if [ -n "${CI_COMMIT_TAG}" ]; then
        # For tags, create a pipeline.
        template=base
    elif [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
        # For pipeline created by using a trigger token.
        template=base
    else
        case "${CI_COMMIT_REF_NAME}" in
            # For master, next, and maintenance branches, only check the defconfigs
            (master|next|????.??.x)
                template=check
                ext=_check
            ;;
            # For the branch or tag name named *-defconfigs, create a pipeline.
            (*-defconfigs)
                template=base
            ;;
            (*-*_defconfig)
                defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
                template=base
            ;;
        esac
    fi

    if [ -n "${template}" ]; then
        for cfg in "${defconfigs[@]}"; do
            printf '%s%s: { extends: .defconfig_%s }\n' \
                   "${cfg}" "${ext}" "${template}"
        done
    fi
}

gen_tests() {
    local -a tests
    local run_tests tst

    tests=( $(./support/testing/run-tests -l 2>&1 \
              | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/'\
              | LC_ALL=C sort)
          )

    run_tests=false
    if [ -n "${CI_COMMIT_TAG}" ]; then
        # For tags, create a pipeline.
        run_tests=true
    elif [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
        # For pipeline created by using a trigger token.
        run_tests=true
    else
        case "${CI_COMMIT_REF_NAME}" in
            # For the branch or tag name named *-runtime-tests, create a pipeline.
            (*-runtime-tests)
                run_tests=true
            ;;
            (*-tests.*)
                tests=( "${CI_COMMIT_REF_NAME##*-}" )
                run_tests=true
            ;;
        esac
    fi

    if ${run_tests}; then
        printf '%s: { extends: .runtime_test_base }\n' "${tests[@]}"
    fi
}

main "${@}"