File: ci-runner.sh

package info (click to toggle)
golang-github-coreos-go-systemd 22.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 656 kB
  • sloc: sh: 101; makefile: 4
file content (111 lines) | stat: -rwxr-xr-x 2,464 bytes parent folder | download
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
#!/usr/bin/env bash
set -e
set -o pipefail

PROJ="go-systemd"
ORG_PATH="github.com/coreos"
REPO_PATH="${ORG_PATH}/${PROJ}"

PACKAGES="activation daemon dbus internal/dlopen journal login1 machine1 sdjournal unit util import1"
EXAMPLES="activation listen udpconn"

function build_source {
    go build ./...
}

function build_tests {
    rm -rf ./test_bins ; mkdir -p ./test_bins
    for pkg in ${PACKAGES}; do
        echo "  - ${pkg}"
        go test -c -o ./test_bins/${pkg}.test ./${pkg}
    done
    for ex in ${EXAMPLES}; do
        echo "  - examples/${ex}"
        go build -o ./test_bins/${ex}.example ./examples/activation/${ex}.go
    done
    # just to make sure it's buildable
    go build -o ./test_bins/journal ./examples/journal/
}

function run_tests {
    pushd test_bins
    sudo -v
    for pkg in ${PACKAGES}; do
        echo "  - ${pkg}"
        sudo -E ./${pkg}.test -test.v
    done
    popd
    sudo rm -rf ./test_bins
}

function go_fmt {
    for pkg in ${PACKAGES}; do
        echo "  - ${pkg}"
        fmtRes=$(gofmt -l "./${pkg}")
        if [ -n "${fmtRes}" ]; then
            echo -e "gofmt checking failed:\n${fmtRes}"
            exit 255
        fi
    done
}

function go_vet {
    for pkg in ${PACKAGES}; do
        echo "  - ${pkg}"
        vetRes=$(go vet "./${pkg}")
        if [ -n "${vetRes}" ]; then
            echo -e "govet checking failed:\n${vetRes}"
            exit 254
        fi
    done
}

function license_check {
    licRes=$(for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
  	             head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e "  ${file}"
  	         done;)
    if [ -n "${licRes}" ]; then
        echo -e "license header checking failed:\n${licRes}"
  	    exit 253
    fi
}

export GO15VENDOREXPERIMENT=1

subcommand="$1"
case "$subcommand" in
    "build_source" )
        echo "Building source..."
        build_source
        ;;

    "build_tests" )
        echo "Building tests..."
        build_tests
        ;;

    "run_tests" )
        echo "Running tests..."
        run_tests
        ;;

    "go_fmt" )
        echo "Checking gofmt..."
        go_fmt
        ;;

    "go_vet" )
        echo "Checking govet..."
        go_vet
        ;;

    "license_check" )
        echo "Checking licenses..."
        license_check
        ;;

    * )
        echo "Error: unrecognized subcommand (hint: try with 'run_tests')."
        exit 1
    ;;
esac