diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 1b245264..f2c0ac5f 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -33,10 +33,10 @@ concurrency: jobs: check-license: name: License header - if: (github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || (github.event_name != 'schedule') + if: github.repository == 'apache/skywalking-cli' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Check License Header uses: apache/skywalking-eyes@5dfa68f93380a5e57259faaf95088b7f133b5778 @@ -44,76 +44,31 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Setup Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: "1.18" + go-version: "1.24" - name: Check Dependencies License run: make dependency-license - - changes: - runs-on: ubuntu-latest - if: github.event_name != 'schedule' - timeout-minutes: 10 - outputs: - cli: ${{ steps.filter-cli.outputs.any_modified }} - steps: - - uses: actions/checkout@v3 # required for push event - with: - fetch-depth: 0 - - name: Check for CLI source changes - id: filter-cli - # The GHA version is pinned by infra - uses: tj-actions/changed-files@v43.0.0 - with: - files_from_source_file: .github/file-filters.txt - - name: List all modified files - if: steps.filter-cli.outputs.any_modified == 'true' - run: | - echo "Files that have changed or modified:" - echo "Filter-cli: ${{ steps.filter-cli.outputs.all_changed_and_modified_files }}" - - - golang-lint: - name: Golang Lint - runs-on: ubuntu-latest - needs: [changes] - if: | - ( always() && ! cancelled() ) && - ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true') - steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.18 - - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: v1.50.0 - args: --timeout 5m - - build: name: Build - needs: [changes] runs-on: ubuntu-latest - if: | - ( always() && ! cancelled() ) && - ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true') + if: github.repository == 'apache/skywalking-cli' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.24 - name: Check code generation run: make check-codegen - - uses: actions/upload-artifact@v3 + - name: Lint + run: make lint + + - uses: actions/upload-artifact@v4 if: failure() with: name: check-diff @@ -129,20 +84,20 @@ jobs: command-tests: name: Command Tests runs-on: ubuntu-latest - needs: [changes] - if: | - ( always() && ! cancelled() ) && - ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true') + if: github.repository == 'apache/skywalking-cli' strategy: matrix: oap: - a65a6e0ff2ef9c716131b36172399076307c35f1 # Feb 27th, 2024 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.24 + + - name: Install swctl + run: make install DESTDIR=/usr/local/bin - name: Test commands uses: apache/skywalking-infra-e2e@cf589b4a0b9f8e6f436f78e9cfd94a1ee5494180 @@ -155,16 +110,13 @@ jobs: unit-tests: name: Unit Tests runs-on: ubuntu-latest - needs: [changes] - if: | - ( always() && ! cancelled() ) && - ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true') + if: github.repository == 'apache/skywalking-cli' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: setup go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: '1.18' + go-version: '1.24' - name: run unit tests and report coverage working-directory: ./ @@ -176,7 +128,6 @@ jobs: name: Required needs: - check-license - - golang-lint - build - command-tests - unit-tests @@ -185,15 +136,12 @@ jobs: steps: - name: Merge Requirement run: | - execute=${{ needs.changes.outputs.cli }} checkLicense=${{ needs.check-license.result }} - [[ ${checkLicense} == 'success' ]] || exit -1; - golangLint=${{ needs.golang-lint.result }}; + [[ ${checkLicense} == 'success' ]] || exit 1; build=${{ needs.build.result }}; commandTests=${{ needs.command-tests.result }}; unitTests=${{ needs.unit-tests.result }}; - [[ ${golangLint} == 'success' ]] || [[ ${execute} != 'true' && ${golangLint} == 'skipped' ]] || exit -2; - [[ ${build} == 'success' ]] || [[ ${execute} != 'true' && ${build} == 'skipped' ]] || exit -3; - [[ ${commandTests} == 'success' ]] || [[ ${execute} != 'true' && ${commandTests} == 'skipped' ]] || exit -4; - [[ ${unitTests} == 'success' ]] || [[ ${execute} != 'true' && ${unitTests} == 'skipped' ]] || exit -5; - exit 0; \ No newline at end of file + [[ ${build} == 'success' ]] || [[ ${build} == 'skipped' ]] || exit 3; + [[ ${commandTests} == 'success' ]] || [[ ${commandTests} == 'skipped' ]] || exit 4; + [[ ${unitTests} == 'success' ]] || [[ ${unitTests} == 'skipped' ]] || exit 5; + exit 0; diff --git a/.github/workflows/publish-docker.yaml b/.github/workflows/publish-docker.yaml index 1ebca1cf..dbc761bc 100644 --- a/.github/workflows/publish-docker.yaml +++ b/.github/workflows/publish-docker.yaml @@ -43,7 +43,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.18 + go-version: 1.24 - name: Log in to the Container registry uses: docker/login-action@v1.10.0 with: @@ -51,4 +51,4 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push docker images - run: make docker.push || make docker.push \ No newline at end of file + run: make docker.push || make docker.push diff --git a/.golangci.yml b/.golangci.yml index c9af1f94..82a287ff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,25 +16,15 @@ linters-settings: govet: - check-shadowing: true - golint: - min-confidence: 0 + enable: + - shadow gocyclo: min-complexity: 15 - maligned: - suggest-new: true dupl: threshold: 200 goconst: min-len: 2 min-occurrences: 2 - depguard: - list-type: blacklist - packages: - - - include-go-root: true - packages-with-error-messages: - fmt: "logging is allowed only by logutils.Log" misspell: locale: US lll: @@ -60,7 +50,6 @@ linters-settings: linters: enable: - bodyclose - - depguard - dogsled - dupl - errcheck diff --git a/Dockerfile b/Dockerfile index cd9a8bc2..2bd22135 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.18 AS builder +FROM golang:1.24 AS builder ARG VERSION diff --git a/Makefile b/Makefile index bd3b9b6c..0cbf198e 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ deps: @$(GO_GET) -v -t -d ./... $(GO_LINT): - @$(GO_LINT) version > /dev/null 2>&1 || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin v1.50.0 + @$(GO_LINT) version > /dev/null 2>&1 || go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.0 $(LICENSE_EYE): @$(LICENSE_EYE) --version > /dev/null 2>&1 || go install github.com/apache/skywalking-eyes/cmd/license-eye@d38fe05 diff --git a/go.mod b/go.mod index af7daee4..caff7d79 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/apache/skywalking-cli -go 1.18 +go 1.24 require ( github.com/apache/skywalking-swck/operator v0.0.0-20220815142653-ed08076b7433 diff --git a/internal/commands/completion/bash.go b/internal/commands/completion/bash.go index 78ec3450..f8e44d8d 100644 --- a/internal/commands/completion/bash.go +++ b/internal/commands/completion/bash.go @@ -28,7 +28,7 @@ var bashCommand = &cli.Command{ Aliases: []string{"b"}, Usage: "Output shell completion code for bash", ArgsUsage: "[parameters...]", - Action: func(ctx *cli.Context) error { + Action: func(_ *cli.Context) error { fmt.Print(bashScript) return nil }, diff --git a/internal/commands/completion/fish.go b/internal/commands/completion/fish.go index 53f170b7..aafd7ab8 100644 --- a/internal/commands/completion/fish.go +++ b/internal/commands/completion/fish.go @@ -28,7 +28,7 @@ var fishCommand = &cli.Command{ Aliases: []string{"f"}, Usage: "Output shell completion code for fish", ArgsUsage: "[parameters...]", - Action: func(ctx *cli.Context) error { + Action: func(_ *cli.Context) error { fmt.Print(fishScript) return nil }, diff --git a/internal/commands/completion/powershell.go b/internal/commands/completion/powershell.go index 34234b7c..5aca22c8 100644 --- a/internal/commands/completion/powershell.go +++ b/internal/commands/completion/powershell.go @@ -28,7 +28,7 @@ var powershellCommand = &cli.Command{ Aliases: []string{"p"}, Usage: "Output shell completion code for powershell", ArgsUsage: "[parameters...]", - Action: func(ctx *cli.Context) error { + Action: func(_ *cli.Context) error { fmt.Print(powershellScript) return nil }, diff --git a/internal/commands/completion/zsh.go b/internal/commands/completion/zsh.go index e8505c9f..9d586efd 100644 --- a/internal/commands/completion/zsh.go +++ b/internal/commands/completion/zsh.go @@ -28,7 +28,7 @@ var zshCommand = &cli.Command{ Aliases: []string{"z"}, Usage: "Output shell completion code for zsh", ArgsUsage: "[parameters...]", - Action: func(ctx *cli.Context) error { + Action: func(_ *cli.Context) error { fmt.Print(zshScript) return nil }, diff --git a/internal/commands/interceptor/duration.go b/internal/commands/interceptor/duration.go index 20c1ac5b..5d93c897 100644 --- a/internal/commands/interceptor/duration.go +++ b/internal/commands/interceptor/duration.go @@ -106,7 +106,7 @@ func ParseDuration(start, end string, userStep api.Step) (startTime, endTime tim var err error // both are present - if len(start) > 0 && len(end) > 0 { + if start != "" && end != "" { if userStep, startTime, err = TryParseTime(start, userStep); err != nil { logger.Log.Fatalln("Unsupported time format:", start, err) } @@ -120,12 +120,12 @@ func ParseDuration(start, end string, userStep api.Step) (startTime, endTime tim logger.Log.Fatalln("Unsupported time format:", start, err) } return startTime, startTime.Add(30 * utils.StepDuration[step]), step, utils.EndAbsent - } else { // start is absent - if step, endTime, err = TryParseTime(end, userStep); err != nil { - logger.Log.Fatalln("Unsupported time format:", end, err) - } - return endTime.Add(-30 * utils.StepDuration[step]), endTime, step, utils.StartAbsent } + // start is absent + if step, endTime, err = TryParseTime(end, userStep); err != nil { + logger.Log.Fatalln("Unsupported time format:", end, err) + } + return endTime.Add(-30 * utils.StepDuration[step]), endTime, step, utils.StartAbsent } // AlignPrecision aligns the two time strings to same precision diff --git a/internal/commands/profiling/asyncprofiler/create.go b/internal/commands/profiling/asyncprofiler/create.go index 1d21938c..5df43279 100644 --- a/internal/commands/profiling/asyncprofiler/create.go +++ b/internal/commands/profiling/asyncprofiler/create.go @@ -69,7 +69,7 @@ $ swctl profiling async create --service-name=service-name --duration=60 --event ), Action: func(ctx *cli.Context) error { serviceID := ctx.String("service-id") - instanceIds := strings.Split(ctx.String("instance-id-list"), ",") + instanceIDs := strings.Split(ctx.String("instance-id-list"), ",") duration := ctx.Int("duration") eventTypes := ctx.Generic("events").(*asyncprofiler.ProfilerEventTypeEnumValue).Selected @@ -80,7 +80,7 @@ $ swctl profiling async create --service-name=service-name --duration=60 --event request := &query.AsyncProfilerTaskCreationRequest{ ServiceID: serviceID, - ServiceInstanceIds: instanceIds, + ServiceInstanceIds: instanceIDs, Duration: duration, Events: eventTypes, ExecArgs: execArgs, diff --git a/pkg/heatmap/axes/axes.go b/pkg/heatmap/axes/axes.go index 5354f7c3..f8e82968 100644 --- a/pkg/heatmap/axes/axes.go +++ b/pkg/heatmap/axes/axes.go @@ -44,8 +44,8 @@ type YDetails struct { // RequiredWidth calculates the minimum width required // in order to draw the Y axis and its labels. -func RequiredWidth(max string) int { - return runewidth.StringWidth(max) + AxisWidth +func RequiredWidth(mx string) int { + return runewidth.StringWidth(mx) + AxisWidth } // NewYDetails retrieves details about the Y axis required @@ -100,7 +100,7 @@ type XDetails struct { // plotted. // customLabels are the desired labels for the X axis, these are preferred if // provided. -func NewXDetails(cvsAr image.Rectangle, yEnd image.Point, stringLabels []string, cellWidth int) (*XDetails, error) { +func NewXDetails(_ image.Rectangle, yEnd image.Point, stringLabels []string, cellWidth int) (*XDetails, error) { // The space between the start of the axis and the end of the canvas. // graphWidth := cvsAr.Dx() - yEnd.X - 1 graphWidth := len(stringLabels) * cellWidth diff --git a/pkg/heatmap/axes/label.go b/pkg/heatmap/axes/label.go index e797dae9..0abe33a0 100644 --- a/pkg/heatmap/axes/label.go +++ b/pkg/heatmap/axes/label.go @@ -43,11 +43,11 @@ type Label struct { // Labels are returned with Y coordinates in ascending order. // Y coordinates grow down. func yLabels(graphHeight, labelWidth int, stringLabels []string) ([]*Label, error) { - if min := 2; graphHeight < min { - return nil, fmt.Errorf("cannot place labels on a canvas with height %d, minimum is %d", graphHeight, min) + if mn := 2; graphHeight < mn { + return nil, fmt.Errorf("cannot place labels on a canvas with height %d, minimum is %d", graphHeight, mn) } - if min := 0; labelWidth < min { - return nil, fmt.Errorf("cannot place labels in label area width %d, minimum is %d", labelWidth, min) + if mn := 0; labelWidth < mn { + return nil, fmt.Errorf("cannot place labels in label area width %d, minimum is %d", labelWidth, mn) } var labels []*Label diff --git a/pkg/heatmap/heatmap.go b/pkg/heatmap/heatmap.go index 5c877308..74c9ff0e 100644 --- a/pkg/heatmap/heatmap.go +++ b/pkg/heatmap/heatmap.go @@ -51,12 +51,12 @@ func newColumnValues(values []int64) *columnValues { v := make([]int64, len(values)) copy(v, values) - min, max := minMax(values) + mn, mx := minMax(values) return &columnValues{ values: v, - Min: min, - Max: max, + Min: mn, + Max: mx, } } @@ -159,7 +159,7 @@ func (hp *HeatMap) axesDetails(cvs *canvas.Canvas) (*axes.XDetails, *axes.YDetai // Draw draws the values as HeatMap. // Implements widgetapi.Widget.Draw. -func (hp *HeatMap) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error { +func (hp *HeatMap) Draw(cvs *canvas.Canvas, _ *widgetapi.Meta) error { hp.mu.Lock() defer hp.mu.Unlock() @@ -250,12 +250,12 @@ func (hp *HeatMap) minSize() image.Point { } // Keyboard input isn't supported on the SparkLine widget. -func (*HeatMap) Keyboard(k *terminalapi.Keyboard) error { +func (*HeatMap) Keyboard(_ *terminalapi.Keyboard) error { return errors.New("the HeatMap widget doesn't support keyboard events") } // Mouse input isn't supported on the SparkLine widget. -func (*HeatMap) Mouse(m *terminalapi.Mouse) error { +func (*HeatMap) Mouse(_ *terminalapi.Mouse) error { return errors.New("the HeatMap widget doesn't support mouse events") } @@ -280,13 +280,13 @@ func (hp *HeatMap) getBlockColor(value int64) cell.Color { } // minMax returns the min and max values in given integer array. -func minMax(values []int64) (min, max int64) { - min = math.MaxInt64 - max = math.MinInt64 +func minMax(values []int64) (mn, mx int64) { + mn = math.MaxInt64 + mx = math.MinInt64 for _, v := range values { - min = int64(math.Min(float64(min), float64(v))) - max = int64(math.Max(float64(max), float64(v))) + mn = int64(math.Min(float64(mn), float64(v))) + mx = int64(math.Max(float64(mx), float64(v))) } return } diff --git a/pkg/util/commandNotFound.go b/pkg/util/commandNotFound.go index be462bbe..b104dbbc 100644 --- a/pkg/util/commandNotFound.go +++ b/pkg/util/commandNotFound.go @@ -66,10 +66,10 @@ func minEditDistance(word1, word2 string) int { for i := range dp { dp[i] = make([]int, n+1) } - for i := 0; i < m+1; i++ { + for i := range m + 1 { dp[i][0] = i } - for j := 0; j < n+1; j++ { + for j := range n + 1 { dp[0][j] = j } for i := 1; i < m+1; i++ { @@ -83,14 +83,3 @@ func minEditDistance(word1, word2 string) int { } return dp[m][n] } - -// min get The minimum of the args. -func min(args ...int) int { - min := args[0] - for _, item := range args { - if item < min { - min = item - } - } - return min -} diff --git a/test/cases/basic/test.yaml b/test/cases/basic/test.yaml index 78716efd..6214a1ca 100644 --- a/test/cases/basic/test.yaml +++ b/test/cases/basic/test.yaml @@ -22,8 +22,6 @@ setup: steps: - name: install yq command: yq > /dev/null 2>&1 || go install github.com/mikefarah/yq/v4@latest - - name: install swctl - command: make install DESTDIR=/usr/local/bin > /dev/null 2>&1 trigger: action: http