diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..2a93c859 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,69 @@ +--- +name: test + +on: ["push", "pull_request"] + +env: + GO_VERSION: "1.14" + LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le" + +jobs: + build: + name: Build all linux architectures + runs-on: ubuntu-latest + steps: + - name: setup go + uses: actions/setup-go@v1 + with: + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v2 + + - name: Build on all supported architectures + run: | + set -e + for arch in ${LINUX_ARCHES}; do + echo "Building for arch $arch" + GOARCH=$arch ./build_linux.sh + rm bin/* + done + + test-linux: + name: Run tests on Linux amd64 + runs-on: ubuntu-latest + steps: + - name: setup go + uses: actions/setup-go@v1 + with: + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v2 + + - name: Install test binaries + env: + GO111MODULE: off + run: | + go get github.com/containernetworking/cni/cnitool + go get github.com/mattn/goveralls + go get github.com/modocache/gover + + - name: test + run: PATH=$PATH:$(go env GOPATH)/bin COVERALLS=1 ./test_linux.sh + + - name: Send coverage to coveralls + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PATH=$PATH:$(go env GOPATH)/bin + gover + goveralls -coverprofile=gover.coverprofile -service=github + + test-win: + name: Build and run tests on Windows + runs-on: windows-latest + steps: + - name: setup go + uses: actions/setup-go@v1 + with: + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v2 + - name: test + run: bash ./test_windows.sh diff --git a/build_linux.sh b/build_linux.sh index 03c04aad..6f8340b5 100755 --- a/build_linux.sh +++ b/build_linux.sh @@ -1,21 +1,11 @@ #!/usr/bin/env bash set -e -cd $(dirname "$0") +cd "$(dirname "$0")" if [ "$(uname)" == "Darwin" ]; then export GOOS="${GOOS:-linux}" fi -ORG_PATH="github.com/containernetworking" -export REPO_PATH="${ORG_PATH}/plugins" - -if [ ! -h gopath/src/${REPO_PATH} ]; then - mkdir -p gopath/src/${ORG_PATH} - ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 -fi - -export GOPATH=${PWD}/gopath -export GO="${GO:-go}" export GOFLAGS="${GOFLAGS} -mod=vendor" mkdir -p "${PWD}/bin" @@ -25,9 +15,9 @@ PLUGINS="plugins/meta/* plugins/main/* plugins/ipam/*" for d in $PLUGINS; do if [ -d "$d" ]; then plugin="$(basename "$d")" - if [ $plugin != "windows" ]; then + if [ "${plugin}" != "windows" ]; then echo " $plugin" - $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d + ${GO:-go} build -o "${PWD}/bin/$plugin" "$@" ./"$d" fi fi done diff --git a/build_windows.sh b/build_windows.sh index c6f8979d..d71cf686 100755 --- a/build_windows.sh +++ b/build_windows.sh @@ -1,25 +1,15 @@ #!/usr/bin/env bash set -e -cd $(dirname "$0") - -ORG_PATH="github.com/containernetworking" -export REPO_PATH="${ORG_PATH}/plugins" - -export GOPATH=$(mktemp -d) -mkdir -p ${GOPATH}/src/${ORG_PATH} -trap "{ rm -rf $GOPATH; }" EXIT -ln -s ${PWD} ${GOPATH}/src/${REPO_PATH} || exit 255 +cd "$(dirname "$0")" export GO="${GO:-go}" export GOOS=windows export GOFLAGS="${GOFLAGS} -mod=vendor" -echo $GOFLAGS +echo "$GOFLAGS" -PLUGINS=$(cat plugins/windows_only.txt) +PLUGINS=$(cat plugins/windows_only.txt | dos2unix ) for d in $PLUGINS; do - if [ -d "$d" ]; then - plugin="$(basename "$d").exe" - echo " $plugin" - $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d - fi + plugin="$(basename "$d").exe" + echo "building $plugin" + $GO build -o "${PWD}/bin/$plugin" "$@" ./"${d}" done diff --git a/plugins/windows_only.txt b/plugins/windows_only.txt index 47f31094..2fec309f 100644 --- a/plugins/windows_only.txt +++ b/plugins/windows_only.txt @@ -1,4 +1,4 @@ plugins/ipam/host-local plugins/main/windows/win-bridge plugins/main/windows/win-overlay -plugins/meta/flannel \ No newline at end of file +plugins/meta/flannel diff --git a/test_linux.sh b/test_linux.sh index d726ddb3..29c13557 100755 --- a/test_linux.sh +++ b/test_linux.sh @@ -7,7 +7,7 @@ set -e # switch into the repo root directory -cd "$(dirname $0)" +cd "$(dirname "$0")" # Build all plugins before testing source ./build_linux.sh @@ -15,7 +15,7 @@ source ./build_linux.sh echo "Running tests" function testrun { - sudo -E bash -c "umask 0; cd ${GOPATH}/src; PATH=${GOROOT}/bin:$(pwd)/bin:${PATH} go test $@" + sudo -E bash -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test $@" } COVERALLS=${COVERALLS:-""} @@ -26,36 +26,30 @@ else echo "without coverage profile generation..." fi -PKG=${PKG:-$(cd ${GOPATH}/src/${REPO_PATH}; go list ./... | xargs echo)} +PKG=${PKG:-$(go list ./... | xargs echo)} -# coverage profile only works per-package i=0 for t in ${PKG}; do if [ -n "${COVERALLS}" ]; then COVERFLAGS="-covermode set -coverprofile ${i}.coverprofile" fi + echo "${t}" testrun "${COVERFLAGS:-""} ${t}" i=$((i+1)) done -# Submit coverage information -if [ -n "${COVERALLS}" ]; then - gover - goveralls -service=travis-ci -coverprofile=gover.coverprofile -fi - echo "Checking gofmt..." fmtRes=$(go fmt $PKG) if [ -n "${fmtRes}" ]; then - echo -e "go fmt checking failed:\n${fmtRes}" - exit 255 + echo -e "go fmt checking failed:\n${fmtRes}" + exit 255 fi echo "Checking govet..." vetRes=$(go vet $PKG) if [ -n "${vetRes}" ]; then - echo -e "govet checking failed:\n${vetRes}" - exit 255 + echo -e "govet checking failed:\n${vetRes}" + exit 255 fi # Run the pkg/ns tests as non root user diff --git a/test_windows.sh b/test_windows.sh index 36610dd8..a8dfa63a 100755 --- a/test_windows.sh +++ b/test_windows.sh @@ -3,12 +3,18 @@ # Run CNI plugin tests. # set -e +cd "$(dirname "$0")" source ./build_windows.sh echo "Running tests" -PLUGINS=$(cat plugins/windows_only.txt | tr '\n' ' ') -GINKGO_FLAGS="-p -r --randomizeAllSpecs --randomizeSuites --failOnPending --progress pkg/hns $PLUGINS" +PKGS="./pkg/hns/..." -bash -c "cd ${GOPATH}/src/${REPO_PATH}; PATH='${GOROOT}/bin:$(pwd)/bin:${PATH}' ginkgo ${GINKGO_FLAGS}" +PLUGINS=$(cat plugins/windows_only.txt | dos2unix ) +for d in $PLUGINS; do + PKGS="$PKGS ./$d/..." +done + +echo "testing packages $PKGS" +go test -v $PKGS -ginkgo.randomizeAllSpecs -ginkgo.failOnPending -ginkgo.progress