|
| 1 | +# CI/CD Workflows |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The project uses GitHub Actions for continuous integration. Workflows are defined in `.github/workflows/`. |
| 6 | + |
| 7 | +## Tests and Coverage (`test.yaml`) |
| 8 | + |
| 9 | +**Trigger**: Every push to any branch. |
| 10 | + |
| 11 | +**Runner**: `ubuntu-latest` |
| 12 | + |
| 13 | +### Pipeline |
| 14 | + |
| 15 | +``` |
| 16 | +setup-go (1.23) |
| 17 | + | |
| 18 | +install system deps (libjansson-dev, libhiredis-dev) |
| 19 | + | |
| 20 | +checkout code |
| 21 | + | |
| 22 | +make getdeps (install golangci-lint, zbusc, go mod tidy) |
| 23 | + | |
| 24 | +make testrace |
| 25 | + | |
| 26 | + +-- lint (golangci-lint) |
| 27 | + +-- build (CGO_ENABLED=0 go build ./...) |
| 28 | + +-- test (go test, excludes stubs and network packages) |
| 29 | +``` |
| 30 | + |
| 31 | +### Steps |
| 32 | + |
| 33 | +| Step | What it does | |
| 34 | +|------|-------------| |
| 35 | +| Set up Go 1.23 | Installs Go toolchain via `actions/setup-go` | |
| 36 | +| Prepare dependencies | Installs C libraries needed by CGo bindings (`libjansson-dev`, `libhiredis-dev`) | |
| 37 | +| Checkout code | Checks out the repository | |
| 38 | +| Get dependencies | Runs `make getdeps` in `pkg/` — installs `golangci-lint`, `zbusc` (zbus stub generator), and runs `go mod tidy` | |
| 39 | +| Run tests | Runs `make testrace` in `pkg/` — lint, build, then test | |
| 40 | + |
| 41 | +### Lint Configuration |
| 42 | + |
| 43 | +The linter is configured via `.golangci.yml` at the repository root: |
| 44 | + |
| 45 | +| Linter | What it checks | |
| 46 | +|--------|---------------| |
| 47 | +| `errcheck` | Unchecked error return values | |
| 48 | +| `gofmt` | Code formatting (no trailing whitespace, proper indentation) | |
| 49 | +| `govet` | Suspicious constructs (printf format mismatches, struct tag issues, etc.) | |
| 50 | +| `ineffassign` | Assignments to variables that are never used | |
| 51 | +| `unconvert` | Unnecessary type conversions | |
| 52 | +| `staticcheck` | Static analysis (deprecated APIs, unreachable code, etc.) | |
| 53 | +| `gocyclo` | Cyclomatic complexity (threshold: 100) | |
| 54 | + |
| 55 | +Lint timeout is set to 20 minutes. |
| 56 | + |
| 57 | +### Build |
| 58 | + |
| 59 | +```bash |
| 60 | +CGO_ENABLED=0 go build -v ./... |
| 61 | +``` |
| 62 | + |
| 63 | +The build disables CGo to ensure all packages compile without C dependencies at build time (C libraries are only needed for testing). |
| 64 | + |
| 65 | +### Tests |
| 66 | + |
| 67 | +```bash |
| 68 | +sudo -E go test -vet=off -v $(go list ./... | grep -Ev "stubs|network") |
| 69 | +``` |
| 70 | + |
| 71 | +- Runs with `sudo` because some tests require elevated privileges (network namespaces, device management) |
| 72 | +- `-E` preserves environment variables (Go path, module settings) |
| 73 | +- `-vet=off` skips `go vet` during test (already run by the linter) |
| 74 | +- Excludes `stubs` packages (auto-generated zbus client code) and `network` packages (require real network namespaces/interfaces) |
| 75 | + |
| 76 | +## Makefile Targets |
| 77 | + |
| 78 | +All targets run from the `pkg/` directory. |
| 79 | + |
| 80 | +| Target | Description | |
| 81 | +|--------|-------------| |
| 82 | +| `make getdeps` | Install tooling (golangci-lint, zbusc) and tidy modules | |
| 83 | +| `make lint` | Run golangci-lint with the repo config | |
| 84 | +| `make build` | Build all packages with CGo disabled | |
| 85 | +| `make test` | Lint + build + run tests | |
| 86 | +| `make testrace` | Same as `test` (race detector not currently enabled) | |
| 87 | +| `make generate` | Regenerate zbus client stubs via `go generate` | |
0 commit comments