Skip to content

Include formatting check to the make test (and thus also check) rule - #1366

Merged
appleboy merged 4 commits into
go-gitea:masterfrom
strk:fmt-check
Jun 6, 2017
Merged

Include formatting check to the make test (and thus also check) rule#1366
appleboy merged 4 commits into
go-gitea:masterfrom
strk:fmt-check

Conversation

@strk

@strk strk commented Mar 22, 2017

Copy link
Copy Markdown
Member

... and give it its own standalone target too (make fmt-check)

\cc @lunny, @tboerger, @bkcsoft

@lunny lunny added this to the 1.2.0 milestone Mar 22, 2017
@lunny lunny added topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile type/docs This PR mainly updates/creates documentation labels Mar 22, 2017
@appleboy

Copy link
Copy Markdown
Member
fmt:
- 	find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
+ 	find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -d -s -w

display diffs on drone logs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 22, 2017
@strk

strk commented Mar 22, 2017

Copy link
Copy Markdown
Member Author

@appleboy I don't understand your comment. This PR is about making drone fail unless the PR code was threated by running make fmt

@bkcsoft

bkcsoft commented Mar 24, 2017

Copy link
Copy Markdown
Contributor

@appleboy the way I read the docs for gofmt -d and -w would be mutually exclusive. So that wouldn't work either :) and make fmt is there so contributors can easily fix formating :)

-d display diffs instead of rewriting files
-w write result to (source) file instead of stdout

Comment thread Makefile Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This make it part of make test, not make check as the title says. Change one of them 🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified the title (check is an alias for test)

@appleboy

Copy link
Copy Markdown
Member

@strk I mean that the -d flag show all diff data in logs so the developer can look at it.

@strk strk changed the title Include formatting check to the make check rule Include formatting check to the make test (and thus also check) rule Mar 24, 2017
@strk

strk commented Mar 24, 2017

Copy link
Copy Markdown
Member Author

@appleboy gofmt -d seems indeed useful, but doesn't tell in the exit code if there was or not a diff.
With b2e1367 I removed the --quiet argument to diff so you do get to see the changes, and also I've added messages to give hint about how to fix the problem

@appleboy

Copy link
Copy Markdown
Member

@strk Good work. It is working for me https://github.com/go-training/training/tree/master/example01

LGTM

Don't forget to run make fmt to fix build errors.

screen shot 2017-03-25 at 11 21 42 am

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 25, 2017
@strk

strk commented Mar 25, 2017

Copy link
Copy Markdown
Member Author

@bkcsoft please lift your barrier and let this flow ! :)

@strk

strk commented Mar 29, 2017

Copy link
Copy Markdown
Member Author

I've just installed Go 1.8 and gofmt from that version also doesn't change any file in this branch. So it looks like 1.7 was bogus or something like that, what do you think @tboerger ?

@strk

strk commented Mar 29, 2017

Copy link
Copy Markdown
Member Author

Actually I just tried the make fmt rule with go version go1.7 linux/amd64 and it also didn't change a thing in this branch, so it looks like the difference is elsewhere.

@tboerger

Copy link
Copy Markdown
Member

I don't like such complicated make tasks without a bigger benefit.

@strk

strk commented Mar 29, 2017

Copy link
Copy Markdown
Member Author

I don't like the complexity either, so if we cannot ensure any Go version would format the code in the same way, let's forget about it (and beware of the "make fmt" rule too as it might be doing and undoing the same thing)

@sapk

sapk commented May 2, 2017

Copy link
Copy Markdown
Member

Any news on that ?
For the difference of format depending of go version, I think we just need to choose one (the simplest should be to choose the one of the drone instance)

@strk

strk commented May 2, 2017 via email

Copy link
Copy Markdown
Member Author

@sapk sapk mentioned this pull request May 4, 2017
@appleboy

appleboy commented May 4, 2017

Copy link
Copy Markdown
Member

@strk How about the following check script so we can run fmt check with unstaged changes.

GOFILES := find . -name "*.go" -type f -not -path "./vendor/*"
GOFMT ?= gofmt "-s"

.PHONY: fmt-check
fmt-check:
	# get all go files and run go fmt on them
	@files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \
		echo "Please run 'make fmt' and commit the result:"; \
		echo "$${files}"; \
		exit 1; \
		fi;

@strk

strk commented May 4, 2017 via email

Copy link
Copy Markdown
Member Author

@appleboy

appleboy commented May 4, 2017

Copy link
Copy Markdown
Member

@strk I updated the previous comment and add missing variables on Makefile.

I can confirm that gofmt -l is working on your scenario with Drone.

@lunny lunny modified the milestones: 1.3.0, 1.2.0 May 25, 2017
@appleboy

appleboy commented Jun 3, 2017

Copy link
Copy Markdown
Member

@strk any updates?

@strk

strk commented Jun 6, 2017

Copy link
Copy Markdown
Member Author

@appleboy I gave up due to the differences in formatting choices on different machines (mine, and drone's). Do you want to try from your side ? It'd be a pain to be unable to fix a problem reported by Drone because the developers make fmt would produce a different output. I think this is what makes this PR unmergeable...

@strk

strk commented Jun 6, 2017

Copy link
Copy Markdown
Member Author

Anyway, rebased for a final review. Running make fmt on my machine results in on changes, and make fmt-check passes here. Let's see if Drone made his mind...

@appleboy

appleboy commented Jun 6, 2017

Copy link
Copy Markdown
Member

@strk We should ignore the bindata file. otherwise LGTM

@sapk

sapk commented Jun 6, 2017

Copy link
Copy Markdown
Member

LGTM let merge this if CI don't complain ^^

@appleboy

appleboy commented Jun 6, 2017

Copy link
Copy Markdown
Member

https://drone.gitea.io/go-gitea/gitea/3383

@strk Can you fix some format error?

@strk

strk commented Jun 6, 2017

Copy link
Copy Markdown
Member Author

@appleboy as I wrote before, make fmt on my machine results in no change. This is with go version go1.7.4 linux/amd64 -- Sorry, but gofmt is failing here :/

@appleboy

appleboy commented Jun 6, 2017

Copy link
Copy Markdown
Member

@strk Please rebase the latest code. I just merged #1881 so the CI trigger error.

Try to rebase the latest code and execute make fmt to fix go format error.

strk added 3 commits June 6, 2017 11:32
... and give it its own standalone target too (make fmt-check)

Show diff on fmt-check failure
Do not allow running "fmt-check" with incompatible go version
Also simplify the `fmt` rule
also remove duplicated variable assignment for GOFILES
@strk

strk commented Jun 6, 2017

Copy link
Copy Markdown
Member Author

Ok with the rebase I do have format changed on make fmt, should I commit them too ?

@appleboy

appleboy commented Jun 6, 2017

Copy link
Copy Markdown
Member

@strk You are right.

@strk

strk commented Jun 6, 2017

Copy link
Copy Markdown
Member Author

So now Drone was happy before my make fmt invocation, this means it'll be probably unhappy now. Contending styles. This is a no-go.

@appleboy

appleboy commented Jun 6, 2017

Copy link
Copy Markdown
Member

@strk So let's merge this PR or any concern?

@strk

strk commented Jun 6, 2017

Copy link
Copy Markdown
Member Author

Uhm, as it's still happy (and I am too on my side) - let's merge this.
Even if I don't understand how it works ... we'll eventually file a ticket if things go wrong.

@lunny

lunny commented Jun 6, 2017

Copy link
Copy Markdown
Member

@appleboy @strk I think move this to v1.2 and merge it is a good idea.

@appleboy appleboy modified the milestones: 1.2.0, 1.3.0 Jun 6, 2017
@appleboy

appleboy commented Jun 6, 2017

Copy link
Copy Markdown
Member

@lunny Done. move to 1.2.0

@appleboy
appleboy merged commit f6b5896 into go-gitea:master Jun 6, 2017
@strk
strk deleted the fmt-check branch June 13, 2017 20:54
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile type/docs This PR mainly updates/creates documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants