summaryrefslogtreecommitdiffstats
path: root/scripts/quality.sh
blob: 22639939a6c2787f21a5f5849e0732a1a8cc9028 (plain)
1
2
3
4
5
6
7
8
#!/bin/bash

go test -covermode=count -coverprofile=docs/coverage.out ./...
go tool cover -html=docs/coverage.out -o docs/quality.html

revive -config .revive.toml ./... > docs/lint.txt

abcgo -path . -sort -no-test | sed 's%^/home/ser/workspace/gotop.d/gotop/%%' > docs/abcgo.txt
color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Macros and functions to assist in working with Go
#
# Copyright (c) 2024 Netdata Inc
#
# SPDX-License-Identifier: GPL

if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
    set(GO_LDFLAGS "-X main.version=${NETDATA_VERSION}")
else()
    set(GO_LDFLAGS "-w -s -X main.version=${NETDATA_VERSION}")
endif()

# add_go_target: Add a new target that needs to be built using the Go toolchain.
#
# Takes four arguments, the target name, the output artifact name, the
# source tree for the Go module, and the sub-directory of that source tree
# to pass to `go build`.
#
# The target itself will invoke `go build` in the specified source tree,
# using the `-o` option to produce the final output artifact, and passing
# the requested sub-directory as the final argument.
#
# This will also automatically construct the dependency list for the
# target by finding all Go source files under the specified source tree
# and then appending the go.mod and go.sum files from the root of the
# source tree.
macro(add_go_target target output build_src build_dir)
    file(GLOB_RECURSE ${target}_DEPS CONFIGURE_DEPENDS "${build_src}/*.go")
    list(APPEND ${target}_DEPS
        "${build_src}/go.mod"
        "${build_src}/go.sum"
    )

    add_custom_command(
        OUTPUT ${output}
        COMMAND "${CMAKE_COMMAND}" -E env CGO_ENABLED=0 "${GO_EXECUTABLE}" build -buildvcs=false -ldflags "${GO_LDFLAGS}" -o "${CMAKE_BINARY_DIR}/${output}" "./${build_dir}"
        DEPENDS ${${target}_DEPS}
        COMMENT "Building Go component ${output}"
        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${build_src}"
        VERBATIM
    )
    add_custom_target(
        ${target} ALL
        DEPENDS ${output}
    )
endmacro()

# find_min_go_version: Determine the minimum Go version based on go.mod files
#
# Takes one argument, specifying a source tree to scan for go.mod files.
#
# All files found will be checked for a `go` directive, and the
# MIN_GO_VERSION variable will be set to the highest version
# number found among these directives.
#
# Only works on UNIX-like systems, because it has to process the go.mod
# files in ways that CMake can't do on it's own.
function(find_min_go_version src_tree)
    message(STATUS "Determining minimum required version of Go for this build")

    file(GLOB_RECURSE go_mod_files ${src_tree}/go.mod)

    set(result 1.0)

    foreach(f IN ITEMS ${go_mod_files})
        message(VERBOSE "Checking Go version specified in ${f}")
        execute_process(
            COMMAND grep -E "^go .*$" ${f}
            COMMAND cut -f 2 -d " "
            RESULT_VARIABLE version_check_result
            OUTPUT_VARIABLE go_mod_version
        )

        if(version_check_result EQUAL 0)
            string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" go_mod_version "${go_mod_version}")

            if(go_mod_version VERSION_GREATER result)
                set(result "${go_mod_version}")
            endif()
        endif()
    endforeach()

    message(STATUS "Minimum required Go version determined to be ${result}")
    set(MIN_GO_VERSION "${result}" PARENT_SCOPE)
endfunction()