...

Text file src/github.com/coreos/go-systemd/v22/scripts/ci-runner.sh

Documentation: github.com/coreos/go-systemd/v22/scripts

     1#!/usr/bin/env bash
     2set -e
     3set -o pipefail
     4
     5PROJ="go-systemd"
     6ORG_PATH="github.com/coreos"
     7REPO_PATH="${ORG_PATH}/${PROJ}"
     8
     9PACKAGES="activation daemon dbus internal/dlopen journal login1 machine1 sdjournal unit util import1"
    10EXAMPLES="activation listen udpconn"
    11
    12function build_source {
    13    go build ./...
    14}
    15
    16function build_tests {
    17    rm -rf ./test_bins ; mkdir -p ./test_bins
    18    for pkg in ${PACKAGES}; do
    19        echo "  - ${pkg}"
    20        go test -c -o ./test_bins/${pkg}.test ./${pkg}
    21    done
    22    for ex in ${EXAMPLES}; do
    23        echo "  - examples/${ex}"
    24        go build -o ./test_bins/${ex}.example ./examples/activation/${ex}.go
    25    done
    26    # just to make sure it's buildable
    27    go build -o ./test_bins/journal ./examples/journal/
    28}
    29
    30function run_tests {
    31    pushd test_bins
    32    sudo -v
    33    for pkg in ${PACKAGES}; do
    34        echo "  - ${pkg}"
    35        sudo -E ./${pkg}.test -test.v
    36    done
    37    popd
    38    sudo rm -rf ./test_bins
    39}
    40
    41function go_fmt {
    42    for pkg in ${PACKAGES}; do
    43        echo "  - ${pkg}"
    44        fmtRes=$(gofmt -l "./${pkg}")
    45        if [ -n "${fmtRes}" ]; then
    46            echo -e "gofmt checking failed:\n${fmtRes}"
    47            exit 255
    48        fi
    49    done
    50}
    51
    52function go_vet {
    53    for pkg in ${PACKAGES}; do
    54        echo "  - ${pkg}"
    55        vetRes=$(go vet "./${pkg}")
    56        if [ -n "${vetRes}" ]; then
    57            echo -e "govet checking failed:\n${vetRes}"
    58            exit 254
    59        fi
    60    done
    61}
    62
    63function license_check {
    64    licRes=$(for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
    65  	             head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e "  ${file}"
    66  	         done;)
    67    if [ -n "${licRes}" ]; then
    68        echo -e "license header checking failed:\n${licRes}"
    69  	    exit 253
    70    fi
    71}
    72
    73export GO15VENDOREXPERIMENT=1
    74
    75subcommand="$1"
    76case "$subcommand" in
    77    "build_source" )
    78        echo "Building source..."
    79        build_source
    80        ;;
    81
    82    "build_tests" )
    83        echo "Building tests..."
    84        build_tests
    85        ;;
    86
    87    "run_tests" )
    88        echo "Running tests..."
    89        run_tests
    90        ;;
    91
    92    "go_fmt" )
    93        echo "Checking gofmt..."
    94        go_fmt
    95        ;;
    96
    97    "go_vet" )
    98        echo "Checking govet..."
    99        go_vet
   100        ;;
   101
   102    "license_check" )
   103        echo "Checking licenses..."
   104        license_check
   105        ;;
   106
   107    * )
   108        echo "Error: unrecognized subcommand (hint: try with 'run_tests')."
   109        exit 1
   110    ;;
   111esac

View as plain text