You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2026/04/05 15:06:58 UTC

(skywalking-eyes) branch main updated: ci: add golangci-lint GitHub Actions workflow (#269)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git


The following commit(s) were added to refs/heads/main by this push:
     new f8cba27  ci: add golangci-lint GitHub Actions workflow (#269)
f8cba27 is described below

commit f8cba27bff4208486f61b11da5541db25910381e
Author: Ivan Ka <53...@users.noreply.github.com>
AuthorDate: Sun Apr 5 16:06:52 2026 +0100

    ci: add golangci-lint GitHub Actions workflow (#269)
---
 .github/workflows/lint.yaml | 52 +++++++++++++++++++++++++++++++++++++++++++++
 Makefile                    |  4 +++-
 commands/header_check.go    |  3 ++-
 pkg/deps/golang_test.go     |  2 +-
 pkg/header/fix.go           |  2 +-
 pkg/review/header.go        |  2 +-
 6 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml
new file mode 100644
index 0000000..70d4475
--- /dev/null
+++ b/.github/workflows/lint.yaml
@@ -0,0 +1,52 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+name: Lint
+
+on:
+  pull_request:
+    branches: [ main ]
+
+jobs:
+  lint:
+    name: Go
+    runs-on: ubuntu-latest
+    permissions:
+      # Required: allow read access to the content for analysis.
+      contents: read
+    steps:
+
+      - name: Check out code into the Go module directory
+        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+
+      - name: Set up Go
+        uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
+        with:
+          go-version-file: go.mod
+
+      - name: Go formatting
+        run: |
+          if [ -z "$(gofmt -l .)" ]; then
+            echo -e "All '*.go' files are properly formatted."
+          else
+            echo -e "Please run 'gofmt -w .' to fix. Some files need formatting:"
+            gofmt -d -l .
+            exit 1
+          fi
+
+      - name: Verify linter configuration and Lint go code
+        run: make lint
diff --git a/Makefile b/Makefile
index 7091532..9f1e2d0 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@ GO := GO111MODULE=on go
 GO_PATH = $(shell $(GO) env GOPATH)
 GO_BUILD = $(GO) build
 GO_TEST = $(GO) test
+GOLANGCI_LINT_VERSION = v2.6.1
 GO_LINT = $(GO_PATH)/bin/golangci-lint
 GO_BUILD_LDFLAGS = -X github.com/apache/skywalking-eyes/commands.version=$(VERSION)
 GOOS ?= $(shell $(GO) env GOOS)
@@ -44,10 +45,11 @@ RELEASE_SRC = skywalking-$(PROJECT)-$(VERSION)-src
 all: clean lint license test build
 
 $(GO_LINT):
-	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin v2.6.1
+	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin $(GOLANGCI_LINT_VERSION)
 
 .PHONY: lint
 lint: $(GO_LINT)
+	$(GO_LINT) config verify
 	$(GO_LINT) run -v ./...
 
 .PHONY: fix-lint
diff --git a/commands/header_check.go b/commands/header_check.go
index 72bd758..22e3e20 100644
--- a/commands/header_check.go
+++ b/commands/header_check.go
@@ -67,7 +67,8 @@ var CheckCommand = &cobra.Command{
 
 func writeSummaryQuietly(result *header.Result) {
 	if summaryFileName := os.Getenv("GITHUB_STEP_SUMMARY"); summaryFileName != "" {
-		if summaryFile, err := os.OpenFile(summaryFileName, os.O_WRONLY|os.O_APPEND, 0o644); err == nil {
+		summaryFile, err := os.OpenFile(summaryFileName, os.O_WRONLY|os.O_APPEND, 0o644) //nolint:gosec // path from GITHUB_STEP_SUMMARY env var
+		if err == nil {
 			defer summaryFile.Close()
 			_, _ = summaryFile.WriteString("# License Eye Summary\n")
 			_, _ = summaryFile.WriteString(result.String())
diff --git a/pkg/deps/golang_test.go b/pkg/deps/golang_test.go
index 6d878b6..fd4eaa9 100644
--- a/pkg/deps/golang_test.go
+++ b/pkg/deps/golang_test.go
@@ -137,7 +137,7 @@ func TestResolvePackageLicense(t *testing.T) {
 func writeTempFile(t *testing.T, dir, name, content string) string {
 	t.Helper()
 	path := filepath.Join(dir, name)
-	if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
+	if err := os.WriteFile(path, []byte(content), 0o600); err != nil { //nolint:gosec // path is under t.TempDir()
 		t.Fatalf("failed to write %v: %v", name, err)
 	}
 	return path
diff --git a/pkg/header/fix.go b/pkg/header/fix.go
index 232aa7e..18cf067 100644
--- a/pkg/header/fix.go
+++ b/pkg/header/fix.go
@@ -63,7 +63,7 @@ func InsertComment(file string, style *comments.CommentStyle, config *ConfigHead
 
 	content = rewriteContent(style, content, licenseHeader, config.LicensePattern(style))
 
-	if err := os.WriteFile(file, content, stat.Mode()); err != nil {
+	if err := os.WriteFile(file, content, stat.Mode()); err != nil { //nolint:gosec // path from tool's own file scanner
 		return err
 	}
 
diff --git a/pkg/review/header.go b/pkg/review/header.go
index f4a9594..bbc2194 100644
--- a/pkg/review/header.go
+++ b/pkg/review/header.go
@@ -299,7 +299,7 @@ func GetSha() (string, error) {
 	if filepath == "" {
 		return "", fmt.Errorf("failed to get event path")
 	}
-	content, err := os.ReadFile(filepath)
+	content, err := os.ReadFile(filepath) //nolint:gosec // intentional: reading from a path from GITHUB_EVENT_PATH env var
 	if err != nil {
 		return "", err
 	}