diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..e65f33eca8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: release +on: + push: + tags: + - '*' +jobs: + release: + name: Release with Go ${{ matrix.go-version }} + environment: release + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.15.7] + steps: + - name: Install rpm + run: sudo apt-get install rpm + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install gox + run: GO111MODULE=off go get github.com/mitchellh/gox + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Release on Github + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist --release-notes=misc/release/notes.md + env: + # note custom secret here since we need access to Centrifugo Homebrew repo. + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + + - name: Release on Packagecloud + env: + PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }} + run: misc/scripts/release_packagecloud.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..f9e4245289 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: test +on: [push, pull_request] +jobs: + golangci: + name: Lint + runs-on: ubuntu-latest + # Prevent duplicate builds on internal PRs. + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.29 + test: + name: Test with Go ${{ matrix.go-version }} + runs-on: ubuntu-latest + # Prevent duplicate builds on internal PRs. + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + strategy: + matrix: + go-version: [1.15] + steps: + - name: Install Go stable version + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install cover + run: GO111MODULE=off go get golang.org/x/tools/cmd/cover + + - name: Test + run: make test diff --git a/.goreleaser.yml b/.goreleaser.yml index becf5011de..3e1e29321d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -7,7 +7,7 @@ release: prerelease: false brews: - - github: + tap: owner: centrifugal name: homebrew-centrifugo folder: Formula @@ -73,7 +73,7 @@ signs: artifacts: none dockers: - - binaries: + ids: - centrifugo goos: linux goarch: amd64 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 40adcec7a1..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -sudo: required - -language: go - -env: - - GO111MODULE=on - -go: - # Use quotes here: - # https://github.com/travis-ci/gimme/issues/132 - - '1.15.x' - - 'tip' - -addons: - apt: - packages: - # needed for the nfpm pipe: - - rpm - -services: - - docker - - redis - -before_install: - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; fi' - - GO111MODULE=off go get golang.org/x/tools/cmd/cover - - GO111MODULE=off go get github.com/mitchellh/gox - -script: make ci - -deploy: - - provider: script - skip_cleanup: true - script: misc/release/release.sh --release-notes=misc/release/notes.md - on: - tags: true - go: '1.15.x' - - provider: script - script: misc/scripts/travis_packagecloud.sh - on: - tags: true - go: '1.15.x' diff --git a/Makefile b/Makefile index 0ee89f22eb..6bbc93171e 100644 --- a/Makefile +++ b/Makefile @@ -61,5 +61,3 @@ local-deps: build: CGO_ENABLED=0 go build -mod=vendor - -ci: deps test diff --git a/internal/api/encoding.go b/internal/api/encoding.go index d0f3399b54..b706fa706e 100644 --- a/internal/api/encoding.go +++ b/internal/api/encoding.go @@ -54,9 +54,7 @@ func GetCommandDecoder(enc Encoding, data []byte) CommandDecoder { } // PutCommandDecoder ... -func PutCommandDecoder(_ Encoding, _ CommandDecoder) { - return -} +func PutCommandDecoder(_ Encoding, _ CommandDecoder) {} // GetDecoder ... func GetDecoder(enc Encoding) Decoder { @@ -67,9 +65,7 @@ func GetDecoder(enc Encoding) Decoder { } // PutDecoder ... -func PutDecoder(_ Encoding, _ Decoder) { - return -} +func PutDecoder(_ Encoding, _ Decoder) {} // GetEncoder ... func GetEncoder(enc Encoding) Encoder { @@ -80,6 +76,4 @@ func GetEncoder(enc Encoding) Encoder { } // PutEncoder ... -func PutEncoder(_ Encoding, _ Encoder) { - return -} +func PutEncoder(_ Encoding, _ Encoder) {} diff --git a/internal/api/raw.go b/internal/api/raw.go index c1eba483ae..a7387dec0b 100644 --- a/internal/api/raw.go +++ b/internal/api/raw.go @@ -32,7 +32,6 @@ func (r Raw) MarshalTo(data []byte) (n int, err error) { // Unmarshal exists to fit gogoprotobuf custom type interface. func (r *Raw) Unmarshal(data []byte) error { if len(data) == 0 { - r = nil return nil } id := Raw(make([]byte, len(data))) diff --git a/internal/client/handler_test.go b/internal/client/handler_test.go index 4218ea8c96..703e397463 100644 --- a/internal/client/handler_test.go +++ b/internal/client/handler_test.go @@ -100,14 +100,6 @@ func newTestTransport() *testTransport { } } -func (t *testTransport) setProtocolType(pType centrifuge.ProtocolType) { - t.protoType = pType -} - -func (t *testTransport) setSink(sink chan []byte) { - t.sink = sink -} - func (t *testTransport) Write(data []byte) error { t.mu.Lock() defer t.mu.Unlock() diff --git a/internal/health/health.go b/internal/health/health.go index 85214a8a21..34fc4d222d 100644 --- a/internal/health/health.go +++ b/internal/health/health.go @@ -11,7 +11,6 @@ type Config struct{} // Handler handles health endpoint. type Handler struct { - mux *http.ServeMux node *centrifuge.Node config Config } diff --git a/internal/jwks/cache_ttl.go b/internal/jwks/cache_ttl.go index bdd5df8952..44ad4a5810 100644 --- a/internal/jwks/cache_ttl.go +++ b/internal/jwks/cache_ttl.go @@ -64,13 +64,14 @@ func (tc *TTLCache) run() { d = time.Second } - ticker := time.Tick(d) + ticker := time.NewTicker(d) go func() { for { select { - case <-ticker: + case <-ticker.C: tc.cleanup() case <-tc.stop: + ticker.Stop() return } } diff --git a/internal/middleware/log.go b/internal/middleware/log.go index 3a31fa6d66..471de5314f 100644 --- a/internal/middleware/log.go +++ b/internal/middleware/log.go @@ -29,7 +29,6 @@ func LogRequest(h http.Handler) http.Handler { } else { h.ServeHTTP(w, r) } - return }) } @@ -69,5 +68,6 @@ func (lrw *logResponseWriter) Flush() { // CloseNotify as SockJS uses http.CloseNotifier. func (lrw *logResponseWriter) CloseNotify() <-chan bool { + //nolint:staticcheck return lrw.ResponseWriter.(http.CloseNotifier).CloseNotify() } diff --git a/main.go b/main.go index 33cd918933..a48ed8a048 100644 --- a/main.go +++ b/main.go @@ -736,7 +736,7 @@ func handleSignals(configFile string, n *centrifuge.Node, ruleContainer *rule.Co }() } - ctx, _ := context.WithTimeout(context.Background(), shutdownTimeout) + ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout) for _, srv := range httpServers { wg.Add(1) @@ -749,6 +749,7 @@ func handleSignals(configFile string, n *centrifuge.Node, ruleContainer *rule.Co _ = n.Shutdown(ctx) wg.Wait() + cancel() if pidFile != "" { _ = os.Remove(pidFile) diff --git a/misc/scripts/release_packagecloud.sh b/misc/scripts/release_packagecloud.sh new file mode 100755 index 0000000000..b044ccbd18 --- /dev/null +++ b/misc/scripts/release_packagecloud.sh @@ -0,0 +1,7 @@ +#!/bin/sh +sudo gem install rake +sudo gem install package_cloud +sudo gem install fpm +sudo apt-get install -y rpm +make package +make packagecloud diff --git a/misc/scripts/travis_packagecloud.sh b/misc/scripts/travis_packagecloud.sh deleted file mode 100755 index 1767c7890b..0000000000 --- a/misc/scripts/travis_packagecloud.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -gem install package_cloud -gem install fpm -sudo apt-get install -y rpm -make package -make packagecloud