diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..4a375645b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: Testing +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 'stable' + + - name: Install deps + shell: bash --noprofile --norc -x -eo pipefail {0} + run: | + go get -t ./... + go install honnef.co/go/tools/cmd/staticcheck@latest + go install github.com/client9/misspell/cmd/misspell@latest + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + + - name: Run linters + shell: bash --noprofile --norc -x -eo pipefail {0} + run: | + $(exit $(go fmt -modfile=go_test.mod ./... | wc -l)) + go vet -modfile=go_test.mod ./... + GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck ./... + find . -type f -name "*.go" | xargs misspell -error -locale US + golangci-lint run --timeout 5m0s ./jetstream/... + + test: + runs-on: ubuntu-latest + + strategy: + matrix: + go: [ "1.21", "1.22" ] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Install deps + shell: bash --noprofile --norc -x -eo pipefail {0} + run: | + go install github.com/mattn/goveralls@latest + go install github.com/wadey/gocovmerge@latest + + - name: Test and coverage + shell: bash --noprofile --norc -x -eo pipefail {0} + run: | + go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off + if [ "${{ matrix.go }}" = "1.22" ]; then + ./scripts/cov.sh CI + else + go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing + fi + + - name: Coveralls + if: matrix.go == '1.22' + uses: coverallsapp/github-action@v2 + with: + file: acc.out \ No newline at end of file diff --git a/.github/workflows/latest-server.yaml b/.github/workflows/latest-server.yaml new file mode 100644 index 000000000..c44523b1a --- /dev/null +++ b/.github/workflows/latest-server.yaml @@ -0,0 +1,27 @@ +name: Test nats-server@main +on: + schedule: + - cron: "30 8 * * *" + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 'stable' + + - name: Get latest server + shell: bash --noprofile --norc -x -eo pipefail {0} + run: | + go get -modfile go_test.mod github.com/nats-io/nats-server/v2@main + + - name: Test + shell: bash --noprofile --norc -x -eo pipefail {0} + run: | + go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off + go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 9a6b4a89c..678c4d031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,4 +33,4 @@ jobs: before_script: - go get -modfile go_test.mod github.com/nats-io/nats-server/v2@main allow_failures: - - name: "Go: 1.22.x (nats-server@main)" + - name: "Go: 1.22.x (nats-server@main)" \ No newline at end of file diff --git a/nats_test.go b/nats_test.go index e64c80133..8f4546a77 100644 --- a/nats_test.go +++ b/nats_test.go @@ -94,10 +94,11 @@ func checkErrChannel(t *testing.T, errCh chan error) { } func TestVersionMatchesTag(t *testing.T) { - tag := os.Getenv("TRAVIS_TAG") - if tag == "" { + refType := os.Getenv("GITHUB_REF_TYPE") + if refType != "tag" { t.SkipNow() } + tag := os.Getenv("GITHUB_REF_NAME") // We expect a tag of the form vX.Y.Z. If that's not the case, // we need someone to have a look. So fail if first letter is not // a `v` diff --git a/scripts/cov.sh b/scripts/cov.sh index 80828cb16..fa0fdc19d 100755 --- a/scripts/cov.sh +++ b/scripts/cov.sh @@ -5,14 +5,15 @@ rm -rf ./cov mkdir cov go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/nats.out . -tags=skip_no_race_tests go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/test.out -coverpkg=github.com/nats-io/nats.go ./test -tags=skip_no_race_tests,internal_testing -go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/jetstream.out -coverpkg=github.com/nats-io/nats.go/jetstream ./jetstream/test -tags=skip_no_race_tests +go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/jetstream.out -coverpkg=github.com/nats-io/nats.go/jetstream ./jetstream/... +go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/service.out -coverpkg=github.com/nats-io/nats.go/micro ./micro/... go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/builtin.out -coverpkg=github.com/nats-io/nats.go/encoders/builtin ./test -run EncBuiltin -tags=skip_no_race_tests go test -modfile=go_test.mod --failfast -vet=off -v -covermode=atomic -coverprofile=./cov/protobuf.out -coverpkg=github.com/nats-io/nats.go/encoders/protobuf ./test -run EncProto -tags=skip_no_race_tests gocovmerge ./cov/*.out > acc.out rm -rf ./cov # Without argument, launch browser results. We are going to push to coveralls only -# from Travis.yml and after success of the build (and result of pushing will not affect +# from ci.yml and after success of the build (and result of pushing will not affect # build result). if [[ $1 == "" ]]; then go tool cover -html=acc.out