refac: generate Go code to render themes
matm opened this issue ยท 23 comments
Generating the code for methods Beautifier.Template()
and Beautifier.Data()
will ease theme management. This way Beautifer.Assets()
can be used to simply define the required assets to build a theme.
- Remove implementions of
Beautifier.Template()
andBeautifier.Data()
for thegolang
(default) theme - Write a Go generator in
pkg/themes/generator.go
that will generate adefault_gen.go
file implementing those two methods with proper content taken fromAssets()
- Update the build system to
go generate
before building
Generating the code for methods
Beautifier.Template()
andBeautifier.Data()
will ease theme management. This wayBeautifer.Assets()
can be used to simply define the required assets to build a theme.
- Remove implementions of
Beautifier.Template()
andBeautifier.Data()
for thegolang
(default) theme- Write a Go generator in
pkg/themes/generator.go
that will generate adefault_gen.go
file implementing those two methods with proper content taken fromAssets()
- Update the build system to
go generate
before building
Hi @matm I don't see generator.go file in pkg/themes/ and we are getting this error
/../github.com/matm/gocov-html/pkg/themes/theme.go:9:14: cannot use defaultTheme{} (type defaultTheme) as type types.Beautifier in slice literal:
defaultTheme does not implement types.Beautifier (missing Data method)
github.com/matm/gocov-html/pkg/themes/theme.go:13:5: cannot use defaultTheme{} (type defaultTheme) as type types.Beautifier in assignment:
defaultTheme does not implement types.Beautifier (missing Data method)
Hi @MdSahilGrab, the generator code has been moved to cmd/generator
on master
. How do you get this error? How do you build it?
Actually we have this command in Dockerfile RUN go get github.com/matm/gocov-html/cmd/gocov-html which we are running when building the code.
@matm so you want to us to use RUN go get github.com/matm/gocov-html/cmd/generator
Okay, can you try with the latest stable release instead? Something like
RUN go install github.com/matm/gocov-html/cmd/gocov-html@latest
Yes we tried but this is also not working
@matm so you want to us to use RUN go get github.com/matm/gocov-html/cmd/generator
Maybe this can help: https://github.com/matm/gocov-html/blob/master/build.mk#L73
Yes we tried but this is also not working
What if you do
RUN go install github.com/matm/gocov-html/cmd/gocov-html@v1.2.0
Let me check
@matm so you want to us to use RUN go get github.com/matm/gocov-html/cmd/generator
Maybe this can help: https://github.com/matm/gocov-html/blob/master/build.mk#L73
Yes we tried but this is also not working
What if you do
RUN go install github.com/matm/gocov-html/cmd/gocov-html@v1.2.0
When we tried this command RUN go install github.com/matm/gocov-html/cmd/gocov-html@latest, we actually got this error.
go: modules disabled by GO111MODULE=off; see 'go help modules'
The command '/bin/sh -c go install github.com/matm/gocov-html/cmd/gocov-html@latest' returned a non-zero code: 1
Maybe this can help: https://github.com/matm/gocov-html/blob/master/build.mk#L73,
How exactly can i use this in dokerfile
Can you paste a working sample of your Dockerfile
here? I need more context, thank you.
@matm yeah this is the Dockerfile we have now which was running successfully till yesterday
RUN ./coverage.sh
RUN go get github.com/jstemmer/go-junit-report
RUN go get github.com/axw/gocov/gocov
RUN go get github.com/AlekSi/gocov-xml
RUN go get github.com/matm/gocov-html/cmd/gocov-html
RUN go test -v -coverprofile=coverage.txt -covermode count ./... 2>&1 | go-junit-report > report.xml
RUN mkdir $GOPATH/coverage
RUN mkdir $GOPATH/lint
RUN gocov convert coverage.txt > coverage.json
RUN gocov-xml < coverage.json > $GOPATH/coverage/coverage.xml
RUN gocov-html < coverage.json > $GOPATH/coverage/index.html
RUN cp report.xml $GOPATH/coverage/report.xml
RUN cp lint_report.xml $GOPATH/lint/lint_report.xml
Which Go compiler version is used by this image?
its golang:1.16-alpine3.14
This works:
FROM golang:1.16-alpine3.14
RUN go get github.com/axw/gocov/gocov
RUN go get github.com/matm/gocov-html/cmd/gocov-html
Then
$ docker build -t tool .
$ docker run --rm -ti tool gocov-html -h
Usage of gocov-html:
-d output CSS of default theme
-lt
list available themes
-s string
path to custom CSS file
-t string
theme to use for rendering (default "golang")
-v show program version
@matm This is what we have in dockerfile but still its failing from yesterday
FROM golang:1.16-alpine3.14 RUN go get github.com/axw/gocov/gocov RUN go get github.com/matm/gocov-html/cmd/gocov-html
Can you try my Dockerfile
above and assert if it works? If it does work, the problem is elsewhere.
Fetching the latest stable release v1.2.0
works too:
FROM golang:1.16-alpine3.14
RUN go get github.com/axw/gocov/gocov
RUN go install github.com/matm/gocov-html/cmd/gocov-html@v1.2.0
No error, gocov-html
works.
Not sure why its failing, will check internally
@matm What is the reason not to store generated code in git?
@obalunenko Actually, I was thinking about it today. Also this would prevent increasing the major version number and keeping the go install
working.
v1.3.1 just released and fixes this annoying issue. go install
works as usual now.
Thanks for your feedback guys.