Skip to content

Commit

Permalink
[IMPROVED] Move CI to github actions (#1623)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Piotrowski <[email protected]>
  • Loading branch information
piotrpio authored Sep 5, 2024
1 parent b61c7c5 commit a06b6a9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 5 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/workflows/latest-server.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
5 changes: 3 additions & 2 deletions nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 3 additions & 2 deletions scripts/cov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a06b6a9

Please sign in to comment.