summaryrefslogtreecommitdiff
path: root/scripts/travis/codegen_verification.sh
blob: ae5887366dcdacfb1e9e166a0b9c5e5e3eebde87 (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
#!/usr/bin/env bash

# codegen_verification.sh - Run the auto-code generation and verify it matches current branch content.
#
# Syntax:   codegen_verification.sh
#
# Usage:    Can be used by either Travis or an ephermal build machine
#
# Examples: scripts/travis/codegen_verification.sh
set -e

ALGORAND_DEADLOCK=enable
export ALGORAND_DEADLOCK
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

# Force re-evaluation of genesis files to see if source files changed w/o running make
touch gen/generate.go

"${SCRIPTPATH}/build.sh"

# Get the go build version.
GOLANG_VERSION=$(./scripts/get_golang_version.sh)

eval "$(~/gimme "${GOLANG_VERSION}")"

"${SCRIPTPATH}"/../buildtools/install_buildtools.sh

make gen

function runGoFmt() {
    unformatted=$(gofmt -l .)
    [ -z "$unformatted" ] && return 0

    # Some files are not gofmt'd. Print message and fail.

    echo >&2 "Go files must be formatted with gofmt. Please run:"
    for fn in $unformatted; do
        echo >&2 "  gofmt -w $PWD/$fn"
    done

    return 1
}

function runGoLint() {
    warningCount=$("$GOPATH"/bin/golint $(go list ./... | grep -v /vendor/ | grep -v /test/e2e-go/) | wc -l | tr -d ' ')
    if [ "${warningCount}" = "0" ]; then
        return 0
    fi

    echo >&2 "golint must be clean.  Please run the following to list issues(${warningCount}):"
    echo >&2 " make lint"

    # run the linter again to output the actual issues
    "$GOPATH"/bin/golint $(go list ./... | grep -v /vendor/ | grep -v /test/e2e-go/) >&2
    return 1
}

echo "Running go vet..."
go vet $(go list ./... | grep -v /test/e2e-go/)

echo "Running gofmt..."
runGoFmt

echo "Running golint..."
runGoLint

echo "Running check_license..."
./scripts/check_license.sh

echo "Rebuild swagger.json files"
make rebuild_swagger

echo "Regenerate config files"
go generate ./config

echo "Running fixcheck"
GOPATH=$(go env GOPATH)
"$GOPATH"/bin/algofix -error */

echo "Updating TEAL Specs"
make -C data/transactions/logic

echo "Regenerate REST server"
touch daemon/algod/api/algod.oas2.json
make -C daemon/algod/api generate

echo Checking Enlistment...
if [[ -n $(git status --porcelain) ]]; then
   echo Enlistment is dirty - did you forget to run make?
   git status -s
   git diff
   exit 1
else
   echo Enlistment is clean
fi

# test binary compatibility
"${SCRIPTPATH}/../../test/platform/test_linux_amd64_compatibility.sh"