From 2dcef7c27c0d53296bca7494b2ad2f2813aa5709 Mon Sep 17 00:00:00 2001 From: "v.oleynikov" Date: Fri, 2 Aug 2024 20:05:57 +0300 Subject: [PATCH] [CI] Add golang tests and linter launch Signed-off-by: v.oleynikov --- .github/workflows/go_lint.yaml | 44 +++++++++++++++++++++++++++++++++ .github/workflows/go_tests.yaml | 41 ++++++++++++++++++++++++++++++ .golangci.yaml | 39 +++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 .github/workflows/go_lint.yaml create mode 100644 .github/workflows/go_tests.yaml create mode 100644 .golangci.yaml diff --git a/.github/workflows/go_lint.yaml b/.github/workflows/go_lint.yaml new file mode 100644 index 0000000..46b6e4b --- /dev/null +++ b/.github/workflows/go_lint.yaml @@ -0,0 +1,44 @@ +name: Go linter for images + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + name: Go linter for images + runs-on: [self-hosted, regular] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Go environment + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Install golangci-lint + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 + + - name: Run Go lint + run: | + basedir=$(pwd) + failed='false' + for dir in $(find images -type d); do + if ls $dir/go.mod &> /dev/null; then + echo "Running linter in $dir" + cd $dir + golangci-lint run + if [ $? -ne 0 ]; then + echo "Linter failed in $dir" + failed='true' + fi + cd $basedir + fi + done + if [ $failed == 'true' ]; then + exit 1 + fi diff --git a/.github/workflows/go_tests.yaml b/.github/workflows/go_tests.yaml new file mode 100644 index 0000000..184ee37 --- /dev/null +++ b/.github/workflows/go_tests.yaml @@ -0,0 +1,41 @@ +name: Go tests for images + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + name: Go tests for images + runs-on: [self-hosted, regular] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Go environment + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Run Go tests + run: | + basedir=$(pwd) + failed='false' + for dir in $(find images -type d); do + if ls $dir/*_test.go &> /dev/null; then + echo "Running tests in $dir" + cd $dir + go test -v + if [ $? -ne 0 ]; then + echo "Tests failed in $dir" + failed='true' + fi + cd $basedir + fi + done + if [ $failed == 'true' ]; then + exit 1 + fi diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..4655fb0 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,39 @@ +run: + timeout: 10m + +issues: + exclude: + - ST1005.* + - "should not use dot imports" + - "don't use an underscore in package name" + - "exported: .*" + +linters-settings: + gci: + sections: + - standard + - default + errcheck: + ignore: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy + +linters: + disable-all: true + enable: + - dogsled + - errcheck + - gci + - gocritic + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - revive + - staticcheck +# - structcheck + - typecheck + - unconvert + - unparam + - whitespace + - copyloopvar