Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac: generate Go code to render themes #38

Closed
3 tasks done
matm opened this issue Mar 7, 2023 · 23 comments
Closed
3 tasks done

refac: generate Go code to render themes #38

matm opened this issue Mar 7, 2023 · 23 comments
Assignees
Labels
refac Refactoring
Milestone

Comments

@matm
Copy link
Owner

matm commented Mar 7, 2023

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() and Beautifier.Data() for the golang (default) theme
  • Write a Go generator in pkg/themes/generator.go that will generate a default_gen.go file implementing those two methods with proper content taken from Assets()
  • Update the build system to go generate before building
@matm matm added the refac Refactoring label Mar 7, 2023
@matm matm added this to the 1.3 milestone Mar 7, 2023
@matm matm self-assigned this Mar 7, 2023
@matm matm changed the title Generate Go code to render themes refac: generate Go code to render themes Mar 7, 2023
@matm matm added the in progress Currently being worked on label Mar 7, 2023
matm added a commit that referenced this issue Mar 7, 2023
@matm matm closed this as completed in 2b78593 Mar 7, 2023
@matm matm removed the in progress Currently being worked on label Mar 7, 2023
@MdSahilGrab
Copy link

MdSahilGrab commented Mar 8, 2023

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() and Beautifier.Data() for the golang (default) theme
  • Write a Go generator in pkg/themes/generator.go that will generate a default_gen.go file implementing those two methods with proper content taken from Assets()
  • 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)

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

Hi @MdSahilGrab, the generator code has been moved to cmd/generator on master. How do you get this error? How do you build it?

@MdSahilGrab
Copy link

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.

@MdSahilGrab
Copy link

@matm so you want to us to use RUN go get github.com/matm/gocov-html/cmd/generator

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

Okay, can you try with the latest stable release instead? Something like

RUN go install github.com/matm/gocov-html/cmd/gocov-html@latest

@MdSahilGrab
Copy link

Yes we tried but this is also not working

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

@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

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

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

@MdSahilGrab
Copy link

Let me check

@MdSahilGrab
Copy link

@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

@MdSahilGrab
Copy link

Maybe this can help: https://github.com/matm/gocov-html/blob/master/build.mk#L73,
How exactly can i use this in dokerfile

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

Can you paste a working sample of your Dockerfile here? I need more context, thank you.

@MdSahilGrab
Copy link

@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

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

Which Go compiler version is used by this image?

@MdSahilGrab
Copy link

its golang:1.16-alpine3.14

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

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

@MdSahilGrab
Copy link

MdSahilGrab commented Mar 8, 2023

@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

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

Can you try my Dockerfile above and assert if it works? If it does work, the problem is elsewhere.

@matm
Copy link
Owner Author

matm commented Mar 8, 2023

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.

@MdSahilGrab
Copy link

MdSahilGrab commented Mar 8, 2023

Not sure why its failing, will check internally

@obalunenko
Copy link

@matm What is the reason not to store generated code in git?

@matm
Copy link
Owner Author

matm commented Mar 9, 2023

@obalunenko Actually, I was thinking about it today. Also this would prevent increasing the major version number and keeping the go install working.

@matm
Copy link
Owner Author

matm commented Mar 9, 2023

v1.3.1 just released and fixes this annoying issue. go install works as usual now.
Thanks for your feedback guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refac Refactoring
Projects
None yet
Development

No branches or pull requests

3 participants