name: Tests on: push: branches: [ main, develop ] paths: - 'back/**' pull_request: branches: [ main, develop ] paths: - 'back/**' defaults: run: working-directory: ./back jobs: test: name: Test runs-on: ubuntu-latest services: postgres: image: postgres:15 env: POSTGRES_USER: test_user POSTGRES_PASSWORD: test_password POSTGRES_DB: logidex_test options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 redis: image: redis:7-alpine options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 6379:6379 strategy: matrix: go-version: [1.24] test-type: [unit, integration] steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - name: Cache Go modules uses: actions/cache@v3 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- - name: Install dependencies run: go mod download - name: Verify dependencies run: go mod verify - name: Run linters run: | go vet ./... go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest golangci-lint run - name: Run unit tests if: matrix.test-type == 'unit' run: | make test-unit - name: Run integration tests if: matrix.test-type == 'integration' env: TEST_DB_HOST: localhost TEST_DB_PORT: 5432 TEST_DB_NAME: logidex_test TEST_DB_USER: test_user TEST_DB_PASSWORD: test_password TEST_REDIS_HOST: localhost TEST_REDIS_PORT: 6379 run: | make test-integration - name: Run tests with coverage run: | make test-coverage-html - name: Upload coverage reports uses: codecov/codecov-action@v3 with: file: ./coverage.out flags: unittests name: codecov-umbrella - name: Check coverage threshold run: | make test-coverage-check - name: Run race condition tests run: | make test-race benchmark: name: Benchmark runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 with: go-version: 1.24 - name: Run benchmarks run: | make test-bench | tee benchmark.txt - name: Store benchmark results uses: actions/upload-artifact@v3 with: name: benchmark-results path: benchmark.txt security: name: Security Scan runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 with: go-version: 1.24 - name: Install gosec run: go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest - name: Run security scan run: gosec ./... - name: Install govulncheck run: go install golang.org/x/vuln/cmd/govulncheck@latest - name: Run vulnerability check run: govulncheck ./...