diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index 3c7f77c4d9..cbf45344ff 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -32,34 +32,42 @@ jobs: - name: install go uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: "1.17" - - name: install golangci-lint and goveralls - run: | - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GITHUB_WORKSPACE v1.49.0 - go install github.com/mattn/goveralls@latest - - - name: test and lint backend + - name: test and build backend run: | go test -race -timeout=60s -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov_tmp ./... cat $GITHUB_WORKSPACE/profile.cov_tmp | grep -v "_mock.go" > $GITHUB_WORKSPACE/profile.cov - $GITHUB_WORKSPACE/golangci-lint --config ${GITHUB_WORKSPACE}/backend/.golangci.yml run --out-format=github-actions ./... + go build -race ./... working-directory: backend/app env: TZ: "America/Chicago" - - name: test and lint examples + - name: test examples run: | - go version - $GITHUB_WORKSPACE/golangci-lint version go test -race ./... - $GITHUB_WORKSPACE/golangci-lint --config ${GITHUB_WORKSPACE}/backend/.golangci.yml run --out-format=github-actions ./... + go build -race ./... working-directory: backend/_example/memory_store env: TZ: "America/Chicago" + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + working-directory: backend/app + + - name: golangci-lint on example directory + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --config ../../.golangci.yml + working-directory: backend/_example/memory_store + - name: submit coverage - run: goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov + run: | + go install github.com/mattn/goveralls@latest + goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov working-directory: backend env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/backend/app/main.go b/backend/app/main.go index b5a673d5a9..4118e23810 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -56,9 +56,8 @@ func main() { if _, err := p.Parse(); err != nil { if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { os.Exit(0) - } else { - os.Exit(1) } + os.Exit(1) } } diff --git a/backend/app/migrator/native_test.go b/backend/app/migrator/native_test.go index 9c1e44cd26..88db1c2a73 100644 --- a/backend/app/migrator/native_test.go +++ b/backend/app/migrator/native_test.go @@ -163,7 +163,7 @@ func TestNative_ImportManyWithError(t *testing.T) { buf := &bytes.Buffer{} buf.WriteString(`{"version":1, "users":[], "posts":[]}` + "\n") for i := 0; i < 100; i++ { - buf.WriteString(fmt.Sprintf(goodRec, i)) + fmt.Fprintf(buf, goodRec, i) } buf.WriteString("{}\n") buf.WriteString("{}\n") diff --git a/backend/app/rest/api/migrator.go b/backend/app/rest/api/migrator.go index 3bc540194d..731a4ed56b 100644 --- a/backend/app/rest/api/migrator.go +++ b/backend/app/rest/api/migrator.go @@ -163,7 +163,7 @@ func (m *Migrator) remapCtrl(w http.ResponseWriter, r *http.Request) { rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "remap failed, bad given rules", rest.ErrDecode) return } - defer r.Body.Close() + defer r.Body.Close() //nolint gosec // we don't care about response body // start remap procedure with mapper go func() { diff --git a/backend/app/rest/proxy/image.go b/backend/app/rest/proxy/image.go index e9c3b1d6f2..aa0319f7f7 100644 --- a/backend/app/rest/proxy/image.go +++ b/backend/app/rest/proxy/image.go @@ -159,7 +159,7 @@ func (p Image) downloadImage(ctx context.Context, imgURL string) ([]byte, error) if err != nil { return nil, fmt.Errorf("can't download image %s: %w", imgURL, err) } - defer resp.Body.Close() + defer resp.Body.Close() //nolint gosec // we don't care about response body if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("got unsuccessful response status %d while fetching %s", resp.StatusCode, imgURL) diff --git a/backend/app/store/image/image_test.go b/backend/app/store/image/image_test.go index 5e234009b9..7c9483b5ec 100644 --- a/backend/app/store/image/image_test.go +++ b/backend/app/store/image/image_test.go @@ -287,7 +287,7 @@ func TestCachedImgID(t *testing.T) { assert.Equal(t, "cached_images/"+Sha1Str("example.org")+"-"+Sha1Str(imgURL), img) } -func TestService_DoubleClose(t *testing.T) { +func TestService_DoubleClose(*testing.T) { store := StoreMock{} svc := NewService(&store, ServiceParams{EditDuration: 20 * time.Millisecond}) svc.Close(context.TODO()) diff --git a/backend/app/store/service/title_test.go b/backend/app/store/service/title_test.go index 2dd5af762d..3e3bd79b39 100644 --- a/backend/app/store/service/title_test.go +++ b/backend/app/store/service/title_test.go @@ -124,7 +124,7 @@ func TestTitle_GetFailed(t *testing.T) { assert.Equal(t, int32(1), atomic.LoadInt32(&hits), "hit once, errors cached") } -func TestTitle_DoubleClosed(t *testing.T) { +func TestTitle_DoubleClosed(*testing.T) { ex := NewTitleExtractor(http.Client{Timeout: 5 * time.Second}) ex.Close() // second call should not result in panic