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

add initial Makefile and CI config #11

Merged
merged 12 commits into from
Aug 31, 2022
Merged

Conversation

pkwarren
Copy link
Member

Add some initial files for building with a Makefile and GitHub Actions.
Format source code with go 1.19 (which rewrites comments).

Disable linter from failing the build initially. It would be good to
review the warnings and fix as needed or ignore lint warnings which
aren't critical.

Add some initial files for building with a Makefile and GitHub Actions.
Format source code with go 1.19 (which rewrites comments).

Disable linter from failing the build initially. It would be good to
review the warnings and fix as needed or ignore lint warnings which
aren't critical.
@pkwarren pkwarren requested a review from jhump August 29, 2022 20:39
@@ -0,0 +1,133 @@
# Contributor Covenant Code of Conduct
Copy link
Member Author

Choose a reason for hiding this comment

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

Copied from connect-go.

# For the same reason, only check generated code on the most recent
# supported version.
if: matrix.go-version == '1.19.x'
run: make checkgenerate && make lint
Copy link
Member Author

Choose a reason for hiding this comment

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

Runs lint on go 1.19 (since they format comments now too).

.github/workflows/windows.yaml Show resolved Hide resolved
@@ -0,0 +1,51 @@
run:
Copy link
Member Author

Choose a reason for hiding this comment

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

Config without exclusions from connect-go.

MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2020-2022
Copy link
Member Author

Choose a reason for hiding this comment

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

2020 is first commit to this repo's history.

Copy link
Member

Choose a reason for hiding this comment

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

Do we have to manually bump this every year? Maybe it could be an expression that can always carry through to current year? (I'm not really sure where it's used, so maybe it doesn't matter...)

Copy link
Member

Choose a reason for hiding this comment

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

OIC. This is to generate the pre-amble in every file, isn't it?

MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2020-2022
LICENSE_IGNORE := -e /testdata/ -e /testprotos/
Copy link
Member Author

Choose a reason for hiding this comment

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

Ignored testprotos dir but I think we should relocate this under testdata.

.PHONY: lint
lint: $(BIN)/golangci-lint ## Lint Go
$(GO) vet ./...
$(BIN)/golangci-lint run || : # Don't fail on lint errors initially
Copy link
Member Author

Choose a reason for hiding this comment

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

Turned off failing on lint errors so we can review the lint failures first and fix them one by one.

@@ -11,7 +25,7 @@ import (
"github.com/bufbuild/protocompile/reporter"
)

//go:generate goyacc -o proto.y.go -p proto proto.y
//go:generate goyacc -o proto.y.go -l -p proto proto.y
Copy link
Member Author

Choose a reason for hiding this comment

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

Added -l to inhibit line numbers from generated code to work around golangci/golangci-lint#1559.

@@ -31,7 +45,7 @@ func init() {
func setTokenName(token int, text string) {
// NB: this is based on logic in generated parse code that translates the
// int returned from the lexer into an internal token number.
var intern int
var intern int8
Copy link
Member Author

Choose a reason for hiding this comment

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

Latest generated code appears to use smallest possible type to represent values.

Copy link
Member

Choose a reason for hiding this comment

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

How is the version of goyacc pinned? It's not in go.mod since it's just a tool, not a dependency. I am used to pinning tool versions in the Makefile, like this. Will this just now use whatever version is already installed or always fetch latest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with a pattern I've seen in other projects and created internal/tools/go.mod to pull in Go tools and be able to keep things up to date with dependabot and use go build without hardcoded versions in Makefile. Let me know what you think.

Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

Nice! I think we might have some follow-on tasks, and clearly part of that is deciding how to address current lint failures.

ast/node.go Outdated Show resolved Hide resolved
@@ -22,7 +36,7 @@
// of multiple CPU cores, so a compilation involving thousands of files can be
// done very quickly by compiling things in parallel.
//
// Resolvers
// # Resolvers
Copy link
Member

Choose a reason for hiding this comment

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

Wha? This must be new in Go 1.19. This markdown-like syntax was never previously supported. The way to get a heading in Go docs before was to have a single line with no punctuation starting with a capital letter.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is nice:
https://tip.golang.org/doc/go1.19#go-doc

They finally added support for lists and links!

@@ -31,7 +45,7 @@ func init() {
func setTokenName(token int, text string) {
// NB: this is based on logic in generated parse code that translates the
// int returned from the lexer into an internal token number.
var intern int
var intern int8
Copy link
Member

Choose a reason for hiding this comment

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

How is the version of goyacc pinned? It's not in go.mod since it's just a tool, not a dependency. I am used to pinning tool versions in the Makefile, like this. Will this just now use whatever version is already installed or always fetch latest?

@pkwarren pkwarren requested a review from jhump August 30, 2022 17:00
Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

Nice!

ast/ast_roundtrip_test.go Outdated Show resolved Hide resolved
ast/visitor_test.go Outdated Show resolved Hide resolved
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/bufbuild/protocompile) # Custom section: groups all imports with the specified Prefix.
Copy link
Member

Choose a reason for hiding this comment

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

Cool! I am not familiar with gci, but this seems strictly better than goimports.

In the past, I've used goimports with -local github.com/bufbuild/protocompile to do this. But the standard behavior of goimports seems just wrong... So I actually have a fork that fixes the behavior (and is what is actually in use at FullStory for imports sorting/checking in CI).

@pkwarren pkwarren merged commit 02cf8f3 into main Aug 31, 2022
@pkwarren pkwarren deleted the pkw/TCN-293-initial-makefile-ci branch August 31, 2022 14:56
@bufbuild bufbuild deleted a comment from linear bot Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants