Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 1759e7e

Browse files
authored
Use GitHub Actions and golangci-lint (#310)
* Use GitHub Actions and golangci-lint * Bump golang for Cloud Build
1 parent d772c30 commit 1759e7e

16 files changed

Lines changed: 165 additions & 130 deletions

.github/workflows/ci.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "CI"
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
staticcheck:
11+
name: "Staticcheck"
12+
runs-on: ubuntu-22.04
13+
steps:
14+
- name: Checkout Repository
15+
uses: actions/checkout@v3
16+
- name: Setup Golang Environment
17+
uses: actions/setup-go@v3
18+
with:
19+
go-version-file: go.mod
20+
cache: true
21+
- name: Run Staticcheck
22+
uses: dominikh/staticcheck-action@v1.2.0
23+
lint:
24+
name: "Lint"
25+
runs-on: ubuntu-22.04
26+
steps:
27+
- name: Checkout Repository
28+
uses: actions/checkout@v3
29+
- name: Setup Golang Environment
30+
uses: actions/setup-go@v3
31+
with:
32+
go-version-file: go.mod
33+
cache: true
34+
- name: Run Lint
35+
uses: golangci/golangci-lint-action@v3

.golangci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
linters-settings:
2+
misspell:
3+
locale: US
4+
revive:
5+
ignore-generated-header: true
6+
7+
linters:
8+
enable:
9+
- goimports
10+
- govet
11+
- gofmt
12+
- revive
13+
- misspell
14+
disable-all: true
15+
issues:
16+
max-issues-per-linter: 0
17+
max-same-issues: 0
18+
exclude-use-default: false
19+
run:
20+
timeout: 5m

Makefile

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@ ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
88
GOTEST_OPT?=-v -race -timeout 30s
99
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
1010
GOTEST=go test
11-
GOFMT=gofmt
12-
GOLINT=golint
13-
GOIMPORTS=goimports
14-
GOVET=go vet
1511
EMBEDMD=embedmd
1612
STATICCHECK=staticcheck
1713
# TODO decide if we need to change these names.
1814
README_FILES := $(shell find . -name '*README.md' | sort | tr '\n' ' ')
1915

20-
.DEFAULT_GOAL := defaul-goal
16+
.DEFAULT_GOAL := default-goal
2117

22-
.PHONY: defaul-goal
23-
defaul-goal: fmt lint vet embedmd goimports staticcheck test
18+
.PHONY: default-goal
19+
default-goal: lint embedmd staticcheck test
2420

2521
# TODO: enable test-with-cover when find out why "scripts/check-test-files.sh: 4: set: Illegal option -o pipefail"
2622
.PHONY: ci
27-
ci: fmt lint vet embedmd goimports staticcheck test test-386 test-with-coverage
23+
ci: embedmd test test-386 test-with-coverage
2824

2925
all-pkgs:
3026
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
@@ -56,40 +52,10 @@ test-with-cover:
5652
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
5753
go tool cover -html=coverage.txt -o coverage.html
5854

59-
.PHONY: fmt
60-
fmt:
61-
@FMTOUT=`$(GOFMT) -s -l $(ALL_SRC) 2>&1`; \
62-
if [ "$$FMTOUT" ]; then \
63-
echo "$(GOFMT) FAILED => gofmt the following files:\n"; \
64-
echo "$$FMTOUT\n"; \
65-
exit 1; \
66-
else \
67-
echo "Fmt finished successfully"; \
68-
fi
69-
7055
.PHONY: lint
7156
lint:
72-
@LINTOUT=`$(GOLINT) $(ALL_PKGS) 2>&1`; \
73-
if [ "$$LINTOUT" ]; then \
74-
echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \
75-
echo "$$LINTOUT\n"; \
76-
exit 1; \
77-
else \
78-
echo "Lint finished successfully"; \
79-
fi
57+
golangci-lint run
8058

81-
.PHONY: vet
82-
vet:
83-
# TODO: Understand why go vet downloads "github.com/google/go-cmp v0.2.0"
84-
@VETOUT=`$(GOVET) ./... | grep -v "go: downloading" 2>&1`; \
85-
if [ "$$VETOUT" ]; then \
86-
echo "$(GOVET) FAILED => go vet the following files:\n"; \
87-
echo "$$VETOUT\n"; \
88-
exit 1; \
89-
else \
90-
echo "Vet finished successfully"; \
91-
fi
92-
9359
.PHONY: embedmd
9460
embedmd:
9561
@EMBEDMDOUT=`$(EMBEDMD) -d $(README_FILES) 2>&1`; \
@@ -101,25 +67,12 @@ embedmd:
10167
echo "Embedmd finished successfully"; \
10268
fi
10369

104-
.PHONY: goimports
105-
goimports:
106-
@IMPORTSOUT=`$(GOIMPORTS) -d . 2>&1`; \
107-
if [ "$$IMPORTSOUT" ]; then \
108-
echo "$(GOIMPORTS) FAILED => fix the following goimports errors:\n"; \
109-
echo "$$IMPORTSOUT\n"; \
110-
exit 1; \
111-
else \
112-
echo "Goimports finished successfully"; \
113-
fi
114-
11570
.PHONY: staticcheck
11671
staticcheck:
11772
$(STATICCHECK) ./...
11873

11974
.PHONY: install-tools
12075
install-tools:
121-
GO111MODULE=on go install \
122-
golang.org/x/lint/golint \
123-
golang.org/x/tools/cmd/goimports \
124-
github.com/rakyll/embedmd \
125-
honnef.co/go/tools/cmd/staticcheck
76+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
77+
go install github.com/rakyll/embedmd@latest
78+
go install honnef.co/go/tools/cmd/staticcheck@2022.1.3

cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
steps:
2-
- name: golang:1.17
2+
- name: golang:1.19
33
args: ["make", "install-tools", "ci"]
44
logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs

example_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func Example_defaults() {
6363
}
6464

6565
func Example_gKE() {
66-
6766
// This example shows how to set up a Stackdriver exporter suitable for
6867
// monitoring a GKE container.
6968

go.mod

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,30 @@ module contrib.go.opencensus.io/exporter/stackdriver
33
go 1.17
44

55
require (
6-
cloud.google.com/go/compute v1.5.0
6+
cloud.google.com/go/compute v1.6.1
77
cloud.google.com/go/monitoring v1.1.0
88
cloud.google.com/go/trace v1.0.0
99
github.com/aws/aws-sdk-go v1.43.31
1010
github.com/census-instrumentation/opencensus-proto v0.3.0
1111
github.com/golang/protobuf v1.5.2
12-
github.com/google/go-cmp v0.5.7
12+
github.com/google/go-cmp v0.5.9
1313
github.com/jstemmer/go-junit-report v0.9.1
1414
github.com/prometheus/prometheus v0.35.0
15-
github.com/rakyll/embedmd v0.0.0-20171029212350-c8060a0752a2
1615
go.opencensus.io v0.23.0
17-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
18-
golang.org/x/net v0.0.0-20220325170049-de3da57026de
19-
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
20-
golang.org/x/tools v0.1.10
21-
google.golang.org/api v0.74.0
22-
google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb
23-
google.golang.org/grpc v1.45.0
16+
golang.org/x/net v0.1.0
17+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
18+
google.golang.org/api v0.81.0
19+
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd
20+
google.golang.org/grpc v1.46.2
2421
google.golang.org/protobuf v1.28.0
25-
honnef.co/go/tools v0.0.1-2020.1.4
2622
)
2723

2824
require (
29-
github.com/BurntSushi/toml v0.3.1 // indirect
3025
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
31-
github.com/googleapis/gax-go/v2 v2.2.0 // indirect
26+
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
3227
github.com/jmespath/go-jmespath v0.4.0 // indirect
33-
github.com/pmezard/go-difflib v1.0.0 // indirect
34-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
35-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
36-
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886 // indirect
37-
golang.org/x/text v0.3.7 // indirect
38-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
28+
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
29+
golang.org/x/sys v0.1.0 // indirect
30+
golang.org/x/text v0.4.0 // indirect
3931
google.golang.org/appengine v1.6.7 // indirect
4032
)

0 commit comments

Comments
 (0)