From a20fc29e5f5534b0878eb89944eaffa02c99c428 Mon Sep 17 00:00:00 2001 From: Patrick Paulino Date: Fri, 14 Jul 2023 10:45:35 -0700 Subject: [PATCH 1/6] ci: add job dependencies and logic gates Co-authored-by: Adriel Perkins --- .github/workflows/build.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac935ce1..0cd83137 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,9 @@ -name: Build, Test and Release +name: Lint, Build and Test on: - push: - branches: - - main + pull_request: + branches: [main] + workflow_call: jobs: golangci: @@ -43,6 +43,7 @@ jobs: # install-mode: "goinstall" make-build-checks: + needs: [golangci] runs-on: ubuntu-latest steps: @@ -63,7 +64,9 @@ jobs: - name: Run Checks run: make checks - go-semnatic-release: + go-semantic-release: + if: ${{ github.ref == 'refs/heads/main' }} + needs: [make-build-checks] runs-on: ubuntu-latest permissions: contents: write @@ -74,6 +77,8 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} goreleaser: + if: ${{ github.ref == 'refs/heads/main' }} + needs: [go-semantic-release] runs-on: ubuntu-latest permissions: contents: write From ac89b9d2e222bcb126d06d5e33aca8e54a3dcb27 Mon Sep 17 00:00:00 2001 From: Patrick Paulino Date: Fri, 14 Jul 2023 11:24:24 -0700 Subject: [PATCH 2/6] ci: add golangci to makefile and update github action to use Co-authored-by: Adriel Perkins --- .github/workflows/build.yml | 63 +++++++++++++++++++------------------ Makefile | 5 +++ Makefile.Common | 18 ++++++----- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cd83137..f0849859 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Lint, Build and Test +name: Lint, Build, Test and Release on: pull_request: @@ -19,31 +19,31 @@ jobs: with: go-version: ${{ matrix.go }} cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - # Require: The version of golangci-lint to use. - # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. - # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: v1.53 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # - # Note: by default the `.golangci.yml` file should be at the root of the repository. - # The location of the configuration file can be changed by using `--config=` - # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" - - make-build-checks: - needs: [golangci] + - name: Run golangci-lint + run: make golangci-lint-all + + make-checks: + runs-on: ubuntu-latest + steps: + + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + cache: false + + - name: Install Tools + run: make install-tools + + - name: Run Checks + run: make checks + + make-build: runs-on: ubuntu-latest steps: @@ -58,6 +58,9 @@ jobs: go-version: '1.19' cache: false + - name: Install Tools + run: make install-tools + - name: Build OpenTelemetry Collector run: make cibuild @@ -66,7 +69,7 @@ jobs: go-semantic-release: if: ${{ github.ref == 'refs/heads/main' }} - needs: [make-build-checks] + needs: [golangci, make-checks, make-build] runs-on: ubuntu-latest permissions: contents: write @@ -87,15 +90,15 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 - + - name: Fetch all tags run: git fetch --force --tags - + - name: Set up Go uses: actions/setup-go@v4 with: go-version: 1.19 - + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v4 with: diff --git a/Makefile b/Makefile index 9a2ff170..ca785c6d 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,11 @@ checks: $(PKG_RECEIVER_DIRS) $(PKG_RECEIVER_DIRS): $(MAKE) -C $@ lint + +.PHONY: golangci-lint-all +golangci-lint-all: + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3 + @$(MAKE) for-all CMD="make golangci-lint-all" # Taken from opentelemetry-collector-contrib .PHONY: for-all diff --git a/Makefile.Common b/Makefile.Common index e593681e..eeb9e30a 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -14,13 +14,17 @@ SRC_ROOT := $(shell git rev-parse --show-toplevel) .PHONY: lint lint: - @go fmt ./... - @go vet ./... - @staticcheck ./... - @gosec ./... - @goimports -w ./ + go fmt ./... + go vet ./... + staticcheck ./... + gosec ./... + goimports -w ./ + +.PHONY: golangci-lint +golangci-lint: + golangci-lint run .PHONY: tidy tidy: - @rm go.sum - @go mod tidy -compat=1.19 \ No newline at end of file + rm go.sum + go mod tidy -compat=1.19 \ No newline at end of file From ff7a16255a898968fd397f4983acb861c2d3fd2d Mon Sep 17 00:00:00 2001 From: Patrick Paulino Date: Fri, 14 Jul 2023 11:31:51 -0700 Subject: [PATCH 3/6] docs: fix typo in readme Co-authored-by: Adriel Perkins --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a38b076..38aa330a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ TODO: Add more details here, bit of a preamble... 1. `brew install go` 2. `brew install pre-commit` -3. `pre-commit install +3. `pre-commit install` 4. Create a PAT for GitHub with read access only 5. Run `export GH_USER=` and `export GH_PAT=` 6. Run `make run` From 934e2b2c9cd1783f1f60c064131737fde4ddfd01 Mon Sep 17 00:00:00 2001 From: Patrick Paulino Date: Fri, 14 Jul 2023 12:58:00 -0700 Subject: [PATCH 4/6] chore: change golangci install from curl to go install Co-authored-by: Adriel Perkins --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ca785c6d..59d22eb3 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ OTEL_CONTRIB_REPO = https://github.com/open-telemetry/opentelemetry-collector-co OS := $(shell uname | tr '[:upper:]' '[:lower:]') ARCH := $(shell uname -m) GORELEASER_VERSION = 1.19.2 +GOLANGCI_LINT_VERSION ?= v1.53.2 # Arguments for getting directories & executing commands against them PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name "go.mod" -print -exec dirname {} \; | sort | uniq) @@ -66,7 +67,7 @@ $(PKG_RECEIVER_DIRS): .PHONY: golangci-lint-all golangci-lint-all: - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) @$(MAKE) for-all CMD="make golangci-lint-all" # Taken from opentelemetry-collector-contrib From 43ba8af7b4c9c83c9126b5cbfe9131035aca2970 Mon Sep 17 00:00:00 2001 From: Patrick Paulino Date: Fri, 14 Jul 2023 13:45:18 -0700 Subject: [PATCH 5/6] ci: add golangci config and reworked make to suppor new static analysis changes Co-authored-by: Adriel Perkins --- .github/workflows/build.yml | 4 +++- .golangci.yaml | 48 +++++++++++++++++++++++++++++++++++++ Makefile | 16 ++++++------- Makefile.Common | 8 ------- 4 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0849859..bb8fe0a3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,8 +19,10 @@ jobs: with: go-version: ${{ matrix.go }} cache: false + - name: Install golangci-lint + run: make install-tools - name: Run golangci-lint - run: make golangci-lint-all + run: make lint-all make-checks: runs-on: ubuntu-latest diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..c6c28a6d --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,48 @@ +run: + timeout: 10m + allow-parallel-runners: true + +linters-settings: + errcheck: + check-type-assertions: false + check-blank: true + + gosimple: + go: "1.19" + + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + + unused: + go: "1.19" + + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 185 + # tab width in spaces. Default to 1. + tab-width: 8 + +linters: + disable-all: true + enable: + - gofmt + - errcheck + - goimports + - misspell + - noctx + - lll + - govet + - ineffassign + - typecheck + - unused + - gosimple + - staticcheck + - gosec + +issues: + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 diff --git a/Makefile b/Makefile index 59d22eb3..45feaf06 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ GORELEASER_VERSION = 1.19.2 GOLANGCI_LINT_VERSION ?= v1.53.2 # Arguments for getting directories & executing commands against them -PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name "go.mod" -print -exec dirname {} \; | sort | uniq) +# PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name "go.mod" -print -exec dirname {} \; | sort | uniq) +PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name '*go.mod*' | sed -r 's|/[^/]+$$||' |sort | uniq ) # set ARCH var based on output ifeq ($(ARCH),x86_64) @@ -58,24 +59,21 @@ install-tools: go install honnef.co/go/tools/cmd/staticcheck@latest go install github.com/securego/gosec/v2/cmd/gosec@latest go install golang.org/x/tools/cmd/goimports@latest + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) -.PHONY: checks $(PKG_RECEIVER_DIRS) -checks: $(PKG_RECEIVER_DIRS) +.PHONY: lint-all $(PKG_RECEIVER_DIRS) +lint-all: $(PKG_RECEIVER_DIRS) $(PKG_RECEIVER_DIRS): $(MAKE) -C $@ lint - -.PHONY: golangci-lint-all -golangci-lint-all: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) - @$(MAKE) for-all CMD="make golangci-lint-all" # Taken from opentelemetry-collector-contrib .PHONY: for-all for-all: @echo "running $${CMD} in root" @$${CMD} - @set -e; for dir in $(NONROOT_MODS); do \ + @set -e; for dir in $(PKG_RECEIVER_DIRS); do \ + @echo "running $${CMD} in $${dir}" (cd "$${dir}" && \ echo "running $${CMD} in $${dir}" && \ $${CMD} ); \ diff --git a/Makefile.Common b/Makefile.Common index eeb9e30a..85fdbd10 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -14,14 +14,6 @@ SRC_ROOT := $(shell git rev-parse --show-toplevel) .PHONY: lint lint: - go fmt ./... - go vet ./... - staticcheck ./... - gosec ./... - goimports -w ./ - -.PHONY: golangci-lint -golangci-lint: golangci-lint run .PHONY: tidy From 9eb6f508459f7a72cc3a1f1be489c1f5f52fbdfa Mon Sep 17 00:00:00 2001 From: Patrick Paulino Date: Fri, 14 Jul 2023 14:01:28 -0700 Subject: [PATCH 6/6] ci: refactor github workflow Co-authored-by: Adriel Perkins --- .github/workflows/build.yml | 51 +++++++++++-------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb8fe0a3..0f375f0f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,11 +6,11 @@ on: workflow_call: jobs: - golangci: + lint: strategy: matrix: go: ['1.19'] - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest] name: lint runs-on: ${{ matrix.os }} steps: @@ -19,36 +19,21 @@ jobs: with: go-version: ${{ matrix.go }} cache: false - - name: Install golangci-lint - run: make install-tools - - name: Run golangci-lint - run: make lint-all - - make-checks: - runs-on: ubuntu-latest - steps: - - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.19' - cache: false - - name: Install Tools - run: make install-tools + - name: Make install-tools + run: make install-tools - - name: Run Checks - run: make checks + - name: Make lint-all + run: make lint-all - make-build: - runs-on: ubuntu-latest + build: + strategy: + matrix: + go: ['1.19'] + os: [ubuntu-latest, macos-latest] + name: build + runs-on: ${{ matrix.os }} steps: - - name: Check out code uses: actions/checkout@v3 with: @@ -60,18 +45,12 @@ jobs: go-version: '1.19' cache: false - - name: Install Tools - run: make install-tools - - - name: Build OpenTelemetry Collector + - name: Make cibuild run: make cibuild - - name: Run Checks - run: make checks - go-semantic-release: if: ${{ github.ref == 'refs/heads/main' }} - needs: [golangci, make-checks, make-build] + needs: [lint, build] runs-on: ubuntu-latest permissions: contents: write