|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Run Tests |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Set up Go |
| 19 | + uses: actions/setup-go@v5 |
| 20 | + with: |
| 21 | + go-version: '1.23' |
| 22 | + cache: true |
| 23 | + |
| 24 | + - name: Download dependencies |
| 25 | + run: go mod download |
| 26 | + |
| 27 | + - name: Verify dependencies |
| 28 | + run: go mod verify |
| 29 | + |
| 30 | + - name: Build |
| 31 | + run: make build |
| 32 | + |
| 33 | + - name: Run tests with race detector and coverage |
| 34 | + run: make test |
| 35 | + |
| 36 | + - name: Generate detailed coverage report |
| 37 | + run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... |
| 38 | + |
| 39 | + - name: Check coverage threshold (80% minimum for pkg/) |
| 40 | + run: | |
| 41 | + echo "Checking coverage for each package..." |
| 42 | + for pkg in $(go list ./pkg/...); do |
| 43 | + coverage=$(go test -coverprofile=/tmp/coverage.out $pkg 2>&1 | grep -oP 'coverage: \K[0-9.]+' || echo "0") |
| 44 | + pkg_name=$(echo $pkg | sed 's/.*\///') |
| 45 | + echo "$pkg_name: ${coverage}%" |
| 46 | + # Verify minimum 80% coverage for all pkg/ packages |
| 47 | + if (( $(echo "$coverage < 80" | bc -l) )); then |
| 48 | + echo "::error::$pkg_name has ${coverage}% coverage, which is below 80% threshold" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + done |
| 52 | +
|
| 53 | + - name: Upload coverage to Codecov |
| 54 | + uses: codecov/codecov-action@v4 |
| 55 | + with: |
| 56 | + files: ./coverage.out |
| 57 | + flags: unittests |
| 58 | + name: codecov-umbrella |
| 59 | + fail_ci_if_error: false |
| 60 | + env: |
| 61 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 62 | + |
| 63 | + lint: |
| 64 | + name: Run Linters |
| 65 | + runs-on: ubuntu-latest |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Set up Go |
| 72 | + uses: actions/setup-go@v5 |
| 73 | + with: |
| 74 | + go-version: '1.23' |
| 75 | + cache: true |
| 76 | + |
| 77 | + - name: Run linters |
| 78 | + run: make lint |
| 79 | + |
| 80 | + build: |
| 81 | + name: Build Binaries |
| 82 | + runs-on: ubuntu-latest |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout code |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Set up Go |
| 89 | + uses: actions/setup-go@v5 |
| 90 | + with: |
| 91 | + go-version: '1.23' |
| 92 | + cache: true |
| 93 | + |
| 94 | + - name: Build server |
| 95 | + run: go build -v -o sprinkler-server ./cmd/server |
| 96 | + |
| 97 | + - name: Build client |
| 98 | + run: go build -v -o sprinkler-client ./cmd/client |
| 99 | + |
| 100 | + - name: Verify binaries |
| 101 | + run: | |
| 102 | + ./sprinkler-server -h || true |
| 103 | + ./sprinkler-client -h || true |
0 commit comments