Skip to content

Commit

Permalink
Fix golangci targets on macOS
Browse files Browse the repository at this point in the history
Ever since goccy/go-graphviz was added as a dependency, running "make
golangci" (and related targets) has been broken on macOS. This is
because goccy/go-graphviz requires cgo to be enabled and go disables it
when cross-compiling (we set GOOS to linux in "make golangci" to ensure
that files with a linux build tag are verified by the linters).

We now run "make golangci" from a macOS worker in CI to avoid breaking
this again in the future.

In the future, we should also ensure that the linters are run on
Windows-specific files.

This commit also adds a few "missing" doc.go files.
  • Loading branch information
antoninbas committed Jul 30, 2020
1 parent be28dd1 commit f034685
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ jobs:

golangci-lint:
name: Golangci-lint
runs-on: [ubuntu-18.04]
strategy:
matrix:
platform: [ubuntu-18.04, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,23 @@ fmt:
@echo "===> Installing Golangci-lint <==="
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.21.0

# Setting CGO_ENABLED=1 to run golangci-lint is required on macOS to avoid the following error:
# build github.com/goccy/go-graphviz/internal/ccall: cannot load github.com/goccy/go-graphviz/internal/ccall: no Go source files
# By default go never enables cgo when cross-compiling, but it is required by
# go-graphviz. golangci-lint invokes "go list" to list source directories, which in turn tries to
# build.

.PHONY: golangci
golangci: .golangci-bin
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci.yml
@GOOS=linux CGO_ENABLED=1 .golangci-bin/golangci-lint run -c .golangci.yml

.PHONY: golangci-fix
golangci-fix: .golangci-bin
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci.yml --fix
@GOOS=linux CGO_ENABLED=1 .golangci-bin/golangci-lint run -c .golangci.yml --fix

.PHONY: lint
lint: .golangci-bin
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci-golint.yml
@GOOS=linux CGO_ENABLED=1 .golangci-bin/golangci-lint run -c .golangci-golint.yml

.PHONY: clean
clean:
Expand Down
16 changes: 16 additions & 0 deletions pkg/agent/util/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package util contains utility functions which are used in the agent implementation.
package util
16 changes: 16 additions & 0 deletions pkg/agent/util/sysctl/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package systcl contains utility functions to read and write sysctl configuration on Linux.
package sysctl
16 changes: 16 additions & 0 deletions pkg/agent/util/winfirewall/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package winfirewall contains utility functions to configure the Windows firewall.
package winfirewall
2 changes: 1 addition & 1 deletion pkg/ovs/ovsctl/ovsctl_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux darwin
// +build !windows

// Copyright 2020 Antrea Authors
//
Expand Down

0 comments on commit f034685

Please sign in to comment.