Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/check_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
run: make test

license_validation:
needs: [run_tests]
name: "Validate that license added to all files"
runs-on: ubuntu-latest

Expand All @@ -51,7 +50,6 @@ jobs:
run: make validation/license

lint:
needs: [run_tests, license_validation]
name: "Lint golang code"
runs-on: ubuntu-latest

Expand Down
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ go-installed:
go version

bin/jq: curl-installed bin
curl -sSfL https://github.com/jqlang/jq/releases/download/jq-$(JQ_VERSION)/jq-$(JQ_PLATFORM_ARCH) -o ./bin/jq
@chmod +x "./bin/jq"
if ! ./hack/check_binary.sh "jq" "--version" "$(JQ_VERSION)" ; then \
echo "Install jq"; \
curl -sSfL https://github.com/jqlang/jq/releases/download/jq-$(JQ_VERSION)/jq-$(JQ_PLATFORM_ARCH) -o ./bin/jq; \
chmod +x "./bin/jq"; \
fi

bin/golangci-lint: curl-installed bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}
@chmod +x "./bin/golangci-lint"
if ! ./hack/check_binary.sh "golangci-lint" "--version" "$(GOLANGCI_VERSION)"; then \
echo "Install golangci-lint"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}; \
chmod +x "./bin/golangci-lint"; \
fi

bin/gofumpt: curl-installed bin
curl -sSfLo "bin/gofumpt" https://github.com/mvdan/gofumpt/releases/download/v$(GOFUMPT_VERSION)/gofumpt_v$(GOFUMPT_VERSION)_$(GOFUMPT_PLATFORM)_$(GOFUMPT_ARCH)
@chmod +x "./bin/gofumpt"
if ! ./hack/check_binary.sh "gofumpt" "-version" "$(GOFUMPT_VERSION)"; then \
echo "Install gofumpt"; \
curl -sSfLo "bin/gofumpt" https://github.com/mvdan/gofumpt/releases/download/v$(GOFUMPT_VERSION)/gofumpt_v$(GOFUMPT_VERSION)_$(GOFUMPT_PLATFORM)_$(GOFUMPT_ARCH); \
chmod +x "./bin/gofumpt"; \
fi

deps: bin bin/jq bin/golangci-lint bin/gofumpt

Expand Down
46 changes: 46 additions & 0 deletions hack/check_binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Copyright 2026 Flant JSC
#
# Licensed 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.

binary="$1"
version_arg="$2"
version="$3"

function not_empty_or_exit() {
if [ -z "$2" ]; then
echo "$1 is empty"
exit 1
fi

return 0
}

not_empty_or_exit "binary" "$binary"
not_empty_or_exit "version_arg" "$version_arg"
not_empty_or_exit "version" "$version"

binary_full_path="$(pwd)/bin/${binary}"

if [ ! -x "$binary_full_path" ]; then
echo "$binary_full_path not exists or not executable"
exit 1
fi

if ! "$binary_full_path" "$version_arg" | grep -q "$version" ; then
echo "$binary_full_path version not match ${version}. Version is $("$binary_full_path" "$version_arg")"
exit 1
fi

exit 0
11 changes: 11 additions & 0 deletions hack/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

source "$(pwd)/hack/utils.sh"

check_go

run_tests=""

if [ -n "$RUN_TEST" ]; then
Expand All @@ -25,6 +29,13 @@ run_dir="$(pwd)"
packages="$(go list ./... | grep -v /validation/)"
prefix="$(grep -oP 'module .*$' go.mod | sed 's|module ||')"

if [ -z "$(trim_spaces "$packages")" ]; then
echo -e '\033[1;33m!!!\033[0m'
echo -e "\033[1;33mNot found packages in $run_dir with module ${prefix}. Skip go tests\033[0m"
echo -e '\033[1;33m!!!\033[0m'
exit 0
fi

echo "Found packages: ${packages[@]} in $run_dir with module $prefix"

while IFS= read -r p; do
Expand Down
78 changes: 78 additions & 0 deletions hack/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

# Copyright 2026 Flant JSC
#
# Licensed 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.

function trim_spaces() {
local v="$1"
# Remove leading whitespace
v="${v#"${v%%[![:space:]]*}"}"

# Remove trailing whitespace
v="${v%"${v##*[![:space:]]}"}"

echo -n "$v"
}

function do_in_cycle(){
local msg="$1"
local get_arguments="$2"
local action="$3"

if [ -z "$msg" ]; then
echo "msg is empty"
exit 1
fi

if [ -z "$get_arguments" ]; then
echo "get_arguments is empty"
exit 1
fi

if [ -z "$action" ]; then
echo "action is empty"
exit 1
fi

local attempts=10

echo "Starting $msg with $attempts attempts"

local sleep_time=2
local current_attempt=1

while [[ -n "$(trim_spaces "$("$get_arguments")")" ]]; do
if [[ "$current_attempt" == "$attempts" ]]; then
echo "All attempts $attempts failed for ${msg}. Exit"
exit 1
fi

if ! $action $("$get_arguments"); then
echo "Attempt ${current_attempt}: $msg failed. Sleep ${sleep_time} before next attempt"
sleep "$sleep_time"
fi

((current_attempt++))
done

echo "$msg done!"
return 0
}

function check_go() {
if ! command -v go; then
echo "Go not found!"
exit 1
fi
}
15 changes: 6 additions & 9 deletions pkg/log/ln_logger_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package log

import "fmt"

// formatWithNewLineLogger
// we often use *F function, but for pretty log we use "\n" in end of string
// this interface and wrapper help us for get rit of this
Expand All @@ -28,22 +26,21 @@ func newFormatWithNewLineLoggerWrapper(parent baseLogger) *formatWithNewLineLogg
}

func (w *formatWithNewLineLoggerWrapper) InfoF(format string, a ...any) {
w.parent.InfoFWithoutLn(addLnToMessage(format, a...))
w.parent.InfoFWithoutLn(addLnToFormat(format), a...)
}

func (w *formatWithNewLineLoggerWrapper) ErrorF(format string, a ...any) {
w.parent.ErrorFWithoutLn(addLnToMessage(format, a...))
w.parent.ErrorFWithoutLn(addLnToFormat(format), a...)
}

func (w *formatWithNewLineLoggerWrapper) DebugF(format string, a ...any) {
w.parent.DebugFWithoutLn(addLnToMessage(format, a...))
w.parent.DebugFWithoutLn(addLnToFormat(format), a...)
}

func (w *formatWithNewLineLoggerWrapper) WarnF(format string, a ...any) {
w.parent.WarnFWithoutLn(addLnToMessage(format, a...))
w.parent.WarnFWithoutLn(addLnToFormat(format), a...)
}

func addLnToMessage(format string, a ...any) string {
f := format + "\n"
return fmt.Sprintf(f, a...)
func addLnToFormat(format string) string {
return format + "\n"
}
14 changes: 12 additions & 2 deletions pkg/log/ln_logger_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package log

import (
"errors"
"fmt"
"testing"

Expand All @@ -38,12 +39,21 @@ func TestLnLoggerWrapper(t *testing.T) {
wrapper.ErrorF("Error")
assertAddNewLine(t, "Error")

wrapper.ErrorF("VariablesError %s %v", "msg", true)
assertAddNewLine(t, "VariablesError msg true")

wrapper.WarnF("Warn")
assertAddNewLine(t, "Warn")

wrapper.WarnF("VariablesWarn %s %v", "msg", true)
assertAddNewLine(t, "VariablesWarn msg true")

wrapper.InfoF("Info")
assertAddNewLine(t, "Info")

wrapper.DebugF("Debug")
assertAddNewLine(t, "Debug")
wrapper.InfoF("VariablesInfo %s %v", "msg", errors.New("error"))
assertAddNewLine(t, "VariablesInfo msg error")

wrapper.DebugF("VariablesDebug %v %s", 42, "msg")
assertAddNewLine(t, "VariablesDebug 42 msg")
}