From 883a535a7d1836e228d330956816147925669b42 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 8 Nov 2021 09:47:29 -0800 Subject: [PATCH 1/4] initial test build drone script --- .drone.yml | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..ba0459f --- /dev/null +++ b/.drone.yml @@ -0,0 +1,77 @@ +--- +kind: pipeline +type: docker +name: linux-test + +steps: + - name: fetch + image: golang + volumes: + - name: deps + path: /go + commands: + - go get -u golang.org/x/lint/golint + - git fetch --tags + - go get + - echo `git describe --tags` > VERSION + - echo `date +%G-%m-%d-%H-%M` > BUILDDATE + + - name: quality + image: golang + volumes: + - name: deps + path: /go + commands: + - go list ./... | xargs go vet + - go list ./... | xargs golint -set_exit_status + + - name: units-tests + image: golang + volumes: + - name: deps + path: /go + commands: + - sh testing/tests.sh + + - name: test-builda-app + image: golang + volumes: + - name: deps + path: /go + commands: + - cd app + - go build + + - name: notify-email + image: drillster/drone-email + settings: + host: build.openprivacy.ca + port: 25 + skip_verify: true + from: drone@openprivacy.ca + when: + status: [failure] + + - name: notify-gogs + image: openpriv/drone-gogs + when: + event: pull_request + status: [success, changed, failure] + environment: + GOGS_ACCOUNT_TOKEN: + from_secret: gogs_account_token + settings: + gogs_url: https://git.openprivacy.ca + +volumes: + # gopath where bin and pkg lives to persist across steps + - name: deps + temp: {} + +trigger: + repo: cwtch.im/server + branch: trunk + event: + - push + - pull_request + - tag From 6bff3cd74ddbcb14058a6cf5a13f6438988d38c4 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 8 Nov 2021 10:29:59 -0800 Subject: [PATCH 2/4] drone + windows + macos --- .drone.yml | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/.drone.yml b/.drone.yml index ba0459f..23a9c6b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -75,3 +75,111 @@ trigger: - push - pull_request - tag + +--- +kind: pipeline +type: docker +name: windows-test + +platform: + os: windows + version: 1809 + +steps: + - name: fetch + image: golang + volumes: + - name: deps + path: C:\godeps + environment: + GOPATH: C:\godeps + commands: + - go get + + - name: units-tests + image: golang + volumes: + - name: deps + path: C:\godeps + environment: + GOPATH: C:\godeps + commands: + - go test -race ${1} -v ./metrics + - go test -race ${1} -v ./storage + - go test -race ${1} -v ./ + + - name: test-builda-app + image: golang + volumes: + - name: deps + path: C:\godeps + environment: + GOPATH: C:\godeps + commands: + - cd app + - go build + +volumes: + # gopath where bin and pkg lives to persist across steps + - name: deps + temp: {} + +trigger: + repo: cwtch.im/server + branch: trunk + event: + - push + - pull_request + - tag +--- +kind: pipeline +type: exec +name: mac-test + +platform: + os: darwin + arch: amd64 + +steps: + - name: fetch + volumes: + - name: deps + path: /go + environment: + PATH: PATH=$PATH:/usr/local/go/bin/ + commands: + - go get -u golang.org/x/lint/golint + - go get + + - name: units-tests + volumes: + - name: deps + path: /go + environment: + PATH: PATH=$PATH:/usr/local/go/bin/ + commands: + - sh testing/tests.sh + + - name: test-builda-app + volumes: + - name: deps + path: /go + environment: + PATH: PATH=$PATH:/usr/local/go/bin/ + commands: + - cd app + - go build + +volumes: + # gopath where bin and pkg lives to persist across steps + - name: deps + temp: {} + +trigger: + repo: cwtch.im/server + branch: trunk + event: + - push + - pull_request + - tag + From c725470ea24a5dd6d98ae6806fbba3298f52c57a Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 8 Nov 2021 14:25:54 -0800 Subject: [PATCH 3/4] remove windows from drone for now --- .drone.yml | 66 +++++------------------------------------------------- 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/.drone.yml b/.drone.yml index 23a9c6b..45a643f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -78,61 +78,6 @@ trigger: --- kind: pipeline -type: docker -name: windows-test - -platform: - os: windows - version: 1809 - -steps: - - name: fetch - image: golang - volumes: - - name: deps - path: C:\godeps - environment: - GOPATH: C:\godeps - commands: - - go get - - - name: units-tests - image: golang - volumes: - - name: deps - path: C:\godeps - environment: - GOPATH: C:\godeps - commands: - - go test -race ${1} -v ./metrics - - go test -race ${1} -v ./storage - - go test -race ${1} -v ./ - - - name: test-builda-app - image: golang - volumes: - - name: deps - path: C:\godeps - environment: - GOPATH: C:\godeps - commands: - - cd app - - go build - -volumes: - # gopath where bin and pkg lives to persist across steps - - name: deps - temp: {} - -trigger: - repo: cwtch.im/server - branch: trunk - event: - - push - - pull_request - - tag ---- -kind: pipeline type: exec name: mac-test @@ -145,9 +90,8 @@ steps: volumes: - name: deps path: /go - environment: - PATH: PATH=$PATH:/usr/local/go/bin/ commands: + - export PATH=$PATH:/usr/local/go/bin - go get -u golang.org/x/lint/golint - go get @@ -155,18 +99,16 @@ steps: volumes: - name: deps path: /go - environment: - PATH: PATH=$PATH:/usr/local/go/bin/ commands: + - export PATH=$PATH:/usr/local/go/bin - sh testing/tests.sh - name: test-builda-app volumes: - name: deps path: /go - environment: - PATH: PATH=$PATH:/usr/local/go/bin/ commands: + - export PATH=$PATH:/usr/local/go/bin - cd app - go build @@ -183,3 +125,5 @@ trigger: - pull_request - tag +# TODO: windows: but need windows docker containers with +# go + gcc to compile sqlite. Will prolly come from likewise work for Cwtch From 7fbe110361f63a6ac22c9c3d16ed1e04ed19cb45 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 8 Nov 2021 15:08:29 -0800 Subject: [PATCH 4/4] golint -> staticcheck and required changes --- .drone.yml | 6 +++--- metrics/metrics.go | 12 +++++------- metrics/monitors.go | 2 +- server.go | 7 +++---- storage/message_store.go | 2 +- testing/quality.sh | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.drone.yml b/.drone.yml index 45a643f..6164b33 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,8 @@ steps: - name: deps path: /go commands: - - go get -u golang.org/x/lint/golint + #- go get -u golang.org/x/lint/golint + - go install honnef.co/go/tools/cmd/staticcheck@latest - git fetch --tags - go get - echo `git describe --tags` > VERSION @@ -23,7 +24,7 @@ steps: path: /go commands: - go list ./... | xargs go vet - - go list ./... | xargs golint -set_exit_status + - staticcheck ./... - name: units-tests image: golang @@ -92,7 +93,6 @@ steps: path: /go commands: - export PATH=$PATH:/usr/local/go/bin - - go get -u golang.org/x/lint/golint - go get - name: units-tests diff --git a/metrics/metrics.go b/metrics/metrics.go index 805515a..589c909 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -179,9 +179,7 @@ func reportLine(t MonitorType, array []float64) string { func (mh *monitorHistory) returnCopy(slice []float64) []float64 { retSlice := make([]float64, len(slice)) mh.lock.Lock() - for i, v := range slice { - retSlice[i] = v - } + copy(retSlice, slice) mh.lock.Unlock() return retSlice } @@ -219,22 +217,22 @@ func (mh *monitorHistory) monitorThread() { minuteAvg := rotateAndAccumulate(mh.perMinutePerHour[:], mh.monitor(), mh.monitorAccumulation) - if time.Now().Sub(mh.timeLastHourRotate) > time.Hour { + if time.Since(mh.timeLastHourRotate) > time.Hour { rotateAndAccumulate(mh.perHourForDay[:], minuteAvg, mh.monitorAccumulation) mh.timeLastHourRotate = time.Now() } - if time.Now().Sub(mh.timeLastDayRotate) > time.Hour*24 { + if time.Since(mh.timeLastDayRotate) > time.Hour*24 { rotateAndAccumulate(mh.perDayForWeek[:], accumulate(mh.perHourForDay[:], mh.monitorAccumulation), mh.monitorAccumulation) mh.timeLastDayRotate = time.Now() } - if time.Now().Sub(mh.timeLastWeekRotate) > time.Hour*24*7 { + if time.Since(mh.timeLastWeekRotate) > time.Hour*24*7 { rotateAndAccumulate(mh.perWeekForMonth[:], accumulate(mh.perDayForWeek[:], mh.monitorAccumulation), mh.monitorAccumulation) mh.timeLastWeekRotate = time.Now() } - if time.Now().Sub(mh.timeLastMonthRotate) > time.Hour*24*7*4 { + if time.Since(mh.timeLastMonthRotate) > time.Hour*24*7*4 { rotateAndAccumulate(mh.perMonthForYear[:], accumulate(mh.perWeekForMonth[:], mh.monitorAccumulation), mh.monitorAccumulation) mh.timeLastMonthRotate = time.Now() } diff --git a/metrics/monitors.go b/metrics/monitors.go index c0da8a2..6a9b973 100644 --- a/metrics/monitors.go +++ b/metrics/monitors.go @@ -90,7 +90,7 @@ func (mp *Monitors) report() { w := bufio.NewWriter(f) - fmt.Fprintf(w, "Uptime: %v\n\n", time.Now().Sub(mp.starttime)) + fmt.Fprintf(w, "Uptime: %v\n\n", time.Since(mp.starttime)) fmt.Fprintln(w, "messages:") mp.Messages.Report(w) diff --git a/server.go b/server.go index 47f2d07..e03d3bf 100644 --- a/server.go +++ b/server.go @@ -87,8 +87,7 @@ func (s *server) Run(acn connectivity.ACN) error { } identity := primitives.InitializeIdentity("", &s.config.PrivateKey, &s.config.PublicKey) - var service tapir.Service - service = new(tor2.BaseOnionService) + service := new(tor2.BaseOnionService) service.Init(acn, s.config.PrivateKey, &identity) s.service = service log.Infof("cwtch server running on cwtch:%s\n", s.Onion()) @@ -138,7 +137,7 @@ func (s *server) KeyBundle() *model.KeyBundle { func (s *server) CheckStatus() (bool, error) { s.lock.RLock() defer s.lock.RUnlock() - if s.onionServiceStopped == true || s.tokenServiceStopped == true { + if s.onionServiceStopped || s.tokenServiceStopped { return s.running, fmt.Errorf("one of more server components are down: onion:%v token service: %v", s.onionServiceStopped, s.tokenServiceStopped) } return s.running, nil @@ -192,7 +191,7 @@ func (s *server) Delete(password string) error { if s.config.Encrypted && !s.config.CheckPassword(password) { s.lock.Unlock() log.Errorf("encryped and checkpassword failed") - return errors.New("Cannot delete server, passwords do not match") + return errors.New("cannot delete server, passwords do not match") } s.lock.Unlock() s.Destroy() diff --git a/storage/message_store.go b/storage/message_store.go index 2e4f83d..aa3d459 100644 --- a/storage/message_store.go +++ b/storage/message_store.go @@ -64,7 +64,7 @@ func (s SqliteMessageStore) FetchMessages() []*groups.EncryptedGroupMessage { func (s SqliteMessageStore) FetchMessagesFrom(signature []byte) []*groups.EncryptedGroupMessage { // If signature is empty then treat this as a complete sync request - if signature == nil || len(signature) == 0 { + if len(signature) == 0 { return s.FetchMessages() } diff --git a/testing/quality.sh b/testing/quality.sh index c913c92..7e2a613 100755 --- a/testing/quality.sh +++ b/testing/quality.sh @@ -9,7 +9,7 @@ go list ./... | xargs go vet echo "" echo "Linting:" -go list ./... | xargs golint +staticcheck ./... echo "Time to format"