From 42556b90c446714118f0c5ef51a32d115a843362 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:43:15 +0300 Subject: [PATCH 1/7] add nilaway --- .github/workflows/main.yml | 19 +++++++------------ Makefile | 11 ++++++++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ca11cd14..4bea761c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,9 +12,8 @@ jobs: strategy: matrix: go-version: - - 1.18.x - - 1.19.x - - 1.20.x + - 1.22.x + - 1.23.x os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} steps: @@ -22,22 +21,18 @@ jobs: uses: actions/checkout@master - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} + cache: true # caching and restoring go modules and build outputs - run: go env - - name: Cache deps - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Install deps run: go mod download + - name: nilaway + run: make nilaway + - name: Test run: go test -v -race -p=1 -count=1 diff --git a/Makefile b/Makefile index 85b927a5..472cbf17 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ -.PHONY: all .DEFAULT_GOAL := all PACKAGE := github.com/mailgun/mailgun-go +.PHONY: all all: export GO111MODULE=on; go test . -v +.PHONY: godoc godoc: mkdir -p /tmp/tmpgoroot/doc -rm -rf /tmp/tmpgopath/src/${PACKAGE} @@ -13,3 +14,11 @@ godoc: tar -c --exclude='.git' --exclude='tmp' . | tar -x -C /tmp/tmpgopath/src/${PACKAGE} echo -e "open http://localhost:6060/pkg/${PACKAGE}\n" GOROOT=/tmp/tmpgoroot/ GOPATH=/tmp/tmpgopath/ godoc -http=localhost:6060 + +NILAWAY = $(GOPATH)/bin/nilaway +$(NILAWAY): + go install go.uber.org/nilaway/cmd/nilaway@latest + +.PHONY: nilaway +nilaway: $(NILAWAY) + $(NILAWAY) -include-pkgs="github.com/mailgun/maverick-score" -test=false ./... From fdc553cbfc7365ee5423973d63e8644c032e2d83 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:45:23 +0300 Subject: [PATCH 2/7] fix --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 472cbf17..69be13bf 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ PACKAGE := github.com/mailgun/mailgun-go +NILAWAY = $(GOPATH)/bin/nilaway +$(NILAWAY): + go install go.uber.org/nilaway/cmd/nilaway@latest + .PHONY: all all: export GO111MODULE=on; go test . -v @@ -15,10 +19,6 @@ godoc: echo -e "open http://localhost:6060/pkg/${PACKAGE}\n" GOROOT=/tmp/tmpgoroot/ GOPATH=/tmp/tmpgopath/ godoc -http=localhost:6060 -NILAWAY = $(GOPATH)/bin/nilaway -$(NILAWAY): - go install go.uber.org/nilaway/cmd/nilaway@latest - .PHONY: nilaway nilaway: $(NILAWAY) - $(NILAWAY) -include-pkgs="github.com/mailgun/maverick-score" -test=false ./... + $(NILAWAY) -include-pkgs="$(PACKAGE)" -test=false -exclude-errors-in-files=mock_ ./... From c04d814a1b4b3fc5c0041ef4eb39a9a29be6e752 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:48:40 +0300 Subject: [PATCH 3/7] GOPATH --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 69be13bf..c337dbe0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .DEFAULT_GOAL := all PACKAGE := github.com/mailgun/mailgun-go +GOPATH=$(shell go env GOPATH) NILAWAY = $(GOPATH)/bin/nilaway $(NILAWAY): From ccac9ae46d58852f365344e60aaee1992c71ca01 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:06:58 +0300 Subject: [PATCH 4/7] bump CI From 2ef92859886ea1889a07b5295c089a9423746235 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:16:00 +0300 Subject: [PATCH 5/7] fmt --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4bea761c..aecffe40 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,7 @@ on: pull_request: branches: [ master, main ] push: - branches: [master, main ] + branches: [ master, main ] jobs: test: From c09c4e5b20b0c5be4e8a7b612035cec00fa247b4 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:17:31 +0300 Subject: [PATCH 6/7] fix nil pointer dereference --- messages.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/messages.go b/messages.go index 5df22aff..efe0e7d2 100644 --- a/messages.go +++ b/messages.go @@ -914,6 +914,9 @@ func (mg *MailgunImpl) GetStoredAttachment(ctx context.Context, url string) ([]b r.addHeader("Accept", "message/rfc2822") response, err := makeGetRequest(ctx, r) + if err != nil { + return nil, err + } return response.Data, err } From 5fb56e143d00718f10e9e4069e48044555defbdc Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:20:24 +0300 Subject: [PATCH 7/7] added TODO --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c337dbe0..d4028ebb 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ godoc: echo -e "open http://localhost:6060/pkg/${PACKAGE}\n" GOROOT=/tmp/tmpgoroot/ GOPATH=/tmp/tmpgopath/ godoc -http=localhost:6060 +# TODO(vtopc): fix mocks and enable nilaway for them too? .PHONY: nilaway nilaway: $(NILAWAY) $(NILAWAY) -include-pkgs="$(PACKAGE)" -test=false -exclude-errors-in-files=mock_ ./...