name: Code check on: push: tags: - v* branches: - master - main pull_request: jobs: golangci: name: Static code check runs-on: ubuntu-latest steps: - uses: actions/setup-go@v4 with: go-version: '1.20' cache: false - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: version: latest tests: name: Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Prepare go environment uses: actions/setup-go@v4 with: go-version: '1.20' cache: false - name: Run tests run: go test --cover -coverprofile coverage.out -covermode count -v ./... - name: Coverage check env: TESTCOVERAGE_THRESHOLD: 0 run: | echo "Checking test coverage is above threshold ..." echo "Threshold : $TESTCOVERAGE_THRESHOLD %" totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` echo "Current test coverage : $totalCoverage %" if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then echo "OK" else echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value." echo "Failed" exit 1 fi