From a8d7a8f9346783b41b0ef394ab3ada52d07d3ebd Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Fri, 19 Apr 2024 17:57:20 +0200 Subject: [PATCH 1/6] Move CI to github actions Signed-off-by: Piotr Piotrowski --- .github/workflows/ci.yaml | 32 ++++++++++++++++++ .travis.yml | 70 +++++++++++++++++++-------------------- 2 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..d2a39c50c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,32 @@ +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: 1.22 + cache: false + + - 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/... diff --git a/.travis.yml b/.travis.yml index 9a6b4a89c..63c5dc270 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,36 +1,36 @@ -language: go -go: -- "1.22.x" -- "1.21.x" -go_import_path: github.com/nats-io/nats.go -install: -- go get -t ./... -- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin -- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then - go install github.com/mattn/goveralls@latest; - go install github.com/wadey/gocovmerge@latest; - go install honnef.co/go/tools/cmd/staticcheck@latest; - go install github.com/client9/misspell/cmd/misspell@latest; - fi -before_script: -- $(exit $(go fmt ./... | wc -l)) -- go vet -modfile=go_test.mod ./... -- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then - find . -type f -name "*.go" | xargs misspell -error -locale US; - GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck ./...; - fi -- golangci-lint run ./jetstream/... -script: -- go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off -- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then ./scripts/cov.sh TRAVIS; else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing; fi -after_success: -- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then $HOME/gopath/bin/goveralls -coverprofile=acc.out -service travis-ci; fi +# language: go +# go: +# - "1.22.x" +# - "1.21.x" +# go_import_path: github.com/nats-io/nats.go +# install: +# - go get -t ./... +# - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin +# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then +# go install github.com/mattn/goveralls@latest; +# go install github.com/wadey/gocovmerge@latest; +# go install honnef.co/go/tools/cmd/staticcheck@latest; +# go install github.com/client9/misspell/cmd/misspell@latest; +# fi +# before_script: +# - $(exit $(go fmt ./... | wc -l)) +# - go vet -modfile=go_test.mod ./... +# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then +# find . -type f -name "*.go" | xargs misspell -error -locale US; +# GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck ./...; +# fi +# - golangci-lint run ./jetstream/... +# script: +# - go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off +# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then ./scripts/cov.sh TRAVIS; else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing; fi +# after_success: +# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then $HOME/gopath/bin/goveralls -coverprofile=acc.out -service travis-ci; fi -jobs: - include: - - name: "Go: 1.22.x (nats-server@main)" - go: "1.22.x" - 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)" +# jobs: +# include: +# - name: "Go: 1.22.x (nats-server@main)" +# go: "1.22.x" +# 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)" From 489b24e35db9f8b989f5072294971b01ccc30100 Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Fri, 19 Apr 2024 18:50:07 +0200 Subject: [PATCH 2/6] Add test job Signed-off-by: Piotr Piotrowski --- .github/workflows/ci.yaml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d2a39c50c..4e01af948 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,6 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.22 - cache: false - name: Install deps shell: bash --noprofile --norc -x -eo pipefail {0} @@ -30,3 +29,32 @@ jobs: 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 + run: | + go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off + if [ "${{ matrix.go }}" = "1.21" ]; then + ./scripts/cov.sh CI + elif [ "${{ matrix.go }}" = "1.22" ]; then + go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing + fi \ No newline at end of file From 2dfdcbd86535accae4c2e2bb62ead554c190464d Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Sat, 20 Apr 2024 01:28:29 +0200 Subject: [PATCH 3/6] Remove travis Signed-off-by: Piotr Piotrowski --- .travis.yml | 36 ------------------------------------ nats_test.go | 2 +- scripts/cov.sh | 2 +- 3 files changed, 2 insertions(+), 38 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 63c5dc270..000000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -# language: go -# go: -# - "1.22.x" -# - "1.21.x" -# go_import_path: github.com/nats-io/nats.go -# install: -# - go get -t ./... -# - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin -# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then -# go install github.com/mattn/goveralls@latest; -# go install github.com/wadey/gocovmerge@latest; -# go install honnef.co/go/tools/cmd/staticcheck@latest; -# go install github.com/client9/misspell/cmd/misspell@latest; -# fi -# before_script: -# - $(exit $(go fmt ./... | wc -l)) -# - go vet -modfile=go_test.mod ./... -# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then -# find . -type f -name "*.go" | xargs misspell -error -locale US; -# GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck ./...; -# fi -# - golangci-lint run ./jetstream/... -# script: -# - go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off -# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then ./scripts/cov.sh TRAVIS; else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing; fi -# after_success: -# - if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then $HOME/gopath/bin/goveralls -coverprofile=acc.out -service travis-ci; fi - -# jobs: -# include: -# - name: "Go: 1.22.x (nats-server@main)" -# go: "1.22.x" -# 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)" diff --git a/nats_test.go b/nats_test.go index 7dcdce2cf..7f7e71bce 100644 --- a/nats_test.go +++ b/nats_test.go @@ -94,7 +94,7 @@ func checkErrChannel(t *testing.T, errCh chan error) { } func TestVersionMatchesTag(t *testing.T) { - tag := os.Getenv("TRAVIS_TAG") + tag := os.Getenv("GITHUB_ACTIONS") if tag == "" { t.SkipNow() } diff --git a/scripts/cov.sh b/scripts/cov.sh index 80828cb16..5d3dcb908 100755 --- a/scripts/cov.sh +++ b/scripts/cov.sh @@ -12,7 +12,7 @@ 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 From 4c9d085c19aacb4c7f9106fbd113ae4932a4bf65 Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Mon, 22 Apr 2024 09:06:21 +0200 Subject: [PATCH 4/6] Fix test Signed-off-by: Piotr Piotrowski --- nats_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nats_test.go b/nats_test.go index 7f7e71bce..575e4deba 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("GITHUB_ACTIONS") - 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` From 47225c16450bc1f8f5440514c75512db7ad3ec1d Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Mon, 29 Apr 2024 16:57:56 +0200 Subject: [PATCH 5/6] Add coverage report Signed-off-by: Piotr Piotrowski --- .github/workflows/ci.yaml | 16 ++++++++++++---- .github/workflows/latest-server.yaml | 27 +++++++++++++++++++++++++++ scripts/cov.sh | 3 ++- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/latest-server.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4e01af948..4a375645b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.22 + go-version: 'stable' - name: Install deps shell: bash --noprofile --norc -x -eo pipefail {0} @@ -44,6 +44,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} + - name: Install deps shell: bash --noprofile --norc -x -eo pipefail {0} run: | @@ -51,10 +52,17 @@ jobs: 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.21" ]; then + if [ "${{ matrix.go }}" = "1.22" ]; then ./scripts/cov.sh CI - elif [ "${{ matrix.go }}" = "1.22" ]; then + else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing - fi \ No newline at end of file + 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/scripts/cov.sh b/scripts/cov.sh index 5d3dcb908..fa0fdc19d 100755 --- a/scripts/cov.sh +++ b/scripts/cov.sh @@ -5,7 +5,8 @@ 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 From 1de3c3c532b471d6aa0f85933e370f8ba700ed9a Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Wed, 1 May 2024 09:13:01 +0200 Subject: [PATCH 6/6] Restore travis config Signed-off-by: Piotr Piotrowski --- .travis.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..678c4d031 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,36 @@ +language: go +go: +- "1.22.x" +- "1.21.x" +go_import_path: github.com/nats-io/nats.go +install: +- go get -t ./... +- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin +- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then + go install github.com/mattn/goveralls@latest; + go install github.com/wadey/gocovmerge@latest; + go install honnef.co/go/tools/cmd/staticcheck@latest; + go install github.com/client9/misspell/cmd/misspell@latest; + fi +before_script: +- $(exit $(go fmt ./... | wc -l)) +- go vet -modfile=go_test.mod ./... +- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then + find . -type f -name "*.go" | xargs misspell -error -locale US; + GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck ./...; + fi +- golangci-lint run ./jetstream/... +script: +- go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./... --failfast -vet=off +- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then ./scripts/cov.sh TRAVIS; else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast -vet=off -tags=internal_testing; fi +after_success: +- if [[ "$TRAVIS_GO_VERSION" =~ 1.22 ]]; then $HOME/gopath/bin/goveralls -coverprofile=acc.out -service travis-ci; fi + +jobs: + include: + - name: "Go: 1.22.x (nats-server@main)" + go: "1.22.x" + 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)" \ No newline at end of file