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

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

Merged
merged 4 commits into from
Jun 6, 2017

Conversation

strk
Copy link
Member

@strk strk commented Mar 22, 2017

... 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
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
Copy link
Member Author

strk commented Mar 22, 2017

@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
Copy link
Member

bkcsoft commented Mar 24, 2017

@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

Makefile Outdated
.PHONY: test
test:
test: fmt-check
Copy link
Member

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
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
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
Copy link
Member Author

strk commented Mar 24, 2017

@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
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
Copy link
Member Author

strk commented Mar 25, 2017

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

@strk
Copy link
Member Author

strk commented Mar 29, 2017

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
Copy link
Member Author

strk commented Mar 29, 2017

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
Member

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

@strk
Copy link
Member Author

strk commented Mar 29, 2017

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
Copy link
Member

sapk commented May 2, 2017

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
Copy link
Member Author

strk commented May 2, 2017 via email

@sapk sapk mentioned this pull request May 4, 2017
@appleboy
Copy link
Member

appleboy commented May 4, 2017

@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
Copy link
Member Author

strk commented May 4, 2017 via email

@appleboy
Copy link
Member

appleboy commented May 4, 2017

@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
Copy link
Member

appleboy commented Jun 3, 2017

@strk any updates?

@strk
Copy link
Member Author

strk commented Jun 6, 2017

@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
Copy link
Member Author

strk commented Jun 6, 2017

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
Copy link
Member

appleboy commented Jun 6, 2017

@strk We should ignore the bindata file. otherwise LGTM

@sapk
Copy link
Member

sapk commented Jun 6, 2017

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

@appleboy
Copy link
Member

appleboy commented Jun 6, 2017

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

@strk Can you fix some format error?

@strk
Copy link
Member Author

strk commented Jun 6, 2017

@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
Copy link
Member

appleboy commented Jun 6, 2017

@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
Copy link
Member Author

strk commented Jun 6, 2017

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

@appleboy
Copy link
Member

appleboy commented Jun 6, 2017

@strk You are right.

@strk
Copy link
Member Author

strk commented Jun 6, 2017

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
Copy link
Member

appleboy commented Jun 6, 2017

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

@strk
Copy link
Member Author

strk commented Jun 6, 2017

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
Copy link
Member

lunny commented Jun 6, 2017

@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
Copy link
Member

appleboy commented Jun 6, 2017

@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