diff --git a/.github/workflows/go-generate.sh b/.github/workflows/go-generate.sh new file mode 100755 index 00000000..d5d211eb --- /dev/null +++ b/.github/workflows/go-generate.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +find . -type f -name "*.go" -exec shasum {} \; > checksums_before.txt +# delete all go-generated files generated (that adhere to the comment convention) +grep --include \*.go --exclude-dir quictrace/ -lrIZ "^// Code generated .* DO NOT EDIT\.$" . | xargs --null rm +# delete all files generated by Genny +grep --include \*.go -lrIZ "This file was automatically generated by genny." . | xargs --null rm +# first generate Genny files to make the code compile +grep --include \*.go -lrI "//go:generate genny" | xargs -L 1 go generate +# now generate everything +go generate ./... +find . -type f -name "*.go" -exec shasum {} \; > checksums_after.txt +DIFF=$(diff checksums_before.txt checksums_after.txt) || true +echo "$DIFF" +if [ -n "$DIFF" ]; then + exit 1 +else + echo "All generated files match." +fi diff --git a/.github/workflows/go-generate.yml b/.github/workflows/go-generate.yml new file mode 100644 index 00000000..c5776abd --- /dev/null +++ b/.github/workflows/go-generate.yml @@ -0,0 +1,19 @@ +on: [push, pull_request] +jobs: + gogenerate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.1 + - name: Install dependencies + run: go build + - name: Install code generators + run: | + go install -v github.com/cheekybits/genny + go install -v github.com/golang/mock/mockgen + go install -v golang.org/x/tools/cmd/goimports + - name: Run code generators + run: | + export GOPATH=$(go env GOPATH) + export PATH=$PATH:$GOPATH/bin + .github/workflows/go-generate.sh diff --git a/.travis.yml b/.travis.yml index 5bcae218..44a660aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ env: - TIMESCALE_FACTOR=20 matrix: - TRAVIS_GOARCH=amd64 TESTMODE=lint - - TRAVIS_GOARCH=amd64 TESTMODE=gogenerate - TRAVIS_GOARCH=amd64 TESTMODE=unit - TRAVIS_GOARCH=amd64 TESTMODE=integration - TRAVIS_GOARCH=386 TESTMODE=unit @@ -26,12 +25,6 @@ before_install: - travis_retry go get golang.org/x/tools/cmd/cover - travis_retry go get github.com/onsi/ginkgo/ginkgo - travis_retry go get github.com/onsi/gomega - - | - if [ ${TESTMODE} == "gogenerate" ]; then - travis_retry go get github.com/cheekybits/genny - travis_retry go get github.com/golang/mock/mockgen - travis_retry go get golang.org/x/tools/cmd/goimports - fi - export GOARCH=$TRAVIS_GOARCH - go env # for debugging - travis_retry go get -t ./... diff --git a/.travis/script.sh b/.travis/script.sh index 310700f6..c00b6c8d 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -7,24 +7,6 @@ if [ "${TESTMODE}" == "lint" ]; then ./bin/golangci-lint run ./... fi -if [ "${TESTMODE}" == "gogenerate" ]; then - find . -type f -name "*.go" -exec shasum {} \; > checksums_before.txt - # delete all go-generated files generated (that adhere to the comment convention) - grep --include \*.go --exclude-dir quictrace/ -lrIZ "^// Code generated .* DO NOT EDIT\.$" . | xargs --null rm - # delete all files generated by Genny - grep --include \*.go -lrIZ "This file was automatically generated by genny." . | xargs --null rm - # first generate Genny files to make the code compile - grep --include \*.go -lrI "//go:generate genny" | xargs -L 1 go generate - # now generate everything - go generate ./... - find . -type f -name "*.go" -exec shasum {} \; > checksums_after.txt - DIFF=$(diff checksums_before.txt checksums_after.txt) - echo "$DIFF" - if [ -n "$DIFF" ]; then - exit 1 - fi -fi - if [ "${TESTMODE}" == "unit" ]; then ginkgo -r -v -cover -randomizeAllSpecs -randomizeSuites -trace -skipPackage integrationtests,benchmark # run unit tests with the Go race detector diff --git a/logging/mock_connection_tracer_test.go b/logging/mock_connection_tracer_test.go index bf00e18c..24d994c8 100644 --- a/logging/mock_connection_tracer_test.go +++ b/logging/mock_connection_tracer_test.go @@ -5,13 +5,14 @@ package logging import ( + net "net" + reflect "reflect" + time "time" + gomock "github.com/golang/mock/gomock" protocol "github.com/lucas-clemente/quic-go/internal/protocol" utils "github.com/lucas-clemente/quic-go/internal/utils" wire "github.com/lucas-clemente/quic-go/internal/wire" - net "net" - reflect "reflect" - time "time" ) // MockConnectionTracer is a mock of ConnectionTracer interface diff --git a/logging/mock_tracer_test.go b/logging/mock_tracer_test.go index 55881a1e..22e39c0d 100644 --- a/logging/mock_tracer_test.go +++ b/logging/mock_tracer_test.go @@ -5,11 +5,12 @@ package logging import ( + net "net" + reflect "reflect" + gomock "github.com/golang/mock/gomock" protocol "github.com/lucas-clemente/quic-go/internal/protocol" wire "github.com/lucas-clemente/quic-go/internal/wire" - net "net" - reflect "reflect" ) // MockTracer is a mock of Tracer interface diff --git a/logging/mockgen.go b/logging/mockgen.go index 9237e40e..1bd6d6c1 100644 --- a/logging/mockgen.go +++ b/logging/mockgen.go @@ -1,4 +1,4 @@ package logging -//go:generate sh -c "mockgen -package logging -destination mock_connection_tracer_test.go github.com/lucas-clemente/quic-go/logging ConnectionTracer" -//go:generate sh -c "mockgen -package logging -destination mock_tracer_test.go github.com/lucas-clemente/quic-go/logging Tracer" +//go:generate sh -c "mockgen -package logging -self_package github.com/lucas-clemente/quic-go/logging -destination mock_connection_tracer_test.go github.com/lucas-clemente/quic-go/logging ConnectionTracer && goimports -w mock_connection_tracer_test.go" +//go:generate sh -c "mockgen -package logging -self_package github.com/lucas-clemente/quic-go/logging -destination mock_tracer_test.go github.com/lucas-clemente/quic-go/logging Tracer && goimports -w mock_tracer_test.go"