Uploaded image for project: 'VOLTHA'
  1. VOLTHA
  2. VOL-2057

Makefile dynamic install of go-related tooling is not working right

    XMLWordPrintable

    Details

      Description

      The following doesn't work as it was intended: 

      GO_JUNIT_REPORT:=$(shell which go-junit-report)
      GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
      test:
      ifeq (,$(GO_JUNIT_REPORT))
              go get -u github.com/jstemmer/go-junit-report
              @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
      endif
      ifeq (,$(GOCOVER_COBERTURA))
              go get -u github.com/t-yuki/gocover-cobertura
              @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
      endif
              @mkdir -p ./tests/results
              @go test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
              RETURN=$$? ;\
              $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
              $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
              exit $$RETURN 

      For example, if go-junit-report is not installed when the Makefile is run, the go-test-results.out is zero bytes and the Makefile does not report an error. 

      I think this has something to do with scoping / evaluation of Makefile variables, which may not work as expected when set inside actions. The problem is `@GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report` doesn't actually set GO_JUNIT_REPORT for subsequent commands.

      To reproduce, `GO111MODULE=on go clean -i github.com/jstemmer/go-junit-report && make test && ls -al tests/results`

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            scottb Scott Baker
            Reporter:
            scottb Scott Baker
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews