From ca8b6094bf298f0a61f14c70e25c024f3b122f03 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 1 May 2024 10:49:46 -0700 Subject: [PATCH 1/5] tools/golangci: enable var-naming linter rule Signed-off-by: Ivan Valdes --- tools/.golangci.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/.golangci.yaml b/tools/.golangci.yaml index f1e03a6d826..d176dfb82f7 100644 --- a/tools/.golangci.yaml +++ b/tools/.golangci.yaml @@ -87,9 +87,12 @@ linters-settings: # please keep this alphabetized - name: error-strings severity: error disabled: false - # TODO: enable the following rules - name: var-naming - disabled: true + disabled: false + arguments: + - [] + - ["GRPC", "WAL"] + # TODO: enable the following rules - name: exported disabled: true - name: unexported-return From 7a14c200cd67304583fde4c145c03540eb6cb257 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 1 May 2024 11:24:41 -0700 Subject: [PATCH 2/5] tools/testgrid-analysis: fix var-naming warnings Signed-off-by: Ivan Valdes --- tools/testgrid-analysis/cmd/data.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testgrid-analysis/cmd/data.go b/tools/testgrid-analysis/cmd/data.go index 899523aa275..1b18ca59361 100644 --- a/tools/testgrid-analysis/cmd/data.go +++ b/tools/testgrid-analysis/cmd/data.go @@ -110,9 +110,9 @@ func processRow(dashboard, tab string, row *apipb.ListRowsResponse_Row, allTests t.FailureLogs = logs t.FailureRate = float32(failed) / float32(total) if t.FailedRuns > 0 { - dashboardUrl := fmt.Sprintf("[%s](https://testgrid.k8s.io/%s#%s)", tab, dashboard, tab) + dashboardURL := fmt.Sprintf("[%s](https://testgrid.k8s.io/%s#%s)", tab, dashboard, tab) t.IssueBody = fmt.Sprintf("## %s Test: %s \nTest failed %.1f%% (%d/%d) of the time\n\nfailure logs are:\n| commit | started | log |\n| --- | --- | --- |\n%s\n", - dashboardUrl, t.FullName, t.FailureRate*100, t.FailedRuns, t.TotalRuns, strings.Join(t.FailureLogs, "\n")) + dashboardURL, t.FullName, t.FailureRate*100, t.FailedRuns, t.TotalRuns, strings.Join(t.FailureLogs, "\n")) t.IssueBody += "\nPlease follow the [instructions in the contributing guide](https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#check-for-flaky-tests) to reproduce the issue.\n" fmt.Printf("%s failed %.1f%% (%d/%d) of the time\n", t.FullName, t.FailureRate*100, t.FailedRuns, t.TotalRuns) } From 5a5650d1c363d4e04f7fc959bdbdf76080783bc9 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 1 May 2024 14:02:36 -0700 Subject: [PATCH 3/5] Revert "tools/testgrid-analysis: fix var-naming warnings" This reverts commit 7a14c200cd67304583fde4c145c03540eb6cb257. Signed-off-by: Ivan Valdes --- tools/testgrid-analysis/cmd/data.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testgrid-analysis/cmd/data.go b/tools/testgrid-analysis/cmd/data.go index 1b18ca59361..899523aa275 100644 --- a/tools/testgrid-analysis/cmd/data.go +++ b/tools/testgrid-analysis/cmd/data.go @@ -110,9 +110,9 @@ func processRow(dashboard, tab string, row *apipb.ListRowsResponse_Row, allTests t.FailureLogs = logs t.FailureRate = float32(failed) / float32(total) if t.FailedRuns > 0 { - dashboardURL := fmt.Sprintf("[%s](https://testgrid.k8s.io/%s#%s)", tab, dashboard, tab) + dashboardUrl := fmt.Sprintf("[%s](https://testgrid.k8s.io/%s#%s)", tab, dashboard, tab) t.IssueBody = fmt.Sprintf("## %s Test: %s \nTest failed %.1f%% (%d/%d) of the time\n\nfailure logs are:\n| commit | started | log |\n| --- | --- | --- |\n%s\n", - dashboardURL, t.FullName, t.FailureRate*100, t.FailedRuns, t.TotalRuns, strings.Join(t.FailureLogs, "\n")) + dashboardUrl, t.FullName, t.FailureRate*100, t.FailedRuns, t.TotalRuns, strings.Join(t.FailureLogs, "\n")) t.IssueBody += "\nPlease follow the [instructions in the contributing guide](https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#check-for-flaky-tests) to reproduce the issue.\n" fmt.Printf("%s failed %.1f%% (%d/%d) of the time\n", t.FullName, t.FailureRate*100, t.FailedRuns, t.TotalRuns) } From c01894fa2eb1c7bfc253be5071813f91de85002e Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 1 May 2024 15:22:45 -0700 Subject: [PATCH 4/5] use matrix to run golangci Signed-off-by: Ivan Valdes --- .github/workflows/static-analysis.yaml | 37 ++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 0611fd3e06f..8f40a9fa136 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -3,8 +3,21 @@ name: Static Analysis on: [push, pull_request] permissions: read-all jobs: - run: + module-dirs: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.list-modules.outputs.list }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - id: list-modules + run: | + echo ::set-output name=list::{\"modules\":[\"$(source ./scripts/test_lib.sh && module_dirs | sed 's/\s/","/g' )\"]} + golangci: + name: "Run golangci-lint on ${{ matrix.modules }}" runs-on: ubuntu-latest + needs: module-dirs + strategy: + matrix: ${{ fromJSON(needs.module-dirs.outputs.matrix) }} steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - id: goversion @@ -12,13 +25,27 @@ jobs: - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: go-version: ${{ steps.goversion.outputs.goversion }} - - id: golangci_lint_version - run: echo "golangci_lint_version=$(cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint)" >> "$GITHUB_OUTPUT" + - id: golangci-lint-version + run: echo "version=$(cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint)" >> "$GITHUB_OUTPUT" + - id: golangci-config + run: echo "config=$(git rev-parse --show-toplevel)/tools/.golangci.yaml" >> "$GITHUB_OUTPUT" - name: golangci-lint uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5.1.0 with: - version: ${{ steps.golangci_lint_version.outputs.golangci_lint_version }} - args: --config tools/.golangci.yaml + version: ${{ steps.golangci-lint-version.outputs.version }} + args: --config=${{ steps.golangci-config.outputs.config }} + working-directory: ${{ matrix.modules }} + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - id: goversion + run: echo "goversion=$(cat .go-version)" >> "$GITHUB_OUTPUT" + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version: ${{ steps.goversion.outputs.goversion }} + - run: | + go install github.com/golangci/golangci-lint/cmd/golangci-lint@"$(cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint)" - name: protoc uses: arduino/setup-protoc@149f6c87b92550901b26acd1632e11c3662e381f # v1.3.0 with: From fb69edf16a082c6bd8ee0e59af1d6fb3dd10e7bd Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 1 May 2024 20:48:54 -0700 Subject: [PATCH 5/5] use a flag Signed-off-by: Ivan Valdes --- .github/workflows/static-analysis.yaml | 34 +------------------------- scripts/test.sh | 4 ++- scripts/test_lib.sh | 2 +- 3 files changed, 5 insertions(+), 35 deletions(-) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 8f40a9fa136..4114c40d6d1 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -3,38 +3,6 @@ name: Static Analysis on: [push, pull_request] permissions: read-all jobs: - module-dirs: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.list-modules.outputs.list }} - steps: - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - - id: list-modules - run: | - echo ::set-output name=list::{\"modules\":[\"$(source ./scripts/test_lib.sh && module_dirs | sed 's/\s/","/g' )\"]} - golangci: - name: "Run golangci-lint on ${{ matrix.modules }}" - runs-on: ubuntu-latest - needs: module-dirs - strategy: - matrix: ${{ fromJSON(needs.module-dirs.outputs.matrix) }} - steps: - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - - id: goversion - run: echo "goversion=$(cat .go-version)" >> "$GITHUB_OUTPUT" - - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 - with: - go-version: ${{ steps.goversion.outputs.goversion }} - - id: golangci-lint-version - run: echo "version=$(cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint)" >> "$GITHUB_OUTPUT" - - id: golangci-config - run: echo "config=$(git rev-parse --show-toplevel)/tools/.golangci.yaml" >> "$GITHUB_OUTPUT" - - name: golangci-lint - uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5.1.0 - with: - version: ${{ steps.golangci-lint-version.outputs.version }} - args: --config=${{ steps.golangci-config.outputs.config }} - working-directory: ${{ matrix.modules }} run: runs-on: ubuntu-latest steps: @@ -61,7 +29,7 @@ jobs: - run: | set -euo pipefail - make verify + GOLANGCI_LINT_PASS_OPTIONS='--out-format=github-actions --path-prefix=$MODULE_DIR' make verify - run: | set -euo pipefail diff --git a/scripts/test.sh b/scripts/test.sh index 78c80ec0e83..086494db03a 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -411,7 +411,9 @@ function govet_shadow_pass { } function lint_pass { - run_for_modules generic_checker run golangci-lint run --config "${ETCD_ROOT_DIR}/tools/.golangci.yaml" + local opts + read -ra opts <<< "${GOLANGCI_LINT_PASS_OPTIONS:-}" + run_for_modules generic_checker run golangci-lint run --config "${ETCD_ROOT_DIR}/tools/.golangci.yaml" "${opts[@]}" } function lint_fix_pass { diff --git a/scripts/test_lib.sh b/scripts/test_lib.sh index b521a06ee58..074028d3e6c 100644 --- a/scripts/test_lib.sh +++ b/scripts/test_lib.sh @@ -161,7 +161,7 @@ function run_for_module { local module=${1:-"."} shift 1 ( - cd "${ETCD_ROOT_DIR}/${module}" && "$@" + cd "${ETCD_ROOT_DIR}/${module}" && "${@//\$MODULE_DIR/$module}" ) }